KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ppath_ac.h
Go to the documentation of this file.
1 
6 /*
7  * $Id: ppath_ac.h 17555 2014-09-18 07:36:52Z predoehl $
8  */
9 
10 #ifndef PPATH_AC_H_UOFARIZONAVISION
11 #define PPATH_AC_H_UOFARIZONAVISION 1
12 
13 #include <qd_cpp/pixpath.h>
14 
15 namespace kjb
16 {
17 namespace qd
18 {
19 
24 class PixPathAc : public PixPath {
25 
30  mutable std::vector< float > arclen_cache;
31 
33  mutable bool arclen_valid;
34 
39  void refresh_the_cache_if_stale() const
40  {
41  if ( ! arclen_valid )
42  {
43  ETX( PixPath::arclength( &arclen_cache ) );
44  arclen_valid = true;
45  }
46  }
47 
48 protected:
51  : PixPath(),
52  arclen_valid( false )
53  {}
54 
56  PixPathAc( size_t potential_size )
57  : PixPath( potential_size ),
58  arclen_valid( false )
59  {}
60 
62  PixPathAc( const std::string& fn )
63  : PixPath( fn ),
64  arclen_valid( false )
65  {}
66 
67 public:
69  PixPathAc( const PixPath& path )
70  : PixPath( path ),
71  arclen_valid( false )
72  {}
73 
75  static PixPathAc reserve( size_t potential_size = 0 )
76  {
77  return PixPathAc( potential_size );
78  }
79 
80 
82  PixPathAc& assign( unsigned index, const PixPoint& newp )
83  {
84  arclen_valid = false;
85  PixPath::assign( index, newp );
86  return *this;
87  }
88 
90  void swap( PixPathAc& vpp )
91  {
92  PixPath::swap( vpp );
93  arclen_cache.swap( vpp.arclen_cache );
94  std::swap( arclen_valid, vpp.arclen_valid );
95  }
96 
98  void push_back( const PixPoint& pp )
99  {
100  arclen_valid = false;
101  PixPath::push_back( pp );
102  }
103 
105  void clear()
106  {
107  arclen_valid = false;
108  PixPath::clear();
109  }
110 
113  {
114  arclen_valid = false;
115  PixPath::append( begin, end );
116  return *this;
117  }
118 
124  PixPathAc& append( const PixPath& suffix ) // PixPath input is adequate
125  {
126  arclen_valid = false;
127  PixPath::append( suffix );
128  return *this;
129  }
130 
133  {
134  arclen_valid = false;
135  return PixPath::append_no_overlap( suffix );
136  }
137 
140  {
141  arclen_valid = false;
143  return *this;
144  }
145 
156  int arclength( std::vector< float >* alvec ) const
157  {
158  KJB( NRE( alvec ) );
159 
160  refresh_the_cache_if_stale();
161  alvec -> resize( size() );
162  std::copy( arclen_cache.begin(), arclen_cache.end(), alvec->begin() );
163  return kjb_c::NO_ERROR;
164  }
165 
175  float arclength( size_t index ) const
176  {
177  refresh_the_cache_if_stale();
178  return arclen_cache.at( index );
179  }
180 
184  float arclength() const;
185 
186  size_t whereis_arclength_ratio( float ) const;
187 
189  size_t halfway() const
190  {
191  return whereis_arclength_ratio( 0.5 );
192  }
193 };
194 
195 }
196 }
197 
198 #endif
float arclength() const
Return the polygonal path length for this path, front() to back()
Definition: ppath_ac.cpp:90
#define ETX(a)
Definition: l_exception.h:67
VecPP::const_iterator const_iterator
constant iterator through PixPath points
Definition: pixpath.h:235
#define KJB(x)
Definition: l_util.h:9
virtual PixPath & append(const_iterator begin, const_iterator end)
Append a range from a given other path to the end of this path.
Definition: pixpath.cpp:152
virtual void push_back(const PixPoint &pp)
Vector-like appending a new PixPoint on the end of the object.
Definition: pixpath.h:329
PixPathAc(const PixPath &path)
ctor copies from a PixPath. This is the only public ctor.
Definition: ppath_ac.h:69
PixPathAc & append(const_iterator begin, const_iterator end)
append range of another path to this
Definition: ppath_ac.h:112
virtual float arclength() const
compute and return polygonal path length of this path
Definition: pixpath.cpp:1637
Representation of a sequence of pixel coordinates.
Definition: pixpath.h:117
size_t size() const
Number of points in the path (not the same as its length).
Definition: pixpath.h:338
const_iterator end() const
Rtn iterator pointing to just beyond the last point in the path.
Definition: pixpath.h:364
virtual int append_no_overlap(const PixPath &suffix)
Like append(), with extra avoid-the-duplicates fuss; overwrites.
Definition: pixpath.cpp:177
int arclength(std::vector< float > *alvec) const
compute polygonal path length along path, ret. vector of results.
Definition: ppath_ac.h:156
PixPathAc()
default ctor almost the same as the PixPath default ctor
Definition: ppath_ac.h:50
PixPathAc(size_t potential_size)
ctor receives the size to reserve
Definition: ppath_ac.h:56
const_iterator begin() const
Return an iterator pointing to the first point in the path.
Definition: pixpath.h:358
size_t whereis_arclength_ratio(float) const
Return index of PixPoint in path at a given arclength ratio.
Definition: ppath_ac.cpp:48
PixPathAc & ow_reverse()
Reverse the order of this path, IN PLACE!
Definition: ppath_ac.h:139
This is like PixPath except that it has an arclength cache, for teh performance.
Definition: ppath_ac.h:24
static PixPathAc reserve(size_t potential_size=0)
named ctor creates an empty path but reserves some memory for it
Definition: ppath_ac.h:75
PixPath suffix(unsigned first) const
Variation on subrange: return a suffix of this path (by value)
Definition: pixpath.h:456
PixPathAc & append(const PixPath &suffix)
tack on a copy of a given path to the end of this path
Definition: ppath_ac.h:124
void swap(kjb::Gsl_Multimin_fdf &m1, kjb::Gsl_Multimin_fdf &m2)
Swap two wrapped multimin objects.
Definition: gsl_multimin.h:693
void clear()
throw away all points
Definition: ppath_ac.h:105
virtual void swap(PixPath &vpp)
Swap the contents of two PixPaths.
Definition: pixpath.h:344
int append_no_overlap(const PixPath &suffix)
see description of PixPath::append_no_overlap()
Definition: ppath_ac.h:132
Representation of an (x,y) pair of pixel coordinates.
Definition: pixpoint.h:57
virtual void clear()
Discard all points.
Definition: pixpath.h:351
void swap(PixPathAc &vpp)
swap representations of two PixPathAc objects
Definition: ppath_ac.h:90
PixPathAc(const std::string &fn)
ctor loads from a file, just like PixPath ctor
Definition: ppath_ac.h:62
float arclength(size_t index) const
Return the polygonal path length from front() to indexed point.
Definition: ppath_ac.h:175
PixPath & ow_reverse()
Reverse the order of the points in the path (overwriting!)
Definition: pixpath.cpp:613
virtual PixPath & assign(unsigned index, const PixPoint &newp)
Change a member of the path to a new PixPoint.
Definition: pixpath.h:299
size_t halfway() const
Return index of PixPoint closest to but not beyond mid-arclength.
Definition: ppath_ac.h:189
PixPathAc & assign(unsigned index, const PixPoint &newp)
assign a location in a PixPathAc
Definition: ppath_ac.h:82
Contains definition for class PixPath.
void push_back(const PixPoint &pp)
add a new point to the end of the path
Definition: ppath_ac.h:98