63{
64 trace.
info() <<
"Usage: " << argv[ 0 ] <<
" <thickness> <convexity> <input.vol> <m> <M>" << std::endl;
65 trace.
info() <<
" - convexity in {0,1}: 0=0-convexity, 1=full-convexity"<< std::endl;
66
67 int thickness = argc > 1 ? atoi( argv[ 1 ] ) : 2;
68 bool full_cvx = argc > 2 ? atoi( argv[ 2 ] ) == 1 : false;
69 std::string fn= argc > 3 ? argv[ 3 ] : "";
70 int m = argc > 4 ? atoi( argv[ 4 ] ) : 0;
71 int M = argc > 5 ? atoi( argv[ 5 ] ) : 255;
72 trace.
beginBlock (
"Example of 3D shape thinning with full convexity properties" );
73
74 QApplication application(argc,argv);
76 viewer.setWindowTitle("fullConvexityThinning3D");
78
79 auto params = SH3::defaultParameters();
80
81
82 trace.
info() <<
"Building set or importing vol ... ";
84 Point p1( -50, -50, -50 );
85 Point p2( 50, 50, 50 );
88 std::set< Point > shape_set;
90 if ( fn == "" )
91 {
92 K.
init( p1, p2,
true );
94 {
96 if ( ((p - c ).norm() <= 22+thickness ) && ((p - c ).norm() >= 20-thickness)
97 && ( ((p[0] <= thickness)&& (p[0] >= -thickness))
98 || ((p[1] <= thickness)&& (p[1] >= -thickness))))
99 {
100 shape_set.insert( p );
101 bimage->setValue( p, true );
102 }
103 else
104 bimage->setValue( p, false );
105 }
106 }
107 else
108 {
109 params( "thresholdMin", m );
110 params( "thresholdMax", M );
111 bimage = SH3::makeBinaryImage( fn, params );
112 K = SH3::getKSpace( bimage );
117 if ( (*bimage)( p ) ) shape_set.
insert( p );
118 }
119 std::set< Point > origin_set( shape_set );
121
122 {
123 params( "surfaceComponents" , "All" );
124 auto surface = SH3::makeDigitalSurface( bimage,
K, params );
125 bool ok = SH3::saveOBJ(
surface,
"source.obj" );
126 }
127
129 SH3::BinaryImage& image = *bimage;
130 NCA nca( p1, p2, 10000 );
131 int nb_simple=0;
132 std::set< Point >::iterator it, itE;
133 std::set< Point > to_process( shape_set );
134 do
135 {
136 std::set< Point > next_to_process;
137 nb_simple = 0;
138 trace.
info() <<
"Pass #S=" << shape_set.size()
139 << " #Q=" << to_process.size() << std::endl;
140 for ( auto it = to_process.begin(), itE = to_process.end(); it != itE; ++it )
141 {
143 if ( ! image( p ) ) continue;
144 nca.setCenter( p, image );
145 if ( full_cvx
146 ? nca.isFullyConvexCollapsible()
147 : nca.is0ConvexCollapsible() )
148 {
149 std::vector< Point > neighbors;
150 nca.getLocalX( neighbors, false );
151 for (
auto q : neighbors ) next_to_process.
insert( q );
152 shape_set.erase( p );
153 image.setValue( p, false );
154 ++nb_simple;
155 }
156 }
157 trace.
info() <<
" => nb_removed=" << nb_simple<< std::endl;
158 if ( nb_simple != 0 )
159 std::swap( to_process, next_to_process );
160 }
161 while ( nb_simple != 0 );
163
164 {
165 params( "surfaceComponents" , "All" );
166 auto surface = SH3::makeDigitalSurface( bimage,
K, params );
167 SH3::saveOBJ(
surface,
"geom-thinned.obj" );
168 }
169
170
173 for (
auto p : origin_set ) origin.
insert( p );
174 for (
auto p : shape_set ) output.
insert( p );
175 viewer <<
SetMode3D( output.className(),
"Paving" );
177 viewer << output;
178
179 viewer <<
SetMode3D( origin.className(),
"PavingTransp" );
181 viewer << origin;
182
183 viewer<< Viewer3D<>::updateDisplay;
184
185
187 return application.exec();
188
189}
Structure representing an RGB triple with alpha component.
Aim: Smart pointer based on reference counts.
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Iterator for HyperRectDomain.
const ConstIterator & begin() const
const ConstIterator & end() const
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
const Point & lowerBound() const
Return the lower bound for digital points in this space.
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
const Point & upperBound() const
Return the upper bound for digital points in this space.
void beginBlock(const std::string &keyword="")
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
CountedPtr< SH3::DigitalSurface > surface
NeighborhoodConvexityAnalyzer< KSpace, 1 > NCA
HyperRectDomain< Space > Domain
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
void insert(VContainer1 &c1, LContainer2 &c2, unsigned int idx, double v)