DGtal 1.3.0
Loading...
Searching...
No Matches
homotopicThinning3D.cpp
Go to the documentation of this file.
1
45#include <iostream>
46#include <queue>
47#include "DGtal/base/Common.h"
48#include "DGtal/io/viewers/Viewer3D.h"
49#include "DGtal/io/DrawWithDisplay3DModifier.h"
50#include "DGtal/io/Color.h"
51#include "DGtal/shapes/Shapes.h"
52#include "DGtal/helpers/StdDefs.h"
53
55
56using namespace std;
57using namespace DGtal;
58using namespace Z3i;
59
61
62
63
64int main( int argc, char** argv )
65{
66
67 trace.beginBlock ( "Example simple example of 3DViewer" );
68
69 QApplication application(argc,argv);
70 Viewer3D<> viewer;
71 viewer.setWindowTitle("simpleExample3DViewer");
72 viewer.show();
73
74 // Domain cretation from two bounding points.
75 Point c( 0, 0, 0 );
76 Point p1( -50, -50, -50 );
77 Point p2( 50, 50, 50 );
78 Domain domain( p1, p2 );
79
80 trace.warning() << "Constructing a ring DigitalSet ... ";
81 DigitalSet shape_set( domain );
82 for (Domain::ConstIterator it = domain.begin(); it != domain.end(); ++it )
83 {
84 if ( ((*it - c ).norm() <= 25) && ((*it - c ).norm() >= 18)
85 && ( (((*it)[0] <= 3)&& ((*it)[0] >= -3))|| (((*it)[1] <= 3)&& ((*it)[1] >= -3)))){
86 shape_set.insertNew( *it );
87 }
88 }
89 trace.warning() << " [Done]" << std::endl;
90
91 trace.beginBlock ( "Thinning" );
92 Object18_6 shape( dt18_6, shape_set );
93 int nb_simple=0;
95 do
96 {
97 DigitalSet & S = shape.pointSet();
98 std::queue<DigitalSet::Iterator> Q;
99 it = S.begin();
100 itE = S.end();
101#ifdef WITH_OPENMP
102 std::vector<DigitalSet::Iterator> v( S.size() );
103 std::vector<uint8_t> b( v.size() );
104 for ( size_t i = 0; it != itE; ++it, ++i )
105 v[ i ] = it;
106#pragma omp parallel for schedule(dynamic)
107 for ( size_t i = 0; i < v.size(); ++i )
108 b[ i ] = shape.isSimple( *(v[ i ]) );
109
110 for ( size_t i = 0; i < v.size(); ++i )
111 if ( b[ i ] ) Q.push( v[ i ] );
112#else
113 for ( ; it != itE; ++it )
114 if ( shape.isSimple( *it ) )
115 Q.push( it );
116#endif
117 nb_simple = 0;
118 while ( ! Q.empty() )
119 {
120 DigitalSet::Iterator itt = Q.front();
121 Q.pop();
122 if ( shape.isSimple( *itt ) )
123 {
124 S.erase( *itt );
125 ++nb_simple;
126 }
127 }
128 }
129 while ( nb_simple != 0 );
130 DigitalSet & S = shape.pointSet();
131 trace.endBlock();
132
133 // Display by using two different list to manage OpenGL transparency.
134
135 viewer << SetMode3D( shape_set.className(), "Paving" );
136 viewer << CustomColors3D(Color(25,25,255, 255), Color(25,25,255, 255));
137 viewer << S ;
138
139 viewer << SetMode3D( shape_set.className(), "PavingTransp" );
140 viewer << CustomColors3D(Color(250, 0,0, 25), Color(250, 0,0, 5));
141 viewer << shape_set;
142
143 viewer<< Viewer3D<>::updateDisplay;
144
145
146 trace.endBlock();
147 return application.exec();
148
149}
150// //
152
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Container::iterator Iterator
Iterator type of the container.
Iterator for HyperRectDomain.
const ConstIterator & begin() const
const ConstIterator & end() const
Aim: An object (or digital object) represents a set in some digital space associated with a digital t...
Definition: Object.h:120
const DigitalSet & pointSet() const
bool isSimple(const Point &v) const
void beginBlock(const std::string &keyword="")
std::ostream & warning()
double endBlock()
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
static const DT18_6 dt18_6
Definition: StdDefs.h:195
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
int main()
Definition: testBits.cpp:56
Domain domain