File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/config/TeX-MML-AM_CHTML/MathJax.js
DGtal 2.0.0
fullConvexityAnalysis3D.cpp File Reference
#include <iostream>
#include <queue>
#include "DGtal/base/Common.h"
#include "DGtal/io/viewers/PolyscopeViewer.h"
#include "DGtal/io/Color.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/helpers/Shortcuts.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/geometry/volumes/NeighborhoodConvexityAnalyzer.h"
Include dependency graph for fullConvexityAnalysis3D.cpp:

Go to the source code of this file.

Data Structures

struct  Analyzer< KSpace, N >
struct  MultiScaleAnalyzer< KSpace, N >
struct  MultiScaleAnalyzer< KSpace, 0 >
 Specialization. More...

Functions

int main (int argc, char **argv)

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2021/06/20

An example file named fullConvexityAnalysis3D

This file is part of the DGtal library.

Definition in file fullConvexityAnalysis3D.cpp.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 242 of file fullConvexityAnalysis3D.cpp.

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 // Domain creation from two bounding points.
262 trace.info() << "Building set or importing vol ... ";
263 KSpace K;
264 params( "thresholdMin", m );
265 params( "thresholdMax", M );
266 auto bimage = SH3::makeBinaryImage( fn, params );
267 K = SH3::getKSpace( bimage );
268 trace.info() << " [Done]" << std::endl;
269 // Compute surface
270 params( "surfaceComponents" , "All" );
271 auto surface = SH3::makeDigitalSurface( bimage, K, params );
272
273 // Compute interior boundary points
274 // They are less immediate interior points than surfels.
275 std::vector< Point > points;
276 std::map< SCell, int > surfel2idx;
277 std::map< Point, int > point2idx;
278 int idx = 0;
279 for ( auto s : (*surface) )
280 {
281 // get inside point on the border of the shape.
282 Dimension k = K.sOrthDir( s );
283 auto voxel = K.sIncident( s, k, K.sDirect( s, k ) );
284 Point p = K.sCoords( voxel );
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;
300 trace.beginBlock ( "Single scale analysis" );
301 if ( N == 1 ) result = Analyzer< KSpace, 1 >::run( K, points, bimage );
302 if ( N == 2 ) result = Analyzer< KSpace, 2 >::run( K, points, bimage );
303 if ( N == 3 ) result = Analyzer< KSpace, 3 >::run( K, points, bimage );
304 if ( N == 4 ) result = Analyzer< KSpace, 4 >::run( K, points, bimage );
305 if ( N == 5 ) result = Analyzer< KSpace, 5 >::run( K, points, bimage );
306 trace.endBlock();
307 SCell dummy;
308 Color colors[ 4 ] =
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 ( int 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" );
319 PolyscopeViewer viewer;
320 int i = 0;
321 for ( auto s : (*surface) )
322 {
323 viewer << all_colors[ i ]
324 << s;
325 i++;
326 }
327 viewer.show();
328 }
329 else
330 {
331 trace.beginBlock ( "Multiscale analysis" );
332 auto geometry =
334 trace.endBlock();
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 ( int 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" );
363 SCell dummy;
364 int i = 0;
365 PolyscopeViewer<> viewer;
366 for ( auto s : (*surface) )
367 {
368 viewer << all_colors[ i ]
369 << s;
370 i++;
371 }
372 viewer.show();
373 }
374 return 0;
375}
Structure representing an RGB triple with alpha component.
Definition Color.h:77
void show() override
Starts the event loop and display of elements.
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
Definition Shortcuts.h:333
std::vector< Color > Colors
Definition Shortcuts.h:193
static SurfelRange getSurfelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1548
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1210
std::vector< RealVector > RealVectors
Definition Shortcuts.h:180
static Parameters defaultParameters()
Definition Shortcuts.h:204
static bool saveOBJ(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > digsurf, const TCellEmbedder &embedder, const RealVectors &normals, const Colors &diffuse_colors, std::string objfile, const Color &ambient_color=Color(32, 32, 32), const Color &diffuse_color=Color(200, 200, 255), const Color &specular_color=Color::White)
Definition Shortcuts.h:1740
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
Definition Shortcuts.h:562
CountedPtr< SH3::DigitalSurface > surface
KhalimskySpaceND< 3, Integer > KSpace
Definition StdDefs.h:146
KSpace::SCell SCell
Definition StdDefs.h:149
DGtal::uint32_t Dimension
Definition Common.h:119
Trace trace
static std::vector< int > run(const KSpace &aK, const std::vector< Point > &pts, ImagePtr bimage)
static std::vector< Geometry > multiscale_run(const KSpace &aK, const std::vector< Point > &pts, ImagePtr bimage)
KSpace K

References DGtal::Shortcuts< KSpace >::defaultParameters(), DGtal::Shortcuts< KSpace >::getKSpace(), DGtal::Shortcuts< KSpace >::getSurfelRange(), K, DGtal::Shortcuts< KSpace >::makeBinaryImage(), DGtal::Shortcuts< KSpace >::makeDigitalSurface(), MultiScaleAnalyzer< KSpace, N >::multiscale_run(), Analyzer< KSpace, N >::run(), DGtal::Shortcuts< KSpace >::saveOBJ(), DGtal::PolyscopeViewer< Space, KSpace >::show(), surface, and DGtal::trace.