DGtal  0.9.2
KhalimskyPreSpaceND.h
1 
17 #pragma once
18 
31 #if defined(KhalimskyPreSpaceND_RECURSES)
32 #error Recursive header files inclusion detected in KhalimskyPreSpaceND.h
33 #else // defined(KhalimskyPreSpaceND_RECURSES)
34 
35 #define KhalimskyPreSpaceND_RECURSES
36 
37 #if !defined KhalimskyPreSpaceND_h
38 
39 #define KhalimskyPreSpaceND_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <set>
45 #include <map>
46 #include <DGtal/base/Common.h>
47 #include <DGtal/kernel/CInteger.h>
48 #include <DGtal/kernel/PointVector.h>
49 #include <DGtal/kernel/SpaceND.h>
51 
52 namespace DGtal
53 {
54 
56  // Pre-declaration
57  template <
58  Dimension dim,
59  typename TInteger = DGtal::int32_t
60  >
62 
64 
70  template < Dimension dim,
71  typename TInteger = DGtal::int32_t >
73  {
74 
75  // Integer must be a model of the concept CInteger.
77 
78  // Aliases
79  public:
80  using Integer = TInteger;
84  using PreCell = Self;
87 
88  // Public members
89  public:
91 
92  // Standard interface
93  public:
94 
96  PreCell const& preCell() const;
97 
99  explicit KhalimskyPreCell( Integer dummy = 0 );
100 
101 
105  KhalimskyPreCell( Point const& aPoint );
106 
110  KhalimskyPreCell( KhalimskyPreCell const& aCell ) = default;
111 
115  KhalimskyPreCell & operator=( KhalimskyPreCell const& aCell ) = default;
116 
120  KhalimskyPreCell( KhalimskyPreCell && aCell ) = default;
121 
125  KhalimskyPreCell & operator=( KhalimskyPreCell && aCell ) = default;
126 
131  bool operator==( const KhalimskyPreCell & other ) const;
132 
137  bool operator!=( const KhalimskyPreCell & other ) const;
138 
143  bool operator<( const KhalimskyPreCell & other ) const;
144 
145  // --------------- CDrawableWithBoard2D realization -------------------
146  public:
147 
151  std::string className() const;
152 
153  }; // KhalimskyPreCell
154 
155  template < Dimension dim,
156  typename TInteger >
157  std::ostream &
158  operator<<( std::ostream & out,
159  const KhalimskyPreCell< dim, TInteger > & object );
160 
167  template < Dimension dim,
168  typename TInteger = DGtal::int32_t >
170  {
171 
172  // Integer must be a model of the concept CInteger.
174 
175  // Aliases
176  public:
177  using Integer = TInteger;
181  using SPreCell = Self;
184 
185  // Public members
186  public:
188  bool positive;
189 
190  // Standard interface
191  public:
192 
194  SPreCell const& preCell() const;
195 
197  explicit SignedKhalimskyPreCell( Integer dummy = 0 );
198 
204  SignedKhalimskyPreCell( Point const& aPoint, bool positive );
205 
209  SignedKhalimskyPreCell( SignedKhalimskyPreCell const& aCell ) = default;
210 
214  SignedKhalimskyPreCell & operator=( SignedKhalimskyPreCell const& aCell ) = default;
215 
219  SignedKhalimskyPreCell( SignedKhalimskyPreCell && aCell ) = default;
220 
225 
230  bool operator==( const SignedKhalimskyPreCell & other ) const;
231 
236  bool operator!=( const SignedKhalimskyPreCell & other ) const;
237 
242  bool operator<( const SignedKhalimskyPreCell & other ) const;
243 
244  // --------------- CDrawableWithBoard2D realization -------------------
245  public:
246 
250  std::string className() const;
251 
252  }; // SignedKhalimskyPreCell
253 
254  template < Dimension dim,
255  typename TInteger >
256  std::ostream &
257  operator<<( std::ostream & out,
259 
274  template < Dimension dim,
275  typename TInteger = DGtal::int32_t >
277  {
278  public:
279  typedef TInteger Integer;
280  // Cells
283 
284  public:
290  explicit PreCellDirectionIterator( Cell cell, bool open = true );
291 
297  explicit PreCellDirectionIterator( SCell scell, bool open = true );
298 
302  Dimension operator*() const;
303 
308 
315  bool operator!=( const Integer ) const;
316 
320  bool end() const;
321 
326  bool operator!=( const PreCellDirectionIterator & other ) const;
327 
332  bool operator==( const PreCellDirectionIterator & other ) const;
333 
334  private:
338  Cell myCell;
341  bool myOpen;
342 
343  private:
345  void find();
346  };
347 
349  // template class KhalimskyPreSpaceND
368  template <
369  Dimension dim,
370  typename TInteger
371  >
372  class KhalimskyPreSpaceND
373  {
374  //Integer must be signed to characterize a ring.
376 
377  public:
379  using Integer = TInteger;
380 
381  // Cells
384 
385  using Surfel = SCell;
386  using Sign = bool;
388 
389  // Points and Vectors
392 
395 
396  // static constants
397  static constexpr const Dimension dimension = dim;
398  static constexpr const Dimension DIM = dim;
399  static constexpr const Sign POS = true;
400  static constexpr const Sign NEG = false;
401 
402  template <typename CellType>
403  struct AnyCellCollection : public std::deque<CellType> {
404  using Value = CellType;
405  using Container = typename std::deque<CellType>;
406  using Iterator = typename std::deque<CellType>::iterator;
407  using ConstIterator = typename std::deque<CellType>::const_iterator;
408  };
409 
410  // Neighborhoods, Incident cells, Faces and Cofaces
413 
414  // Sets, Maps
416  using CellSet = std::set<Cell>;
417 
419  using SCellSet = std::set<SCell>;
420 
422  using SurfelSet = std::set<SCell>;
423 
426  template <typename Value> struct CellMap {
427  typedef std::map<Cell,Value> Type;
428  };
429 
432  template <typename Value> struct SCellMap {
433  typedef std::map<SCell,Value> Type;
434  };
435 
438  template <typename Value> struct SurfelMap {
439  typedef std::map<SCell,Value> Type;
440  };
441 
442  // ----------------------- Pre-cell creation services --------------------------
446  public:
447 
454  static Cell uCell( const Point & kp );
455 
464  static Cell uCell( Point p, const Cell & c );
465 
473  static SCell sCell( const Point & kp, Sign sign = POS );
474 
483  static SCell sCell( Point p, const SCell & c );
484 
491  static Cell uSpel( Point p );
492 
500  static SCell sSpel( Point p, Sign sign = POS );
501 
508  static Cell uPointel( Point p );
509 
517  static SCell sPointel( Point p, Sign sign = POS );
518 
520 
521  // ----------------------- Read accessors to pre-cells ------------------------
525  public:
531  static Integer uKCoord( const Cell & c, Dimension k );
532 
538  static Integer uCoord( const Cell & c, Dimension k );
539 
544  static const Point & uKCoords( const Cell & c );
545 
550  static Point uCoords( const Cell & c );
551 
557  static Integer sKCoord( const SCell & c, Dimension k );
558 
564  static Integer sCoord( const SCell & c, Dimension k );
565 
570  static const Point & sKCoords( const SCell & c );
571 
576  static Point sCoords( const SCell & c );
577 
582  static Sign sSign( const SCell & c );
583 
585 
586  // ----------------------- Write accessors to pre-cells ------------------------
590  public:
591 
597  static void uSetKCoord( Cell & c, Dimension k, Integer i );
598 
604  static void sSetKCoord( SCell & c, Dimension k, Integer i );
605 
611  static void uSetCoord( Cell & c, Dimension k, Integer i );
612 
618  static void sSetCoord( SCell & c, Dimension k, Integer i );
619 
624  static void uSetKCoords( Cell & c, const Point & kp );
625 
630  static void sSetKCoords( SCell & c, const Point & kp );
631 
636  static void uSetCoords( Cell & c, const Point & kp );
637 
642  static void sSetCoords( SCell & c, const Point & kp );
643 
648  static void sSetSign( SCell & c, Sign s );
649 
651 
652  // -------------------- Conversion signed/unsigned ------------------------
656  public:
662  static SCell signs( const Cell & p, Sign s );
663 
668  static Cell unsigns( const SCell & p );
669 
675  static SCell sOpp( const SCell & p );
676 
678 
679  // ------------------------- Pre-cell topology services -----------------------
683  public:
688  static Integer uTopology( const Cell & p );
689 
694  static Integer sTopology( const SCell & p );
695 
700  static Dimension uDim( const Cell & p );
701 
706  static Dimension sDim( const SCell & p );
707 
712  static bool uIsSurfel( const Cell & b );
713 
718  static bool sIsSurfel( const SCell & b );
719 
725  static bool uIsOpen( const Cell & p, Dimension k );
726 
732  static bool sIsOpen( const SCell & p, Dimension k );
733 
735 
736  // -------------------- Iterator services for pre-cells ------------------------
740  public:
741 
760  static DirIterator uDirs( const Cell & p );
761 
780  static DirIterator sDirs( const SCell & p );
781 
800  static DirIterator uOrthDirs( const Cell & p );
801 
820  static DirIterator sOrthDirs( const SCell & p );
821 
828  static Dimension uOrthDir( const Cell & s );
829 
836  static Dimension sOrthDir( const SCell & s );
837 
839 
840  // -------------------- Unsigned pre-cell geometry services --------------------
844  public:
845 
852  static Cell uGetIncr( Cell p, Dimension k );
853 
860  static bool uIsMax( const Cell & p, Dimension k );
861 
862 
869  static bool uIsInside( const Cell & p, Dimension k );
870 
871 
877  static bool uIsInside( const Cell & p );
878 
885  static Cell uGetDecr( Cell p, Dimension k );
886 
892  static bool uIsMin( const Cell & p, Dimension k );
893 
901  static Cell uGetAdd( Cell p, Dimension k, Integer x );
902 
910  static Cell uGetSub( Cell p, Dimension k, Integer x );
911 
918  static Cell uTranslation( Cell p, const Vector & vec );
919 
930  static Cell uProjection( Cell p, const Cell & bound, Dimension k );
931 
940  static void uProject( Cell & p, const Cell & bound, Dimension k );
941 
961  static bool uNext( Cell & p, const Cell & lower, const Cell & upper );
962 
964 
965  // -------------------- Signed pre-cell geometry services --------------------
969  public:
970 
977  static SCell sGetIncr( SCell p, Dimension k );
978 
985  static bool sIsMax( const SCell & p, Dimension k );
986 
987 
994  static bool sIsInside( const SCell & p, Dimension k );
995 
996 
1002  static bool sIsInside( const SCell & p );
1003 
1010  static SCell sGetDecr( SCell p, Dimension k );
1011 
1017  static bool sIsMin( const SCell & p, Dimension k );
1018 
1026  static SCell sGetAdd( SCell p, Dimension k, Integer x );
1027 
1035  static SCell sGetSub( SCell p, Dimension k, Integer x );
1036 
1043  static SCell sTranslation( SCell p, const Vector & vec );
1044 
1055  static SCell sProjection( SCell p, const SCell & bound, Dimension k );
1056 
1065  static void sProject( SCell & p, const SCell & bound, Dimension k );
1066 
1086  static bool sNext( SCell & p, const SCell & lower, const SCell & upper );
1087 
1089 
1090  // ----------------------- Neighborhood services --------------------------
1094  public:
1095 
1103  static Cells uNeighborhood( const Cell & cell );
1104 
1112  static SCells sNeighborhood( const SCell & cell );
1113 
1121  static Cells uProperNeighborhood( const Cell & cell );
1122 
1130  static SCells sProperNeighborhood( const SCell & cell );
1131 
1141  static Cell uAdjacent( const Cell & p, Dimension k, bool up );
1142 
1152  static SCell sAdjacent( const SCell & p, Dimension k, bool up );
1153 
1155 
1156  // ----------------------- Incidence services --------------------------
1160  public:
1161 
1172  static Cell uIncident( Cell c, Dimension k, bool up );
1173 
1187  static SCell sIncident( SCell c, Dimension k, bool up );
1188 
1193  static Cells uLowerIncident( const Cell & c );
1194 
1199  static Cells uUpperIncident( const Cell & c );
1200 
1206  static SCells sLowerIncident( const SCell & c );
1207 
1213  static SCells sUpperIncident( const SCell & c );
1214 
1219  static Cells uFaces( const Cell & c );
1220 
1225  static Cells uCoFaces( const Cell & c );
1226 
1241  static bool sDirect( const SCell & p, Dimension k );
1242 
1249  static SCell sDirectIncident( SCell p, Dimension k );
1250 
1257  static SCell sIndirectIncident( SCell p, Dimension k );
1258 
1260 
1261 
1262  // ------------------------- Internals ------------------------------------
1266  private:
1270  static void uAddFaces( Cells & faces, const Cell & c, Dimension axis );
1271 
1275  static void uAddCoFaces( Cells & cofaces, const Cell & c, Dimension axis );
1276 
1278 
1279  // ----------------------- Interface --------------------------------------
1283  public:
1284 
1289  static void selfDisplay ( std::ostream & out );
1290 
1295  static constexpr bool isValid();
1296 
1298 
1299  }; // end of class KhalimskyPreSpaceND
1300 
1307  template < Dimension dim,
1308  typename TInteger >
1309  std::ostream&
1310  operator<< ( std::ostream & out,
1311  const KhalimskyPreSpaceND<dim, TInteger > & object );
1312 
1313 } // namespace DGtal
1314 
1315 
1317 // Includes inline functions.
1318 #include "DGtal/topology/KhalimskyPreSpaceND.ih"
1319 
1320 // //
1322 
1323 #endif // !defined KhalimskyPreSpaceND_h
1324 
1325 #undef KhalimskyPreSpaceND_RECURSES
1326 #endif // else defined(KhalimskyPreSpaceND_RECURSES)
bool operator!=(const KhalimskyPreCell &other) const
static bool sIsSurfel(const SCell &b)
bool operator!=(const SignedKhalimskyPreCell &other) const
bool operator!=(const Integer) const
static SCell sOpp(const SCell &p)
static Cell uTranslation(Cell p, const Vector &vec)
bool operator==(const KhalimskyPreCell &other) const
static SCell sGetSub(SCell p, Dimension k, Integer x)
SignedKhalimskyPreCell< dim, Integer > SCell
static SCell sGetAdd(SCell p, Dimension k, Integer x)
static DirIterator uDirs(const Cell &p)
Point coordinates
Khalimsky coordinates of the cell. Public to allow easy coordinate manipulations. ...
static bool sIsMax(const SCell &p, Dimension k)
static SCell sGetIncr(SCell p, Dimension k)
std::string className() const
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
static Sign sSign(const SCell &c)
static void sProject(SCell &p, const SCell &bound, Dimension k)
static Integer sCoord(const SCell &c, Dimension k)
static void selfDisplay(std::ostream &out)
DGtal::uint32_t Dimension
Definition: Common.h:113
KhalimskyPreCell< dim, Integer > Cell
static SCell sSpel(Point p, Sign sign=POS)
static SCells sLowerIncident(const SCell &c)
static Cell uPointel(Point p)
static Cell uGetAdd(Cell p, Dimension k, Integer x)
SignedKhalimskyPreCell(Integer dummy=0)
Default constructor.
static SCell sIncident(SCell c, Dimension k, bool up)
static Cell uSpel(Point p)
std::set< SCell > SurfelSet
Preferred type for defining a set of surfels (always signed cells).
typename NumberTraits< Integer >::UnsignedVersion UnsignedInteger
static Dimension sDim(const SCell &p)
static void uSetCoord(Cell &c, Dimension k, Integer i)
static Cells uLowerIncident(const Cell &c)
static SCell sGetDecr(SCell p, Dimension k)
static DirIterator sOrthDirs(const SCell &p)
Aim: This class is a model of CPreCellularGridSpaceND. It represents the cubical grid as a cell compl...
SignedKhalimskyPreCell< dim, Integer > SCell
typename NumberTraits< Integer >::UnsignedVersion UnsignedInteger
static Cell uCell(const Point &kp)
static Point sCoords(const SCell &c)
typename std::deque< CellType >::iterator Iterator
This class is useful for looping on all "interesting" coordinates of a pre-cell. For instance...
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition: CInteger.h:87
PreCell const & preCell() const
Returns the underlying constant pre-cell, itself in fact.
SignedKhalimskyPreCell< dim, Integer > Self
static bool sDirect(const SCell &p, Dimension k)
static void uAddCoFaces(Cells &cofaces, const Cell &c, Dimension axis)
static SCell sTranslation(SCell p, const Vector &vec)
static Dimension uOrthDir(const Cell &s)
bool operator==(const PreCellDirectionIterator &other) const
PreCellDirectionIterator(Cell cell, bool open=true)
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
static DirIterator sDirs(const SCell &p)
KhalimskyPreSpaceND< dim, TInteger > PreCellularGridSpace
static Point uCoords(const Cell &c)
static Cell uGetIncr(Cell p, Dimension k)
static SCell sIndirectIncident(SCell p, Dimension k)
KhalimskyPreCell< dim, Integer > Self
static Cells uFaces(const Cell &c)
static SCell sAdjacent(const SCell &p, Dimension k, bool up)
static bool uNext(Cell &p, const Cell &lower, const Cell &upper)
static void sSetCoords(SCell &c, const Point &kp)
static const Point & uKCoords(const Cell &c)
static bool sIsOpen(const SCell &p, Dimension k)
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
bool operator<(const KhalimskyPreCell &other) const
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:69
Point coordinates
Khalimsky coordinates of the cell.
static bool uIsMin(const Cell &p, Dimension k)
static Cells uCoFaces(const Cell &c)
PreCellDirectionIterator & operator++()
static SCell signs(const Cell &p, Sign s)
static Cells uProperNeighborhood(const Cell &cell)
static Integer uKCoord(const Cell &c, Dimension k)
static Cell uIncident(Cell c, Dimension k, bool up)
std::string className() const
static SCell sDirectIncident(SCell p, Dimension k)
bool operator==(const SignedKhalimskyPreCell &other) const
static DirIterator uOrthDirs(const Cell &p)
static bool uIsInside(const Cell &p, Dimension k)
SignedKhalimskyPreCell & operator=(SignedKhalimskyPreCell const &aCell)=default
static Integer sKCoord(const SCell &c, Dimension k)
static constexpr const Sign POS
static void sSetSign(SCell &c, Sign s)
static Dimension uDim(const Cell &p)
static void uAddFaces(Cells &faces, const Cell &c, Dimension axis)
static Cell unsigns(const SCell &p)
DGtal is the top-level namespace which contains all DGtal functions and types.
static Integer uCoord(const Cell &c, Dimension k)
static void sSetKCoords(SCell &c, const Point &kp)
BOOST_CONCEPT_ASSERT((concepts::CInteger< TInteger >))
static void uProject(Cell &p, const Cell &bound, Dimension k)
static bool sIsInside(const SCell &p, Dimension k)
KhalimskyPreCell & operator=(KhalimskyPreCell const &aCell)=default
static void sSetCoord(SCell &c, Dimension k, Integer i)
static Cells uNeighborhood(const Cell &cell)
static constexpr const Sign NEG
std::set< SCell > SCellSet
Preferred type for defining a set of SCell(s).
static Cell uGetSub(Cell p, Dimension k, Integer x)
static Integer uTopology(const Cell &p)
KhalimskyPreCell(Integer dummy=0)
Default constructor.
static SCell sPointel(Point p, Sign sign=POS)
static Cell uAdjacent(const Cell &p, Dimension k, bool up)
static bool sIsMin(const SCell &p, Dimension k)
SPreCell const & preCell() const
Returns the underlying constant pre-cell, itself in fact.
static bool uIsOpen(const Cell &p, Dimension k)
static Cells uUpperIncident(const Cell &c)
static constexpr const Dimension dimension
static bool sNext(SCell &p, const SCell &lower, const SCell &upper)
static void uSetKCoord(Cell &c, Dimension k, Integer i)
static void sSetKCoord(SCell &c, Dimension k, Integer i)
static bool uIsSurfel(const Cell &b)
static Cell uGetDecr(Cell p, Dimension k)
static const Point & sKCoords(const SCell &c)
static Integer sTopology(const SCell &p)
static void uSetKCoords(Cell &c, const Point &kp)
KhalimskyPreSpaceND< dim, TInteger > PreCellularGridSpace
boost::int32_t int32_t
signed 32-bit integer.
Definition: BasicTypes.h:72
static Cell uProjection(Cell p, const Cell &bound, Dimension k)
static SCells sUpperIncident(const SCell &c)
Dimension operator*() const
static Dimension sOrthDir(const SCell &s)
static void uSetCoords(Cell &c, const Point &kp)
BOOST_CONCEPT_ASSERT((concepts::CInteger< TInteger >))
static bool uIsMax(const Cell &p, Dimension k)
static SCells sProperNeighborhood(const SCell &cell)
static SCell sProjection(SCell p, const SCell &bound, Dimension k)
typename std::deque< CellType >::const_iterator ConstIterator
BOOST_CONCEPT_ASSERT((concepts::CInteger< TInteger >))
static SCells sNeighborhood(const SCell &cell)
std::set< Cell > CellSet
Preferred type for defining a set of Cell(s).
static SCell sCell(const Point &kp, Sign sign=POS)
static constexpr bool isValid()
static constexpr const Dimension DIM
bool operator<(const SignedKhalimskyPreCell &other) const