DGtal  0.9.4beta
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 
51 namespace DGtal {
52  namespace functions {
53 
68  template <typename TObject, typename TMap>
69  void
71  const typename TObject::DigitalTopology & dt,
72  TMap & map )
73  {
74  typedef typename TObject::DigitalSet DigitalSet;
75  typedef typename TObject::Point Point;
76  typedef typename DigitalSet::Domain Domain;
77  typedef typename Domain::ConstIterator DomainConstIterator;
78 
79  Point p1 = Point::diagonal( -1 );
80  Point p2 = Point::diagonal( 1 );
81  Point c = Point::diagonal( 0 );
82  Domain domain( p1, p2 );
83  DigitalSet shapeSet( domain );
84  TObject shape( dt, shapeSet );
85  unsigned int k = 0;
86  for ( DomainConstIterator it = domain.begin(); it != domain.end(); ++it )
87  if ( *it != c ) ++k;
88  ASSERT( ( k < 32 )
89  && "[generateSimplicityTable] number of configurations is too high." );
90  unsigned int nbCfg = 1 << k;
91  for ( NeighborhoodConfiguration cfg = 0; cfg < nbCfg; ++cfg )
92  {
93  if ( ( cfg % 1000 ) == 0 )
94  {
95  trace.progressBar( (double) cfg, (double) nbCfg );
96  }
97  shape.pointSet().clear();
98  shape.pointSet().insert( c );
100  for ( DomainConstIterator it = domain.begin(); it != domain.end(); ++it )
101  {
102  if ( *it != c )
103  {
104  if ( cfg & mask ) shape.pointSet().insert( *it );
105  mask <<= 1;
106  }
107  }
108  bool simple = shape.isSimple( c );
109  map[ cfg ] = simple;
110  }
111  }
112 
113  }// namespace functions
114 }// namespace DGtal
116 
117 #endif // !defined NeighborhoodConfigurationsGenerators_h
118 
119 #undef NeighborhoodConfigurationsGenerators_RECURSES
120 #endif // else defined(NeighborhoodConfigurationsGenerators_RECURSES)
void progressBar(const double currentValue, const double maximalValue)
const ConstIterator & begin() const
void generateSimplicityTable(const typename TObject::DigitalTopology &dt, TMap &map)
const ConstIterator & end() const
Trace trace
Definition: Common.h:137
uint32_t NeighborhoodConfiguration
DGtal is the top-level namespace which contains all DGtal functions and types.