DGtal  1.0.0
VoxelComplex.h
1 
17 #pragma once
18 
30 #if defined(VoxelComplex_RECURSES)
31 #error Recursive header files inclusion detected in VoxelComplex.h
32 #else // defined(VoxelComplex_RECURSES)
33 
34 #define VoxelComplex_RECURSES
35 
36 #if !defined VoxelComplex_h
37 
38 #define VoxelComplex_h
39 
41 // Inclusions
42 #include "boost/dynamic_bitset.hpp"
43 #include <DGtal/kernel/sets/DigitalSetBySTLSet.h>
44 #include <DGtal/topology/CubicalComplex.h>
45 #include <DGtal/topology/DigitalTopology.h>
46 #include <DGtal/topology/Object.h>
47 
48 namespace DGtal {
49 
50 // Forward definitions.
51 template <typename TKSpace, typename TCellContainer>
53 
54 template <typename TKSpace, typename TCellContainer>
58 template <typename TKSpace, typename TCellContainer>
62 
64  // template class VoxelComplex
89 template <typename TKSpace,
90  typename TCellContainer = typename TKSpace::template CellMap< CubicalCellData >::Type >
91 class VoxelComplex : public CubicalComplex<TKSpace, TCellContainer> {
92  public:
95 
96  friend Self &DGtal::operator-=<>(Self &, const Self &);
97  friend Self DGtal::operator-<>(const Self &, const Self &);
98  // ----------------------- associated types ------------------------------
102  using KSpace = TKSpace;
104  using CellContainer = TCellContainer;
106  using Data = typename CellContainer::mapped_type;
107 
110 
112  using Integer = typename KSpace::Integer;
114  using Cell = typename KSpace::Cell;
116  using Cells = typename KSpace::Cells;
118  using Space = typename KSpace::Space;
120  using Size = typename KSpace::Size;
122  using Point = typename KSpace::Point;
128  using CellMapConstIterator = typename CellMap::const_iterator;
130  using CellMapIterator = typename CellMap::iterator;
131 
132  // Clique alias
133  using Clique = Parent;
134  using CliqueContainer = std::vector<Clique>;
135 
136  // Tables
137  using ConfigMap = boost::dynamic_bitset<>;
138  using PointToMaskMap = std::unordered_map<Point, unsigned int>;
139 
140  protected:
146  VoxelComplex();
147  public:
150 
156  VoxelComplex( const VoxelComplex & other );
157 
163  Self &operator=(const Self &other);
164 
171  template < typename TDigitalSet >
172  void construct(const TDigitalSet &input_set);
173 
188  template < typename TDigitalSet >
189  void construct(const TDigitalSet &input_set,
190  const Alias<ConfigMap> input_table);
191 
199  void setSimplicityTable(const Alias<ConfigMap> input_table);
200 
207  void copySimplicityTable(const Self & other);
208 
214  const ConfigMap &table() const;
215 
221  const bool &isTableLoaded() const;
222 
230  void voxelClose(const Cell &kcell);
231 
238  void cellsClose(Dimension k_d, const Cells &cells);
239 
247  void insertVoxelCell(const Cell &kcell, const bool &close_it = true,
248  const Data &data = Data());
249 
256  void insertVoxelCell(const std::pair<Cell, Data> &data_pair,
257  const bool &close_it = true) {
258  insertVoxelCell(data_pair.first, close_it, data_pair.second);
259  }
260 
269  void insertVoxelPoint(const Point &dig_point, const bool &close_it = true,
270  const Data &data = Data());
271 
279  template<typename TDigitalSet>
280  void dumpVoxels(TDigitalSet & in_out_set);
281 
286  void clear();
287 
288  //------ Spels ------//
299  void pointelsFromCell(std::set<Cell> &pointels_out,
300  const Cell &input_cell) const;
311  void spelsFromCell(std::set<Cell> &spels_out, const Cell &input_cell) const;
312 
320  std::set<Cell> neighborhoodVoxels(const Cell &input_cell) const;
321 
332  std::set<Cell> properNeighborhoodVoxels(const Cell &input_cell) const;
333 
344  Clique Kneighborhood(const Cell &input_cell) const;
345 
358  bool isSimpleByThinning(const Cell &input_spel) const;
372  bool isSimple(const Cell &input_spel) const;
373 
374  //------ Cliques ------//
375  // Cliques, union of adjacent spels.
376  // The intersection of all spels of the clique define the type.
377  // 0-clique, 1-clique, 2-clique. 3-clique are isolated spels.
378  public:
387  std::pair<bool, Clique>
389  const CellMapConstIterator &cellMapIterator) const;
390 
400  std::array<CliqueContainer, dimension + 1>
401  criticalCliques(const Parent &cubical, bool verbose = false) const {
402  ASSERT((dimension + 1) == 4);
403  std::array<CliqueContainer, dimension + 1> criticals;
404  if (verbose) {
405  trace.beginBlock("criticalCliques of CubicalComplex");
406  trace.info() << cubical << std::endl;
407  }
408  for (size_t d = 0; d != dimension + 1; ++d)
409  criticals[d] = criticalCliquesForD(d, cubical, verbose);
410 
411  if (verbose) {
412  trace.info() << std::endl;
413  trace.endBlock();
414  }
415  return criticals;
416  }
424  std::array<CliqueContainer, dimension + 1>
425  criticalCliques(bool verbose = false) const {
426  return criticalCliques(*this, verbose);
427  }
428 
443  const Parent &cubical,
444  bool verbose = false) const;
445 
457  std::pair<bool, Clique> K_2(const Cell &A, const Cell &B,
458  bool verbose = false) const;
469  std::pair<bool, Clique> K_2(const typename KSpace::Point &A,
470  const typename KSpace::Point &B,
471  bool verbose = false) const;
472 
482  std::pair<bool, Clique> K_2(const Cell &face2, bool verbose = false) const;
483 
492  std::pair<bool, Clique> K_1(const Cell &face1, bool verbose = false) const;
493 
502  std::pair<bool, Clique> K_0(const Cell &face0, bool verbose = false) const;
503 
515  std::pair<bool, Clique> K_3(const Cell &input_spel,
516  bool verbose = false) const;
524  bool isSpel(const Cell &c) const;
525 
534  Cell surfelBetweenAdjacentSpels(const Cell &A, const Cell &B) const;
535 
536  /*------------- Data --------------*/
537  protected:
542  bool myIsTableLoaded{false};
543 
544  /*------------- Internal Methods --------------*/
553  const PointToMaskMap &pointToMask() const;
554 
555  // ----------------------- Interface --------------------------------------
556  public:
561  void selfDisplay(std::ostream &out) const;
562 
567  bool isValid() const;
568 
569  // --------------- CDrawableWithBoard2D realization ------------------
570  public:
574  std::string className() const;
575 
576 }; // end of class CubicalComplex
577 
584 template <typename TKSpace, typename TCellContainer>
585 std::ostream &
586 operator<<(std::ostream &out,
587  const VoxelComplex<TKSpace, TCellContainer> &object);
588 
589 } // namespace DGtal
590 
592 // Includes inline functions.
593 #include "DGtal/topology/VoxelComplex.ih"
594 
595 // //
597 
598 #endif // !defined VoxelComplex_h
599 
600 #undef VoxelComplex_RECURSES
601 #endif // else defined(VoxelComplex_RECURSES)
std::pair< bool, Clique > criticalCliquePair(const Dimension d, const CellMapConstIterator &cellMapIterator) const
void beginBlock(const std::string &keyword="")
std::set< Cell > properNeighborhoodVoxels(const Cell &input_cell) const
std::pair< bool, Clique > K_0(const Cell &face0, bool verbose=false) const
std::set< Cell > neighborhoodVoxels(const Cell &input_cell) const
std::pair< bool, Clique > K_3(const Cell &input_spel, bool verbose=false) const
Trace trace
Definition: Common.h:144
Self & operator=(const Self &other)
CellContainer::mapped_type Data
Type of data associated to each cell.
bool isValid() const
DGtal::uint32_t Dimension
Definition: Common.h:127
void insertVoxelPoint(const Point &dig_point, const bool &close_it=true, const Data &data=Data())
std::vector< Clique > CliqueContainer
Definition: VoxelComplex.h:134
This class represents a voxel complex living in some Khalimsky space. Voxel complexes are derived fro...
Definition: VoxelComplex.h:52
double endBlock()
CountedPtrOrPtr< ConfigMap > myTablePtr
Definition: VoxelComplex.h:539
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: Alias.h:182
CountedPtrOrPtr< PointToMaskMap > myPointToMaskPtr
Definition: VoxelComplex.h:541
const ConfigMap & table() const
std::string className() const
CellMap::const_iterator CellMapConstIterator
Const iterator for visiting type CellMap.
void copySimplicityTable(const Self &other)
void dumpVoxels(TDigitalSet &in_out_set)
const bool & isTableLoaded() const
void construct(const TDigitalSet &input_set)
NumberTraits< Integer >::UnsignedVersion Size
Type used to represent sizes in the digital space.
void selfDisplay(std::ostream &out) const
std::unordered_map< Point, unsigned int > PointToMaskMap
Definition: VoxelComplex.h:138
KForm< Calculus, order, duality > operator-(const KForm< Calculus, order, duality > &form_a, const KForm< Calculus, order, duality > &form_b)
void insertVoxelCell(const Cell &kcell, const bool &close_it=true, const Data &data=Data())
CliqueContainer criticalCliquesForD(const Dimension d, const Parent &cubical, bool verbose=false) const
std::pair< bool, Clique > K_2(const Cell &A, const Cell &B, bool verbose=false) const
void setSimplicityTable(const Alias< ConfigMap > input_table)
void voxelClose(const Cell &kcell)
typename KSpace ::template CellMap< CubicalCellData >::Type CellContainer
Type for storing cells, an associative container Cell -> Data.
CC::CellMapConstIterator CellMapConstIterator
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
KhalimskyCell< dim, Integer > Cell
void spelsFromCell(std::set< Cell > &spels_out, const Cell &input_cell) const
boost::dynamic_bitset<> ConfigMap
Definition: VoxelComplex.h:137
Aim: This class represents an arbitrary cubical complex living in some Khalimsky space....
bool myIsTableLoaded
Flag if using a LUT for simplicity.
Definition: VoxelComplex.h:542
SpaceND< dim, Integer > Space
bool isSimpleByThinning(const Cell &input_spel) const
void cellsClose(Dimension k_d, const Cells &cells)
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
std::array< CliqueContainer, dimension+1 > criticalCliques(bool verbose=false) const
Definition: VoxelComplex.h:425
std::ostream & info()
Cell surfelBetweenAdjacentSpels(const Cell &A, const Cell &B) const
typename CellContainer::mapped_type Data
Definition: VoxelComplex.h:106
void pointelsFromCell(std::set< Cell > &pointels_out, const Cell &input_cell) const
std::array< CliqueContainer, dimension+1 > criticalCliques(const Parent &cubical, bool verbose=false) const
Definition: VoxelComplex.h:401
PointVector< dim, Integer > Point
Clique Kneighborhood(const Cell &input_cell) const
TCellContainer CellContainer
Definition: VoxelComplex.h:104
typename PreCellularGridSpace::DirIterator DirIterator
bool isSimple(const Cell &input_spel) const
static const Dimension dimension
The dimension of the embedding space.
Definition: VoxelComplex.h:109
void insertVoxelCell(const std::pair< Cell, Data > &data_pair, const bool &close_it=true)
Definition: VoxelComplex.h:256
static const constexpr Dimension dimension
CellContainer CellMap
Type for storing cells, an associative container Cell -> Data.
CubicalComplex< TKSpace, TCellContainer > & operator-=(CubicalComplex< TKSpace, TCellContainer > &, const CubicalComplex< TKSpace, TCellContainer > &)
CubicalComplex< TKSpace, TCellContainer > Parent
Definition: VoxelComplex.h:100
const PointToMaskMap & pointToMask() const
std::pair< bool, Clique > K_1(const Cell &face1, bool verbose=false) const
AnyCellCollection< Cell > Cells
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
bool isSpel(const Cell &c) const