DGtal  0.9.4.1
NeighborhoodTablesGenerators.h
1 
31 #if defined(NeighborhoodConfigurationsGenerators_RECURSES)
32 #error Recursive header files inclusion detected in NeighborhoodConfigurationsGenerators.h
33 #else // defined(NeighborhoodConfigurationsGenerators_RECURSES)
34 
35 #define NeighborhoodConfigurationsGenerators_RECURSES
36 
37 #if !defined NeighborhoodConfigurationsGenerators_h
38 
39 #define NeighborhoodConfigurationsGenerators_h
40 // Inclusions
42 #include <iostream>
43 #include <bitset>
44 #include <memory>
45 #include "DGtal/topology/Object.h"
46 #include "DGtal/helpers/StdDefs.h"
47 #include <unordered_map>
48 #include "boost/dynamic_bitset.hpp"
49 #include <DGtal/topology/helpers/NeighborhoodConfigurationsHelper.h>
50 #include "DGtal/topology/VoxelComplexFunctions.h"
51 
52 namespace DGtal {
53  namespace functions {
54 
69  template <typename TObject, typename TMap>
70  void
72  const typename TObject::DigitalTopology & dt,
73  TMap & map )
74  {
75  typedef typename TObject::DigitalSet DigitalSet;
76  typedef typename TObject::Point Point;
77  typedef typename DigitalSet::Domain Domain;
78  typedef typename Domain::ConstIterator DomainConstIterator;
79 
80  Point p1 = Point::diagonal( -1 );
81  Point p2 = Point::diagonal( 1 );
82  Point c = Point::diagonal( 0 );
83  Domain domain( p1, p2 );
84  DigitalSet shapeSet( domain );
85  TObject shape( dt, shapeSet );
86  unsigned int k = 0;
87  for ( DomainConstIterator it = domain.begin(); it != domain.end(); ++it )
88  if ( *it != c ) ++k;
89  ASSERT( ( k < 32 )
90  && "[generateSimplicityTable] number of configurations is too high." );
91  unsigned int nbCfg = 1 << k;
92  for ( NeighborhoodConfiguration cfg = 0; cfg < nbCfg; ++cfg )
93  {
94  if ( ( cfg % 1000 ) == 0 )
95  {
96  trace.progressBar( (double) cfg, (double) nbCfg );
97  }
98  shape.pointSet().clear();
99  shape.pointSet().insert( c );
100  NeighborhoodConfiguration mask = 1;
101  for ( DomainConstIterator it = domain.begin(); it != domain.end(); ++it )
102  {
103  if ( *it != c )
104  {
105  if ( cfg & mask ) shape.pointSet().insert( *it );
106  mask <<= 1;
107  }
108  }
109  bool simple = shape.isSimple( c );
110  map[ cfg ] = simple;
111  }
112  }
113 
130  template <typename TVoxelComplex, typename TMap>
131  void
133  TMap & map,
134  std::function< bool(
135  const TVoxelComplex & ,
136  const typename TVoxelComplex::Cell & )
137  > skelFunction
138  )
139  {
140  using Object = typename TVoxelComplex::Object;
141  using DigitalSet = typename Object::DigitalSet ;
142  using Point = typename Object::Point ;
143  using Domain = typename DigitalSet::Domain ;
144  using DomainConstIterator = typename Domain::ConstIterator ;
145  using KSpace = typename TVoxelComplex::KSpace;
146  using DigitalTopology = typename Object::DigitalTopology;
147  using ForegroundAdjacency = typename Object::ForegroundAdjacency;
148  using BackgroundAdjacency = typename Object::BackgroundAdjacency;
149  ForegroundAdjacency adjF;
150  BackgroundAdjacency adjB;
151  DigitalTopology dt( adjF, adjB,
152  DigitalTopologyProperties::JORDAN_DT);
153 
154  Point p1 = Point::diagonal( -1 );
155  Point p2 = Point::diagonal( 1 );
156  Point c = Point::diagonal( 0 );
157  Domain domain( p1, p2 );
158  DigitalSet shapeSet( domain );
159  Object shape( dt, shapeSet );
160  unsigned int k = 0;
161  for ( DomainConstIterator it = domain.begin(); it != domain.end(); ++it )
162  if ( *it != c ) ++k;
163  ASSERT( ( k < 32 )
164  && "[generateVoxelComplexTable] number of configurations is too high." );
165  unsigned int nbCfg = 1 << k;
166 
167  KSpace ks;
168  // Pad KSpace domain.
169  ks.init(shape.domain().lowerBound() + Point::diagonal( -1 ) ,
170  shape.domain().upperBound() + Point::diagonal( 1 ),
171  true);
172  TVoxelComplex vc(ks);
173  vc.construct(shape);
174  for ( unsigned int cfg = 0; cfg < nbCfg; ++cfg ){
175  if ( ( cfg % 1000 ) == 0 )
176  trace.progressBar( (double) cfg, (double) nbCfg );
177  vc.clear();
178  vc.insertVoxelPoint(c);
179  unsigned int mask = 1;
180  for ( DomainConstIterator it = domain.begin(); it != domain.end(); ++it ){
181  if ( *it != c ) {
182  if ( cfg & mask ) vc.insertVoxelPoint( *it );
183  mask <<= 1;
184  }
185  }
186  const auto &kcell = vc.space().uSpel(c);
187  bool predicate_output = skelFunction(vc, kcell);
188  map[ cfg ] = predicate_output;
189  }
190  }
191  }// namespace functions
192 }// namespace DGtal
194 
195 #endif // !defined NeighborhoodConfigurationsGenerators_h
196 
197 #undef NeighborhoodConfigurationsGenerators_RECURSES
198 #endif // else defined(NeighborhoodConfigurationsGenerators_RECURSES)
Aim: An object (or digital object) represents a set in some digital space associated with a digital t...
Definition: Object.h:119
HyperRectDomain< Space > Domain
void progressBar(const double currentValue, const double maximalValue)
DigitalSet::Point Point
Definition: Object.h:141
void generateSimplicityTable(const typename TObject::DigitalTopology &dt, TMap &map)
MyDigitalSurface::ConstIterator ConstIterator
Trace trace
Definition: Common.h:137
TDigitalSet DigitalSet
Definition: Object.h:123
uint32_t NeighborhoodConfiguration
Domain domain
TDigitalTopology DigitalTopology
Definition: Object.h:138
Aim: Represents a digital topology as a couple of adjacency relations.
DigitalTopology::BackgroundAdjacency BackgroundAdjacency
Definition: Object.h:151
DigitalTopology::ForegroundAdjacency ForegroundAdjacency
Definition: Object.h:150
bool init(const Point &lower, const Point &upper, bool isClosed)
const Domain & domain() const
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
KSpace::Cell Cell
void generateVoxelComplexTable(TMap &map, std::function< bool(const TVoxelComplex &, const typename TVoxelComplex::Cell &) > skelFunction)
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex...