DGtal  0.9.2
homotopicThinning3D.cpp
1 
30 #include <iostream>
32 #include <queue>
33 #include "DGtal/base/Common.h"
34 #include "DGtal/io/viewers/Viewer3D.h"
35 #include "DGtal/io/DrawWithDisplay3DModifier.h"
36 #include "DGtal/io/Color.h"
37 #include "DGtal/shapes/Shapes.h"
38 #include "DGtal/helpers/StdDefs.h"
39 
41 
42 using namespace std;
43 using namespace DGtal;
44 using namespace Z3i;
45 
47 
48 
49 
50 int main( int argc, char** argv )
51 {
52 
53  trace.beginBlock ( "Example simple example of 3DViewer" );
54 
55  QApplication application(argc,argv);
56  Viewer3D<> viewer;
57  viewer.setWindowTitle("simpleExample3DViewer");
58  viewer.show();
59 
60  // Domain cretation from two bounding points.
61  Point c( 0, 0, 0 );
62  Point p1( -50, -50, -50 );
63  Point p2( 50, 50, 50 );
64  Domain domain( p1, p2 );
65 
66  trace.warning() << "Constructing a ring DigitalSet ... ";
67  DigitalSet shape_set( domain );
68  for (Domain::ConstIterator it = domain.begin(); it != domain.end(); ++it )
69  {
70  if ( ((*it - c ).norm() <= 25) && ((*it - c ).norm() >= 18)
71  && ( (((*it)[0] <= 3)&& ((*it)[0] >= -3))|| (((*it)[1] <= 3)&& ((*it)[1] >= -3)))){
72  shape_set.insertNew( *it );
73  }
74  }
75  trace.warning() << " [Done]" << std::endl;
76 
77  trace.beginBlock ( "Thinning" );
78  Object18_6 shape( dt18_6, shape_set );
79  int nb_simple=0;
80  DigitalSet::Iterator it, itE;
81  do
82  {
83  DigitalSet & S = shape.pointSet();
84  std::queue<DigitalSet::Iterator> Q;
85  it = S.begin();
86  itE = S.end();
87 #ifdef WITH_OPENMP
88  std::vector<DigitalSet::Iterator> v( S.size() );
89  std::vector<uint8_t> b( v.size() );
90  for ( size_t i = 0; it != itE; ++it, ++i )
91  v[ i ] = it;
92 #pragma omp parallel for schedule(dynamic)
93  for ( size_t i = 0; i < v.size(); ++i )
94  b[ i ] = shape.isSimple( *(v[ i ]) );
95 
96  for ( size_t i = 0; i < v.size(); ++i )
97  if ( b[ i ] ) Q.push( v[ i ] );
98 #else
99  for ( ; it != itE; ++it )
100  if ( shape.isSimple( *it ) )
101  Q.push( it );
102 #endif
103  nb_simple = 0;
104  while ( ! Q.empty() )
105  {
106  DigitalSet::Iterator itt = Q.front();
107  Q.pop();
108  if ( shape.isSimple( *itt ) )
109  {
110  S.erase( *itt );
111  ++nb_simple;
112  }
113  }
114  }
115  while ( nb_simple != 0 );
116  DigitalSet & S = shape.pointSet();
117  trace.endBlock();
118 
119  // Display by using two different list to manage OpenGL transparency.
120 
121  viewer << SetMode3D( shape_set.className(), "Paving" );
122  viewer << CustomColors3D(Color(25,25,255, 255), Color(25,25,255, 255));
123  viewer << S ;
124 
125  viewer << SetMode3D( shape_set.className(), "PavingTransp" );
126  viewer << CustomColors3D(Color(250, 0,0, 25), Color(250, 0,0, 5));
127  viewer << shape_set;
128 
129  viewer<< Viewer3D<>::updateDisplay;
130 
131 
132  trace.endBlock();
133  return application.exec();
134 
135 }
136 // //
138 
139 
void beginBlock(const std::string &keyword="")
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
const ConstIterator & begin() const
const ConstIterator & end() const
Trace trace
Definition: Common.h:130
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
STL namespace.
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & warning()
Object< DT18_6, DigitalSet > Object18_6
Definition: StdDefs.h:178
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
Modifier class in a Display3D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithDisplay3D.