DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
generateSimplicityTables3D.cpp
1 
32 
33 #include <iostream>
34 #include <vector>
35 #include <bitset>
36 #include "DGtal/topology/Object.h"
37 #include "DGtal/helpers/StdDefs.h"
38 
40 
41 using namespace std;
42 using namespace DGtal;
43 
45 
61 template <typename Object, typename Map>
62 void
63 generateSimplicityTable( const typename Object::DigitalTopology & dt,
64  Map & map )
65 {
67  typedef typename Object::DigitalSet DigitalSet;
68  typedef typename Object::Point Point;
69  typedef typename DigitalSet::Domain Domain;
70  typedef typename Domain::ConstIterator DomainConstIterator;
71 
72  Point p1 = Point::diagonal( -1 );
73  Point p2 = Point::diagonal( 1 );
74  Point c = Point::diagonal( 0 );
75  Domain domain( p1, p2 );
76  DigitalSet shapeSet( domain );
77  Object shape( dt, shapeSet );
78  unsigned int k = 0;
79  for ( DomainConstIterator it = domain.begin(); it != domain.end(); ++it )
80  if ( *it != c ) ++k;
81  ASSERT( ( k < 32 )
82  && "[generateSimplicityTable] number of configurations is too high." );
83  unsigned int nbCfg = 1 << k;
84  for ( unsigned int cfg = 0; cfg < nbCfg; ++cfg )
85  {
86  if ( ( cfg % 1000 ) == 0 )
87  {
88  trace.progressBar( (double) cfg, (double) nbCfg );
89  }
90  shape.pointSet().clear();
91  shape.pointSet().insert( c );
92  unsigned int mask = 1;
93  for ( DomainConstIterator it = domain.begin(); it != domain.end(); ++it )
94  {
95  if ( *it != c )
96  {
97  if ( cfg & mask ) shape.pointSet().insert( *it );
98  mask <<= 1;
99  }
100  }
101  bool simple = shape.isSimple( c );
102  map[ cfg ] = simple;
103  }
104 }
105 
106 
107 
108 int main( int argc, char** argv )
109 {
110  typedef std::bitset<67108864> ConfigMap; // 2^26
111 
112  using namespace Z3i;
113  trace.beginBlock ( "Generate 3d table for 26_6 topology" );
114  // Too big for stack. Use heap instead.
115  ConfigMap* table26_6 = new ConfigMap;
116  generateSimplicityTable< Object26_6 >( dt26_6, *table26_6 );
117  trace.endBlock();
118 
119  ofstream file26_6( "simplicity_table26_6.txt" );
120  file26_6 << *table26_6;
121  file26_6.close();
122 
123  delete table26_6;
124  return 0;
125 }
126 // //