Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
homotopicThinning3D.cpp
Go to the documentation of this file.
1
16
29
30
42
43
45#include <iostream>
46#include <queue>
47#include "DGtal/base/Common.h"
48#include "DGtal/io/viewers/PolyscopeViewer.h"
49#include "DGtal/io/Color.h"
50#include "DGtal/shapes/Shapes.h"
51#include "DGtal/helpers/StdDefs.h"
52
54
55using namespace std;
56using namespace DGtal;
57using namespace Z3i;
58
60
61
62
63int main( int argc, char** argv )
64{
65
66 trace.beginBlock ( "Example simple example of 3DViewer" );
67
68 PolyscopeViewer<> viewer;
69
70 // Domain cretation from two bounding points.
71 Point c( 0, 0, 0 );
72 Point p1( -50, -50, -50 );
73 Point p2( 50, 50, 50 );
74 Domain domain( p1, p2 );
75
76 trace.warning() << "Constructing a ring DigitalSet ... ";
77 DigitalSet shape_set( domain );
78 for (Domain::ConstIterator it = domain.begin(); it != domain.end(); ++it )
79 {
80 if ( ((*it - c ).norm() <= 25) && ((*it - c ).norm() >= 18)
81 && ( (((*it)[0] <= 3)&& ((*it)[0] >= -3))|| (((*it)[1] <= 3)&& ((*it)[1] >= -3)))){
82 shape_set.insertNew( *it );
83 }
84 }
85 trace.warning() << " [Done]" << std::endl;
86
87 trace.beginBlock ( "Thinning" );
88 Object18_6 shape( dt18_6, shape_set );
89 int nb_simple=0;
91 do
92 {
93 DigitalSet & S = shape.pointSet();
94 std::queue<DigitalSet::Iterator> Q;
95 it = S.begin();
96 itE = S.end();
97#ifdef DGTAL_WITH_OPENMP
98 std::vector<DigitalSet::Iterator> v( S.size() );
99 std::vector<uint8_t> b( v.size() );
100 for ( size_t i = 0; it != itE; ++it, ++i )
101 v[ i ] = it;
102#pragma omp parallel for schedule(dynamic)
103 for ( size_t i = 0; i < v.size(); ++i )
104 b[ i ] = shape.isSimple( *(v[ i ]) );
105
106 for ( size_t i = 0; i < v.size(); ++i )
107 if ( b[ i ] ) Q.push( v[ i ] );
108#else
109 for ( ; it != itE; ++it )
110 if ( shape.isSimple( *it ) )
111 Q.push( it );
112#endif
113 nb_simple = 0;
114 while ( ! Q.empty() )
115 {
116 DigitalSet::Iterator itt = Q.front();
117 Q.pop();
118 if ( shape.isSimple( *itt ) )
119 {
120 S.erase( *itt );
121 ++nb_simple;
122 }
123 }
124 }
125 while ( nb_simple != 0 );
126 DigitalSet & S = shape.pointSet();
127 trace.endBlock();
128
129 // Display by using two different list to manage OpenGL transparency.
130
131 viewer << Color(25,25,255, 255);
132 viewer << S ;
133
134 viewer << Color(250, 0,0, 25);
135 viewer << shape_set;
136
137
138 trace.endBlock();
139 viewer.show();
140 return 0;
141
142}
143// //
145
Structure representing an RGB triple with alpha component.
Definition Color.h:77
const DigitalSet & pointSet() const
bool isSimple(const Point &v) const
void show() override
Starts the event loop and display of elements.
Z3i this namespace gathers the standard of types for 3D imagery.
static const DT18_6 dt18_6
Definition StdDefs.h:195
Object< DT18_6, DigitalSet > Object18_6
Definition StdDefs.h:178
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition StdDefs.h:173
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
STL namespace.
int main()
Definition testBits.cpp:56
Domain domain