KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
polypath.h
Go to the documentation of this file.
1 
6 /*
7  * $Id: polypath.h 17555 2014-09-18 07:36:52Z predoehl $
8  */
9 
10 #ifndef POLYPATH_H_UOFARIZONAVISION
11 #define POLYPATH_H_UOFARIZONAVISION 1
12 
13 #include <l_cpp/l_exception.h>
14 #include <m_cpp/m_vector_d.h>
15 #include <qd_cpp/pixpath.h>
16 
17 #include <iosfwd>
18 
19 namespace kjb
20 {
21 namespace qd
22 {
23 
51 class PolyPath : public PixPath
52 {
53  PixPath m_sparsepath;
54 
55  std::vector<size_t> sdmap;
56  std::vector<Vector2> m_tangent;
57 
58  PolyPath(const PixPath&);
59 
60 public:
63  static PolyPath construct_from_vertices(const PixPath& vertices)
64  {
65  if (vertices.self_intersect())
66  {
67  KJB_THROW_2(Illegal_argument, "input must be distinct vertices");
68  }
69  return PolyPath(vertices);
70  }
71 
72 
74  static PolyPath construct_from_path(const PixPath& path)
75  {
77  }
78 
79 
81  const PixPath& get_vertices() const
82  {
83  return m_sparsepath;
84  }
85 
86 
103  {
104  return m_tangent.at(i - begin());
105  }
106 
107 
109  Vector2 tangent_at(size_t ix) const
110  {
111  return m_tangent.at(ix);
112  }
113 
114 
116  bool is_a_vertex(size_t ix) const
117  {
118  return std::find(sdmap.begin(), sdmap.end(), ix) != sdmap.end();
119  }
120 
121 
122  int debug_print(std::ostream&) const;
123 };
124 
125 
158 
159 
162 {
163  return 0 == v.x() && 0 == v.y() ? v : get_unit_vector_2x_angle(v);
164 }
165 
166 
169 
170 
172 bool is_valid_as_polypath(const PixPath&, bool throw_failure = false);
173 
174 }
175 }
176 
177 #endif /* POLYPATH_H_UOFARIZONAVISION */
178 
const PixPath & get_vertices() const
provide read-only access to the sequence of polygon vertices
Definition: polypath.h:81
VecPP::const_iterator const_iterator
constant iterator through PixPath points
Definition: pixpath.h:235
Vector2 get_unit_vector_2x_angle_of_unit_vector(const Vector2 &u)
like compute_unit_vector_2x_angle but for unit-magnitude input.
Definition: polypath.cpp:203
Vector2 get_unit_vector_2x_angle_nothrow(const Vector2 &v)
like get_unit_vector_2x_angle() but return zero vector on zero input
Definition: polypath.h:161
PixPath cull_redundant_points() const
Remove "unnecessary" points (ones that can be bresenham interpolated)
Definition: pixpath.cpp:914
double y() const
Definition: m_vector_d.impl.h:169
represents an open polygonal path with a tangent at each point
Definition: polypath.h:51
Representation of a sequence of pixel coordinates.
Definition: pixpath.h:117
double x() const
Definition: m_vector_d.impl.h:134
const_iterator begin() const
Return an iterator pointing to the first point in the path.
Definition: pixpath.h:358
Vector2 get_unit_vector_2x_angle(const Vector2 &v)
double the angle relative to (1,0) and return a unit vector that way.
Definition: polypath.cpp:192
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
bool is_valid_as_polypath(const PixPath &path, bool throw_failure)
test whether a pixel path is convertible to PolyPath (maybe say why)
Definition: polypath.cpp:212
Vector2 tangent_at(size_t ix) const
access unit vector at a point along path, specified by index
Definition: polypath.h:109
Vector2 tangent_at(const_iterator i) const
access unit vector at a point along path, spec by const_iterator
Definition: polypath.h:102
bool self_intersect(PixPoint *where=00) const
Reveal whether the path has any self-intersections.
Definition: pixpath.cpp:324
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
static PolyPath construct_from_path(const PixPath &path)
static ctor: reconstruct a path with extra information
Definition: polypath.h:74
int debug_print(std::ostream &) const
print the inner state of a PolyPath object to a stream
Definition: polypath.cpp:152
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
Support for error handling exception classes in libKJB.
static PolyPath construct_from_vertices(const PixPath &vertices)
static ctor: build polygonal path from a sequence of vertices
Definition: polypath.h:63
Contains definition for class PixPath.
bool is_a_vertex(size_t ix) const
test whether the point at a given index is a polygonal vertex
Definition: polypath.h:116