DGtal  1.5.beta
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)
34 #define VoxelComplex_RECURSES
35 
36 #if !defined VoxelComplex_h
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>
52 class VoxelComplex;
53 
54 template <typename TKSpace, typename TCellContainer>
55 VoxelComplex<TKSpace, TCellContainer> &
56 operator-=(VoxelComplex<TKSpace, TCellContainer> &,
57  const VoxelComplex<TKSpace, TCellContainer> &);
58 template <typename TKSpace, typename TCellContainer>
59 VoxelComplex<TKSpace, TCellContainer>
60 operator-(const VoxelComplex<TKSpace, TCellContainer> &,
61  const VoxelComplex<TKSpace, 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 
109  static const Dimension dimension = KSpace::dimension;
110 
112  using Integer = typename KSpace::Integer;
114  using Cell = typename KSpace::Cell;
116  using PreCell = typename Cell::PreCell;
118  using Cells = typename KSpace::Cells;
120  using Space = typename KSpace::Space;
122  using Size = typename KSpace::Size;
124  using Point = typename KSpace::Point;
130  using CellMapConstIterator = typename CellMap::const_iterator;
132  using CellMapIterator = typename CellMap::iterator;
133 
134  // Clique alias
135  using Clique = Parent;
136  using CliqueContainer = std::vector<Clique>;
137 
138  // Tables
139  using ConfigMap = boost::dynamic_bitset<>;
140  using PointToMaskMap = std::unordered_map<Point, unsigned int>;
141 
142  protected:
149  public:
152 
158  VoxelComplex( const VoxelComplex & other );
159 
165  Self &operator=(const Self &other);
166 
181  template < typename TDigitalSet >
182  void construct(const TDigitalSet &input_set,
183  const Alias<ConfigMap> input_table);
184  using Parent::construct;
185 
193  void setSimplicityTable(const Alias<ConfigMap> input_table);
194 
201  void copySimplicityTable(const Self & other);
202 
208  const ConfigMap &table() const;
209 
215  const bool &isTableLoaded() const;
216 
224  void voxelClose(const Cell &kcell);
225 
232  void cellsClose(Dimension k_d, const Cells &cells);
233 
241  void insertVoxelCell(const Cell &kcell, const bool &close_it = true,
242  const Data &data = Data());
243 
250  void insertVoxelCell(const std::pair<Cell, Data> &data_pair,
251  const bool &close_it = true) {
252  insertVoxelCell(data_pair.first, close_it, data_pair.second);
253  }
254 
263  void insertVoxelPoint(const Point &dig_point, const bool &close_it = true,
264  const Data &data = Data());
265 
273  template<typename TDigitalSet>
274  void dumpVoxels(TDigitalSet & in_out_set) const;
275 
276  //------ Spels ------//
287  void pointelsFromCell(std::set<Cell> &pointels_out,
288  const Cell &input_cell) const;
299  void spelsFromCell(std::set<Cell> &spels_out, const Cell &input_cell) const;
300 
308  std::set<Cell> neighborhoodVoxels(const Cell &input_cell) const;
309 
320  std::set<Cell> properNeighborhoodVoxels(const Cell &input_cell) const;
321 
332  Clique Kneighborhood(const Cell &input_cell) const;
333 
346  bool isSimpleByThinning(const Cell &input_spel) const;
355  bool isSimple(const Cell &input_spel) const;
356 
357  //------ Cliques ------//
358  // Cliques, union of adjacent spels.
359  // The intersection of all spels of the clique define the type.
360  // 0-clique, 1-clique, 2-clique. 3-clique are isolated spels.
361  public:
370  std::pair<bool, Clique>
372  const CellMapConstIterator &cellMapIterator) const;
373 
383  std::array<CliqueContainer, dimension + 1>
384  criticalCliques(const Parent &cubical, bool verbose = false) const {
385  ASSERT((dimension + 1) == 4);
386  std::array<CliqueContainer, dimension + 1> criticals;
387  if (verbose) {
388  trace.beginBlock("criticalCliques of CubicalComplex");
389  trace.info() << cubical << std::endl;
390  }
391  for (Dimension d = 0; d != dimension + 1; ++d)
392  criticals[d] = criticalCliquesForD(d, cubical, verbose);
393 
394  if (verbose) {
395  trace.info() << std::endl;
396  trace.endBlock();
397  }
398  return criticals;
399  }
407  std::array<CliqueContainer, dimension + 1>
408  criticalCliques(bool verbose = false) const {
409  return criticalCliques(*this, verbose);
410  }
411 
426  const Parent &cubical,
427  bool verbose = false) const;
428 
440  std::pair<bool, Clique> K_2(const Cell &A, const Cell &B,
441  bool verbose = false) const;
452  std::pair<bool, Clique> K_2(const typename KSpace::Point &A,
453  const typename KSpace::Point &B,
454  bool verbose = false) const;
455 
465  std::pair<bool, Clique> K_2(const Cell &face2, bool verbose = false) const;
466 
475  std::pair<bool, Clique> K_1(const Cell &face1, bool verbose = false) const;
476 
485  std::pair<bool, Clique> K_0(const Cell &face0, bool verbose = false) const;
486 
498  std::pair<bool, Clique> K_3(const Cell &input_spel,
499  bool verbose = false) const;
507  bool isSpel(const Cell &c) const;
508 
517  Cell surfelBetweenAdjacentSpels(const Cell &A, const Cell &B) const;
518 
519  /*------------- Data --------------*/
520  protected:
525  bool myIsTableLoaded{false};
526 
527  /*------------- Internal Methods --------------*/
536  const PointToMaskMap &pointToMask() const;
537 
538  // ----------------------- Interface --------------------------------------
539  public:
544  void selfDisplay(std::ostream &out) const;
545 
550  bool isValid() const;
551 
552  // --------------- CDrawableWithBoard2D realization ------------------
553  public:
557  std::string className() const;
558 
559 }; // end of class CubicalComplex
560 
567 template <typename TKSpace, typename TCellContainer>
568 std::ostream &
569 operator<<(std::ostream &out,
571 
572 } // namespace DGtal
573 
575 // Includes inline functions.
576 #include "DGtal/topology/VoxelComplex.ih"
577 
578 // //
580 
581 #endif // !defined VoxelComplex_h
582 
583 #undef VoxelComplex_RECURSES
584 #endif // else defined(VoxelComplex_RECURSES)
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: Alias.h:183
Aim: This class represents an arbitrary cubical complex living in some Khalimsky space....
void construct(const TDigitalSet &set)
typename PreCellularGridSpace::DirIterator DirIterator
AnyCellCollection< Cell > Cells
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
This class represents a voxel complex living in some Khalimsky space. Voxel complexes are derived fro...
Definition: VoxelComplex.h:91
void dumpVoxels(TDigitalSet &in_out_set) const
std::pair< bool, Clique > K_2(const typename KSpace::Point &A, const typename KSpace::Point &B, bool verbose=false) const
typename KSpace::Point Point
Definition: VoxelComplex.h:124
typename CellMap::const_iterator CellMapConstIterator
Definition: VoxelComplex.h:130
std::pair< bool, Clique > K_3(const Cell &input_spel, bool verbose=false) const
typename CellContainer::mapped_type Data
Definition: VoxelComplex.h:106
std::unordered_map< Point, unsigned int > PointToMaskMap
Definition: VoxelComplex.h:140
void insertVoxelCell(const std::pair< Cell, Data > &data_pair, const bool &close_it=true)
Definition: VoxelComplex.h:250
void cellsClose(Dimension k_d, const Cells &cells)
typename KSpace::Space Space
Definition: VoxelComplex.h:120
bool isValid() const
typename KSpace::Integer Integer
Definition: VoxelComplex.h:112
const PointToMaskMap & pointToMask() const
Self & operator=(const Self &other)
void copySimplicityTable(const Self &other)
void setSimplicityTable(const Alias< ConfigMap > input_table)
void voxelClose(const Cell &kcell)
CubicalComplex< TKSpace, TCellContainer > Parent
Definition: VoxelComplex.h:100
std::set< Cell > neighborhoodVoxels(const Cell &input_cell) const
const ConfigMap & table() const
std::array< CliqueContainer, dimension+1 > criticalCliques(bool verbose=false) const
Definition: VoxelComplex.h:408
VoxelComplex(const VoxelComplex &other)
bool myIsTableLoaded
Flag if using a LUT for simplicity.
Definition: VoxelComplex.h:525
std::array< CliqueContainer, dimension+1 > criticalCliques(const Parent &cubical, bool verbose=false) const
Definition: VoxelComplex.h:384
Clique Kneighborhood(const Cell &input_cell) const
CliqueContainer criticalCliquesForD(const Dimension d, const Parent &cubical, bool verbose=false) const
void insertVoxelPoint(const Point &dig_point, const bool &close_it=true, const Data &data=Data())
std::pair< bool, Clique > K_2(const Cell &A, const Cell &B, bool verbose=false) const
TCellContainer CellContainer
Definition: VoxelComplex.h:104
std::pair< bool, Clique > criticalCliquePair(const Dimension d, const CellMapConstIterator &cellMapIterator) const
CountedPtrOrPtr< PointToMaskMap > myPointToMaskPtr
Definition: VoxelComplex.h:524
CountedPtrOrPtr< ConfigMap > myTablePtr
Definition: VoxelComplex.h:522
std::set< Cell > properNeighborhoodVoxels(const Cell &input_cell) const
void construct(const TDigitalSet &input_set, const Alias< ConfigMap > input_table)
typename KSpace::DirIterator DirIterator
Definition: VoxelComplex.h:126
bool isSpel(const Cell &c) const
bool isSimple(const Cell &input_spel) const
std::pair< bool, Clique > K_2(const Cell &face2, bool verbose=false) const
static const Dimension dimension
The dimension of the embedding space.
Definition: VoxelComplex.h:109
std::pair< bool, Clique > K_0(const Cell &face0, bool verbose=false) const
const bool & isTableLoaded() const
void pointelsFromCell(std::set< Cell > &pointels_out, const Cell &input_cell) const
void spelsFromCell(std::set< Cell > &spels_out, const Cell &input_cell) const
std::pair< bool, Clique > K_1(const Cell &face1, bool verbose=false) const
CellContainer CellMap
Definition: VoxelComplex.h:128
Cell surfelBetweenAdjacentSpels(const Cell &A, const Cell &B) const
boost::dynamic_bitset<> ConfigMap
Definition: VoxelComplex.h:139
void selfDisplay(std::ostream &out) const
bool isSimpleByThinning(const Cell &input_spel) const
void insertVoxelCell(const Cell &kcell, const bool &close_it=true, const Data &data=Data())
typename KSpace::Cell Cell
Definition: VoxelComplex.h:114
std::string className() const
typename CellMap::iterator CellMapIterator
Definition: VoxelComplex.h:132
typename Cell::PreCell PreCell
Definition: VoxelComplex.h:116
std::vector< Clique > CliqueContainer
Definition: VoxelComplex.h:136
typename KSpace::Cells Cells
Definition: VoxelComplex.h:118
typename KSpace::Size Size
Definition: VoxelComplex.h:122
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
DGtal::uint32_t Dimension
Definition: Common.h:136
Trace trace
Definition: Common.h:153
KForm< Calculus, order, duality > operator-(const KForm< Calculus, order, duality > &form_a, const KForm< Calculus, order, duality > &form_b)
CubicalComplex< TKSpace, TCellContainer > & operator-=(CubicalComplex< TKSpace, TCellContainer > &, const CubicalComplex< TKSpace, TCellContainer > &)
MyPointD Point
Definition: testClone2.cpp:383
KSpace::Cell Cell
HalfEdgeDataStructure::Size Size