243{
244 if ( argc <= 2 )
245 {
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;
252 return 1;
253 }
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;
258
259 auto params = SH3::defaultParameters();
260
261
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 );
269
270 params( "surfaceComponents" , "All" );
271 auto surface = SH3::makeDigitalSurface( bimage,
K, params );
272
273
274
275 std::vector< Point > points;
276 std::map< SCell, int > surfel2idx;
277 std::map< Point, int > point2idx;
278 int idx = 0;
280 {
281
285 auto it = point2idx.find( p );
286 if ( it == point2idx.end() )
287 {
288 points.push_back( p );
289 surfel2idx[ s ] = idx;
290 point2idx [ p ] = idx++;
291 }
292 else
293 surfel2idx[ s ] = it->second;
294 }
295 trace.
info() <<
"Shape has " << points.size() <<
" interior boundary points"
296 << std::endl;
297 if ( N != 0 )
298 {
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++ )
314 {
315 const auto j = surfel2idx[ surfels[ i ] ];
316 all_colors[ i ] = colors[ result[ j ] ];
317 }
318 SH3::saveOBJ(
surface, SH3::RealVectors(), all_colors,
"geom-cvx.obj" );
320 int i = 0;
322 {
323 viewer << all_colors[ i ]
324 << s;
325 i++;
326 }
328 }
329 else
330 {
332 auto geometry =
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 ) ];
359 else
360 all_colors[ i ] = colors_ccv[ 5 -
abs( m0 - m1 ) ];
361 }
362 SH3::saveOBJ(
surface, SH3::RealVectors(), all_colors,
"geom-scale-cvx.obj" );
364 int i = 0;
367 {
368 viewer << all_colors[ i ]
369 << s;
370 i++;
371 }
373 }
374 return 0;
375}
Structure representing an RGB triple with alpha component.
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Dimension sOrthDir(const SCell &s) const
Given a signed surfel [s], returns its orthogonal direction (ie, the coordinate where the surfel is c...
Point sCoords(const SCell &c) const
Return its digital coordinates.
bool sDirect(const SCell &p, Dimension k) const
Return 'true' if the direct orientation of [p] along [k] is in the positive coordinate direction.
SCell sIncident(const SCell &c, Dimension k, bool up) const
Return the forward or backward signed cell incident to [c] along axis [k], depending on [up].
void show() override
Starts the event loop and display of elements.
void beginBlock(const std::string &keyword="")
CountedPtr< SH3::DigitalSurface > surface
DGtal::uint32_t Dimension
static std::vector< int > run(const KSpace &aK, const std::vector< Point > &pts, ImagePtr bimage)
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
static std::vector< Geometry > multiscale_run(const KSpace &aK, const std::vector< Point > &pts, ImagePtr bimage)