242int main(
int argc,
char** argv )
246 trace.
info() <<
"Usage: " << argv[ 0 ] <<
" <K> <input.vol> <m> <M>" << std::endl;
247 trace.
info() <<
"\tAnalyze the shape with local full convexity" << std::endl;
248 trace.
info() <<
"\t- 1 <= K <= 5: analysis at scale K" << std::endl;
249 trace.
info() <<
"\t- K == 0: multiscale analysis (using scales 1-5)" << std::endl;
250 trace.
info() <<
"\t- input.vol: choose your favorite shape" << std::endl;
251 trace.
info() <<
"\t- m [==0], M [==255]: used to threshold input vol image" << std::endl;
254 int N = atoi( argv[ 1 ] );
255 std::string fn= argv[ 2 ];
256 int m = argc > 3 ? atoi( argv[ 3 ] ) : 0;
257 int M = argc > 4 ? atoi( argv[ 4 ] ) : 255;
259 auto params = SH3::defaultParameters();
262 trace.
info() <<
"Building set or importing vol ... ";
264 params(
"thresholdMin", m );
265 params(
"thresholdMax", M );
266 auto bimage = SH3::makeBinaryImage( fn, params );
267 K = SH3::getKSpace( bimage );
270 params(
"surfaceComponents" ,
"All" );
271 auto surface = SH3::makeDigitalSurface( bimage,
K, params );
275 std::vector< Point > points;
276 std::map< SCell, int > surfel2idx;
277 std::map< Point, int > point2idx;
279 for (
auto s : (*surface) )
285 auto it = point2idx.find( p );
286 if ( it == point2idx.end() )
288 points.push_back( p );
289 surfel2idx[ s ] = idx;
290 point2idx [ p ] = idx++;
293 surfel2idx[ s ] = it->second;
295 trace.
info() <<
"Shape has " << points.size() <<
" interior boundary points"
299 std::vector< int > result;
309 {
Color( 255, 0, 0, 255 ),
Color( 0, 255, 0, 255 ),
310 Color( 0, 0, 255, 255 ),
Color( 255, 255, 255, 255 ) };
311 auto surfels = SH3::getSurfelRange(
surface, params );
312 SH3::Colors all_colors( surfels.size() );
313 for (
size_t i = 0; i < surfels.size(); i++ )
315 const auto j = surfel2idx[ surfels[ i ] ];
316 all_colors[ i ] = colors[ result[ j ] ];
318 SH3::saveOBJ(
surface, SH3::RealVectors(), all_colors,
"geom-cvx.obj" );
321 for (
auto s : (*surface) )
323 viewer << all_colors[ i ]
335 Color colors_planar[ 6 ] =
336 {
Color( 0, 255, 255, 255),
337 Color( 50, 255, 255, 255),
Color( 100, 255, 255, 255),
338 Color( 150, 255, 255, 255),
Color( 200, 255, 255, 255 ),
339 Color( 255, 255, 255, 255 ) };
340 Color color_atypical( 255, 0, 0, 255 );
341 Color colors_cvx[ 5 ] =
342 {
Color( 0, 255, 0, 255 ),
Color( 50, 255, 50, 255 ),
343 Color( 100, 255, 100, 255 ),
Color( 150, 255, 150, 255 ),
344 Color( 200, 255, 200, 255 ) };
345 Color colors_ccv[ 5 ] =
346 {
Color( 0, 0, 255, 255 ),
Color( 50, 50, 255, 255 ),
347 Color( 100, 100, 255, 255 ),
Color( 150, 150, 255, 255 ),
348 Color( 200, 200, 255, 255 ) };
349 auto surfels = SH3::getSurfelRange(
surface, params );
350 SH3::Colors all_colors( surfels.size() );
351 for (
size_t i = 0; i < surfels.size(); i++ ) {
352 const auto j = surfel2idx[ surfels[ i ] ];
353 int m0 = std::min( geometry[ j ].first, geometry[ j ].second );
354 int m1 = std::max( geometry[ j ].first, geometry[ j ].second );
355 if ( m1 == 0 ) all_colors[ i ] = color_atypical;
356 else if ( m0 == m1 ) all_colors[ i ] = colors_planar[ 5 ];
357 else if ( geometry[ j ].first > geometry[ j ].second )
358 all_colors[ i ] = colors_cvx[ 5 - abs( m0 - m1 ) ];
360 all_colors[ i ] = colors_ccv[ 5 - abs( m0 - m1 ) ];
362 SH3::saveOBJ(
surface, SH3::RealVectors(), all_colors,
"geom-scale-cvx.obj" );
366 for (
auto s : (*surface) )
368 viewer << all_colors[ i ]