DGtal 1.3.0
Loading...
Searching...
No Matches
OneBalancedWordComputer.h
1
17#pragma once
18
36#if defined(OneBalancedWordComputer_RECURSES)
37#error Recursive header files inclusion detected in OneBalancedWordComputer.h
38#else // defined(OneBalancedWordComputer_RECURSES)
40#define OneBalancedWordComputer_RECURSES
41
42#if !defined OneBalancedWordComputer_h
44#define OneBalancedWordComputer_h
45
47// Inclusions
48#include <iostream>
49#include "DGtal/base/Common.h"
50#include "DGtal/geometry/curves/FreemanChain.h"
51#include "DGtal/base/OrderedAlphabet.h"
52#include "DGtal/base/IteratorCirculatorTraits.h"
53#include "DGtal/kernel/CInteger.h"
54#include "DGtal/arithmetic/IntegerComputer.h"
55#include "DGtal/geometry/curves/ArithmeticalDSL.h"
57
58namespace DGtal
59{
60
61
62
64 // template class OneBalancedWordComputer
90 template <typename TConstIterator, typename TInteger>
92 {
93
94 // ----------------------- Types ------------------------------
95 public :
96 //Required type
98 typedef TConstIterator ConstIterator;
99 typedef TInteger Integer;
100
101 //Required types
105
106 //2D points and 2D vectors
109
111 typedef int Size;
112 typedef int Index;
113
114 //The basic steps associate to the codes are given by a function `f: Code -> Vector`
116
117 //DSL
119
120 private :
128 template < class TIterator, class iterator_type = typename IteratorCirculatorTraits <TIterator>::Category > class CodeHandler
129 {
130 public :
132 { }
133 void init( const TIterator & it )
134 {
135 myIter = it;
136 }
137
138 Code getCode( Index n ) const
139 {
140 return myCodes[ n ];
141 }
142
144 {
145 while ( n >= myCodes.size() )
146 {
147 myCodes.push_back( *myIter );
148 ++myIter;
149 }
150 return myCodes[ n ];
151 }
152
153 private :
154 std::vector<Code> myCodes;
155 TIterator myIter;
156 };
157
162 template < class TIterator >
164 {
165 public :
167 {
168 }
169 void init( const TIterator & it )
170 {
171 myFirst = it;
172 myLast = it;
173 }
174
175 Code getCode( Index n ) const
176 {
177 return ( n >= 0 ) ? myPosCodes[ n ] : myNegCodes[ 1-n ];
178 }
179
181 {
182 Code c;
183 if ( n<0 )
184 {
185 unsigned int i = 1-n;
186 while ( i >= myNegCodes.size() )
187 {
188 --myFirst;
189 myNegCodes.push_back( *myFirst );
190 }
191 c = myNegCodes[ n ];
192 }
193 else
194 {
195 unsigned int i = n;
196 while ( i >= myPosCodes.size() )
197 {
198 myPosCodes.push_back( *myLast );
199 ++myLast;
200 }
201 c = myPosCodes[ n ];
202 }
203 return c;
204 }
205
206 private :
207 std::vector<Code> myPosCodes;
208 std::vector<Code> myNegCodes;
209 TIterator myFirst;
210 TIterator myLast;
211 };
212
216 template < class TIterator>
218 {
219 public :
221 { }
222
223 void init ( const TIterator & it )
224 {
225 myIter = it;
226 }
227
228 Code getCode( Index n ) const
229 {
230 return myIter[ n ];
231 }
232
234 {
235 return myIter[ n ];
236 }
237
238 private :
239 TIterator myIter;
240 };
241
242
243 public :
244
249 {
250
254 typedef Point * pointer;
255 typedef Point & reference;
256
260
265 {}
266
274 myDSS(dss), i(ind), p(pt)
275 {}
276
281
285 bool operator==( const ConstPointIterator other) const
286 {
287 return i == other.i;
288 }
289 bool operator!=( const ConstPointIterator other) const
290 {
291 return i != other.i;
292 }
293
295 {
296 return i - other.i;
297 }
298
303 ConstPointIterator( const ConstPointIterator & other) = default;
304
310 {
311 i = other.i;
312 myDSS = other.myDSS;
313 p = other.p;
314 return *this;
315 }
316
318 {
319 return p;
320 }
321
322 // pre-increment ++i
324 {
325 next();
326 return *this;
327 }
328
329 // post-increment
331 {
332 ConstPointIterator it = *this;
333 next();
334 return it;
335 }
336
337
338 // pre-decrement --i
340 {
341 prev();
342 return *this;
343 }
344
345 // post-decrement
347 {
348 ConstPointIterator it = *this;
349 prev();
350 return it;
351 }
352
353 // Move to next position
354 void next()
355 {
356 p += myDSS->myDisplacements( myDSS->getCode( i ) );
357 ++i;
358 }
359
360 // Move to previous position
361 void prev()
362 {
363 --i;
364 p -= myDSS->myDisplacements( myDSS->getCode( i ) );
365 }
366
367
368 // Get a reference to the current Combinatorial DSS
370 {
371 return myDSS;
372 }
373
374
375 // Get the index of the iterator
377 {
378 return i;
379 }
380
381 };
382
383
384
385
386 // ----------------------- Standard services ------------------------------
387 public:
388
393
398
399
412 void init( const ConstIterator & it,
413 const Point & start = Point(0,0),
414 Vector (*displacements) (Code) = defaultMoves );
415
416
417
422 void init(const ConstPointIterator & i);
423
432 void init(const FreemanChainCode & fc);
433
442 void init(const typename FreemanChainCode::ConstIterator & it);
443
448 OneBalancedWordComputer ( const Self & other );
449
456
460 Self getSelf( ) const;
461
462
463
468 bool operator==( const Self & other ) const;
469
476 bool operator!=( const Self & other ) const;
477
478
483
484
491
498
505
512
521
530
535 void setPosition( const Point & p );
536
537
542 void translate( const Vector & v );
543
552
560 Integer getA() const;
561
569 Integer getB() const;
570
578 Integer getMu() const;
579
588
589
597
606 Point & lf, Point & ll ) const;
607
608
615 Point Uf() const;
616
623 Point Ul() const;
624
631 Point Lf() const;
632
639 Point Ll() const;
640
646 bool isValid() const;
647
672 ConstIterator it,
673 const OrderedAlphabet & aOA);
674
675
676 // ----------------------- Accessors --------------------------------------
677
678 public:
679
684 Point back() const;
685
690 Point front() const;
691
697
703
708
713
714
715
716
717
718
719 // ----------------------- Interface --------------------------------------
720 public:
721
726 void selfDisplay ( std::ostream & out ) const;
727
728
729 protected:
730 // ------------------------- Protected Datas ------------------------------
731
736
742
749
755
756
762 unsigned int myNbRepeat;
763
770
776
784
785
790
791
792
793 // ------------------------- Private Datas --------------------------------
794 private:
795
796 // ------------------------- Hidden services ------------------------------
797 public:
798
799
805
811
819
825 Code getCode(Index pos) const;
826
832
838
845
852
863 bool isUL ( Index pos ) const;
864
875 bool nextIsLL ( Index pos ) const;
876
887 bool previousIsLL ( Index pos ) const;
888
894 bool isTrivial() const;
895
902
903
904
905
906 private:
907 // ------------------------- Internals ------------------------------------
908 public :
909
926 {
927 Integer x = ( c == '0' ) ? 1 : ( ( c == '2' ) ? -1 : 0 ) ;
928 Integer y = ( c == '1' ) ? 1 : ( ( c == '3' ) ? -1 : 0 ) ;
929 return Vector( x, y );
930 }
931
932
933
934 }; // end of class OneBalancedWordComputer
935
942 template < typename TConstIterator, typename TInteger >
943 std::ostream&
944 operator<< ( std::ostream & out,
946
947
948} // namespace DGtal
949
950
952// Includes inline functions.
953#include "DGtal/geometry/curves/OneBalancedWordComputer.ih"
954// //
956
957#endif // !defined OneBalancedWordComputer_h
958
959#undef OneBalancedWordComputer_RECURSES
960#endif // else defined(OneBalancedWordComputer_RECURSES)
Aim: This class represents a naive (resp. standard) digital straight line (DSL), ie....
bool longestChristoffelPrefix(ConstIterator it, const OrderedAlphabet &aOA)
void init(const FreemanChainCode &fc)
void translate(const Vector &v)
void init(const typename FreemanChainCode::ConstIterator &it)
bool isUL(Index pos) const
void computeLeaningPoints(Point &uf, Point &ul, Point &lf, Point &ll) const
ConstPointIterator pointEnd() const
ArithmeticalDSL< TInteger, TInteger, 4 > DSL
OneBalancedWordComputer< ConstIterator, Integer > Self
ConstPointIterator pointBegin() const
void init(const ConstIterator &it, const Point &start=Point(0, 0), Vector(*displacements)(Code)=defaultMoves)
OneBalancedWordComputer(const Self &other)
DGtal::PointVector< 2, Integer > Vector
void selfDisplay(std::ostream &out) const
bool operator==(const Self &other) const
void setPosition(const Point &p)
void init(const ConstPointIterator &i)
CodeHandler< ConstIterator > myCodeHandler
DGtal::PointVector< 2, Integer > Point
ConstIterator end() const
BOOST_CONCEPT_ASSERT((concepts::CInteger< TInteger >))
bool operator!=(const Self &other) const
IteratorCirculatorTraits< ConstIterator >::Value Code
Integer remainder(const Point &aPoint) const
ConstIterator begin() const
Vector displacement(Code c) const
bool previousIsLL(Index pos) const
Code getCode(Index pos) const
FreemanChain< TInteger > FreemanChainCode
bool nextIsLL(Index pos) const
OneBalancedWordComputer< ConstIterator, Integer > Reverse
OneBalancedWordComputer & operator=(const Self &other)
Aim: Describes an alphabet over an interval of (ascii) letters, where the lexicographic order can be ...
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
ConstPointIterator & operator=(const ConstPointIterator &other)
const OneBalancedWordComputer * getDSS() const
bool operator!=(const ConstPointIterator other) const
ConstPointIterator(const OneBalancedWordComputer *dss, Index ind, Point pt)
bool operator==(const ConstPointIterator other) const
ConstPointIterator(const ConstPointIterator &other)=default
Index operator-(const ConstPointIterator other) const
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition: CInteger.h:88
const Point aPoint(3, 4)