KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | List of all members
kjb::qd::PolyPath Class Reference

represents an open polygonal path with a tangent at each point More...

#include <polypath.h>

Inheritance diagram for kjb::qd::PolyPath:
kjb::qd::PixPath

Public Member Functions

const PixPathget_vertices () const
 provide read-only access to the sequence of polygon vertices More...
 
Vector2 tangent_at (const_iterator i) const
 access unit vector at a point along path, spec by const_iterator More...
 
Vector2 tangent_at (size_t ix) const
 access unit vector at a point along path, specified by index More...
 
bool is_a_vertex (size_t ix) const
 test whether the point at a given index is a polygonal vertex More...
 
int debug_print (std::ostream &) const
 print the inner state of a PolyPath object to a stream More...
 
- Public Member Functions inherited from kjb::qd::PixPath
virtual ~PixPath ()
 obligatory dtor More...
 
virtual PixPathassign (unsigned index, const PixPoint &newp)
 Change a member of the path to a new PixPoint. More...
 
const PixPointoperator[] (unsigned index) const
 Vector-like access to points (returning an rvalue). More...
 
virtual void push_back (const PixPoint &pp)
 Vector-like appending a new PixPoint on the end of the object. More...
 
virtual void pop_back ()
 
size_t size () const
 Number of points in the path (not the same as its length). More...
 
virtual void swap (PixPath &vpp)
 Swap the contents of two PixPaths. More...
 
virtual void clear ()
 Discard all points. More...
 
const_iterator begin () const
 Return an iterator pointing to the first point in the path. More...
 
const_iterator end () const
 Rtn iterator pointing to just beyond the last point in the path. More...
 
const_reverse_iterator rbegin () const
 return a reverse-moving iterator to the last point in path More...
 
const_reverse_iterator rend () const
 return one-before-first iterator, in symmetry with end(). More...
 
virtual PixPathappend (const_iterator begin, const_iterator end)
 Append a range from a given other path to the end of this path. More...
 
virtual PixPathappend (const PixPath &suffix)
 Append the given path to the tail of this path; overwrites. More...
 
virtual int append_no_overlap (const PixPath &suffix)
 Like append(), with extra avoid-the-duplicates fuss; overwrites. More...
 
PixPath subrange (unsigned, unsigned) const
 Returns a subrange of this PixPath object. More...
 
PixPath prefix (unsigned postlast) const
 Variation on subrange: return a prefix of this path (by value) More...
 
PixPath suffix (unsigned first) const
 Variation on subrange: return a suffix of this path (by value) More...
 
bool self_intersect (PixPoint *where=00) const
 Reveal whether the path has any self-intersections. More...
 
bool connected8 (bool emit_verbose_debug_output=false) const
 Is the path all connected, using 8-connectivity? More...
 
PixPoint front () const
 Return (by value) the first point in the path. More...
 
PixPoint back () const
 Return (by value) the last point in the path. More...
 
virtual int arclength (std::vector< float > *) const
 Return a vector of arclengths along the polygonal path. More...
 
virtual float arclength () const
 compute and return polygonal path length of this path More...
 
std::string str (const std::string &separator="\n") const
 Return the path as an ASCII string. More...
 
int save (const std::string &filename) const
 Saves the path to an ASCII file, returns NO_ERROR or ERROR. More...
 
bool operator== (const PixPath &) const
 Compare PixPaths; true iff the sequence of points is identical. More...
 
bool operator!= (const PixPath &other) const
 Compare PixPaths; true iff the sequence of points differs. More...
 
PixPath operator+ (const PixPath &) const
 Add, element-by-element, two PixPaths of the same length. More...
 
virtual PixPoint boundbox_min_min () const
 Return the corner point of a bounding box, with min x and y. More...
 
virtual PixPoint boundbox_max_max () const
 Similar to boundbox_min_min() but returns maximum x, y coords. More...
 
bool boundbox_within_boundbox (const PixPath &outer) const
 Test whether the axis-aligned bounding box of this path lies within the axis-aligned bounding box of the given path. More...
 
bool so_boundbox_holds_within (const PixPoint &q) const
 sort of like boundbox_within_boundbox but works on a single point More...
 
unsigned hits (const PixPoint &query_point) const
 Return number of times (maybe 0) the path hits a query point. More...
 
unsigned hits (const PixPath &query_path) const
 return number of common points between query_path and this path More...
 
PixPoint nearest (const PixPoint &, const_iterator *q=00) const
 Return the PixPath member closest to a given query point. More...
 
PixPoint nearest (const kjb::Vector2 &, const_iterator *q=00) const
 Return the PixPath member closest to the given real xy coordinates. More...
 
PixPathow_reverse ()
 Reverse the order of the points in the path (overwriting!) More...
 
PixPath reverse () const
 return a copy of this list after reversing the front-back order. More...
 
int cubic_fit (std::vector< float > *x, std::vector< float > *y, int ref=0) const
 Fit a cubic polynomial to the given list of x and y points. More...
 
PixPath interpolate (bool forbid_self_intersection=false) const
 This interpolates pixels between unconnected pixels. More...
 
PixPath cull_redundant_points () const
 Remove "unnecessary" points (ones that can be bresenham interpolated) More...
 
PixPath merge_redundant_slopes () const
 return a path with interior points removed but preserve all slopes. More...
 
PixPath expel (const_iterator) const
 Duplicate this path, except that we omit the indicated point. More...
 
PixPath expel (size_t index_of_unwanted_point) const
 Duplicate this path, except we omit the point with given index. More...
 
virtual float hausdorff_distance (const PixPath &that) const
 Compute the Hausdorff metric between two sets of points. More...
 
float closest_pair (const_iterator *pa=0, const_iterator *pb=0) const
 Find the distance between closest pair of points, ignoring adjacency. More...
 
float closest_adjacent_pair (const_iterator *pa=0) const
 Find a pair of adjacent points at least as close as any other. More...
 
bool has_subsequence (const PixPath &subseq) const
 tests whether a given path is a subsequence of this path More...
 
double angle_at (unsigned) const
 Compute included angle at some interior point in a path. More...
 
PixPoint::Integer bracket_cross_at (unsigned index) const
 cross product of line segs (index-1,index+1) x (index,index+1) More...
 
double heading_shift_at (unsigned index) const
 compute shift in "heading" angle at an interior point More...
 
bool intersect_at_with (unsigned preindex1, unsigned preindex2, unsigned *endpoint_intersector_index=00) const
 Test whether two segments of this path intersect. More...
 
bool do_segments_intersect (unsigned *s1=00, unsigned *s2=00, unsigned *count=00) const
 quadratic time test whether any 2 path segments cross each other More...
 
unsigned longest_segment (float *length=00) const
 return index of first point of longest segment More...
 
kjb::Vector2 centroid () const
 return the "mean" of the points (nonempty, none may be unused) More...
 
unsigned member_near_centroid () const
 return index of a member point nearest centroid() (qv) More...
 

Static Public Member Functions

static PolyPath construct_from_vertices (const PixPath &vertices)
 static ctor: build polygonal path from a sequence of vertices More...
 
static PolyPath construct_from_path (const PixPath &path)
 static ctor: reconstruct a path with extra information More...
 
- Static Public Member Functions inherited from kjb::qd::PixPath
static PixPath reserve (size_t potential_size=0)
 named ctor creates an empty path but reserves some memory for it More...
 
static PixPath load (const std::string &filename)
 named ctor loads path coordinates from an ASCII file More...
 
static PixPath fenceposts (const PixPoint &pt_a, const PixPoint &pt_b, size_t sz)
 named ctor makes a path of evenly spaced points from a to b More...
 
static PixPath parse (const std::string &coords)
 named ctor builds from string-format list of coordinates More...
 

Additional Inherited Members

- Public Types inherited from kjb::qd::PixPath
typedef const PixPointconst_reference
 Reference to an element – required to use std::back_inserter(). More...
 
typedef PixPoint value_type
 Element type – required to use std::back_inserter() in c++11. More...
 
typedef VecPP::const_iterator const_iterator
 constant iterator through PixPath points More...
 
typedef
VecPP::const_reverse_iterator 
const_reverse_iterator
 constant reverse iterator through PixPath points More...
 
- Protected Member Functions inherited from kjb::qd::PixPath
 PixPath ()
 Default ctor starts as empty, and you can push points onto it. More...
 
 PixPath (size_t potential_size)
 ctor receives the size to reserve More...
 
 PixPath (const std::string &)
 ctor to load from an ASCII file More...
 
 PixPath (const PixPoint &, const PixPoint &, size_t)
 ctor makes evenly spaced points between termini More...
 
 PixPath (const std::string &, int)
 ctor that parses a string of characters More...
 

Detailed Description

represents an open polygonal path with a tangent at each point

The PixPath interface to this object represents the 8-connected "view" of the path. If you want to access the vertices, use the get_vertices() method. If you want to test whether a certain location along the path is a vertex, use the is_a_vertex() predicate.

This class defines a tangent at each point along the connected path. Each tangent is represented as a radial unit vector, i.e., it could lie anywhere on the unit circle. The direction points generally from the lower-numbered vertices to the higher-numbered vertices. Thus the tangent at location 0 is a unit vector pointing from vertex 0 to vertex 1.

Tangents at non-vertex locations are defined similarly: each non-vertex location is bookended by vertices v, w, and the tangent goes in the direction from v to w. This is one reason why the input vertices must be distinct.

We also define a value that will serve as "tangent" at the vertices themselves. Let v be an interior vertex and let u, w be its predecessor and successor vertices. Let r be a unit vector in the (u,v) direction and let s be a unit vector in the (v, w) direction. We define the "tangent" at v therefore to be a unit vector in the (r+s) direction. We defined the "tangent" at the first vertex above, and for the last vertex the definition is similar.

Member Function Documentation

static PolyPath kjb::qd::PolyPath::construct_from_path ( const PixPath path)
inlinestatic

static ctor: reconstruct a path with extra information

static PolyPath kjb::qd::PolyPath::construct_from_vertices ( const PixPath vertices)
inlinestatic

static ctor: build polygonal path from a sequence of vertices

Exceptions
Illegal_argumentif input has a repeated pt. or a 180-deg bend.
int kjb::qd::PolyPath::debug_print ( std::ostream &  os) const

print the inner state of a PolyPath object to a stream

Returns
ERROR iff the object has broken invariants, otherwise NO_ERROR
const PixPath& kjb::qd::PolyPath::get_vertices ( ) const
inline

provide read-only access to the sequence of polygon vertices

bool kjb::qd::PolyPath::is_a_vertex ( size_t  ix) const
inline

test whether the point at a given index is a polygonal vertex

Vector2 kjb::qd::PolyPath::tangent_at ( const_iterator  i) const
inline

access unit vector at a point along path, spec by const_iterator

Parameters
iconst_iterator to a point in the path
Warning
behavior is undefined if i does not point into this PolyPath.

On points that are NOT vertices, the output represents a ray passing from the nearest vertex prior to this path location, through the nearest vertex subsequent to this path location. Thus, it is directed and the output (as a unit vector) can potentially lie in any of the four quadrants. If you prefer an axial direction rather than a radial direction, you might find these other functions useful:

See Also
get_unit_vector_2x_angle();
get_unit_vector_2x_angle_of_unit_vector()
Vector2 kjb::qd::PolyPath::tangent_at ( size_t  ix) const
inline

access unit vector at a point along path, specified by index


The documentation for this class was generated from the following files: