DGtal 1.3.0
Loading...
Searching...
No Matches
Typedefs | Functions
fullConvexityAnalysis3D.cpp File Reference
#include <iostream>
#include <queue>
#include "DGtal/base/Common.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/io/DrawWithDisplay3DModifier.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"

Go to the source code of this file.

Typedefs

typedef Shortcuts< KSpaceSH3
 

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.

Typedef Documentation

◆ SH3

typedef Shortcuts< KSpace > SH3

Definition at line 88 of file fullConvexityAnalysis3D.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 241 of file fullConvexityAnalysis3D.cpp.

242{
243 if ( argc <= 2 )
244 {
245 trace.info() << "Usage: " << argv[ 0 ] << " <K> <input.vol> <m> <M>" << std::endl;
246 trace.info() << "\tAnalyze the shape with local full convexity" << std::endl;
247 trace.info() << "\t- 1 <= K <= 5: analysis at scale K" << std::endl;
248 trace.info() << "\t- K == 0: multiscale analysis (using scales 1-5)" << std::endl;
249 trace.info() << "\t- input.vol: choose your favorite shape" << std::endl;
250 trace.info() << "\t- m [==0], M [==255]: used to threshold input vol image" << std::endl;
251 return 1;
252 }
253 int N = atoi( argv[ 1 ] );
254 std::string fn= argv[ 2 ];
255 int m = argc > 3 ? atoi( argv[ 3 ] ) : 0;
256 int M = argc > 4 ? atoi( argv[ 4 ] ) : 255;
257
258 QApplication application(argc,argv);
259
260 auto params = SH3::defaultParameters();
261
262 // Domain creation from two bounding points.
263 trace.info() << "Building set or importing vol ... ";
264 KSpace K;
265 params( "thresholdMin", m );
266 params( "thresholdMax", M );
267 auto bimage = SH3::makeBinaryImage( fn, params );
268 K = SH3::getKSpace( bimage );
269 trace.info() << " [Done]" << std::endl;
270 // Compute surface
271 params( "surfaceComponents" , "All" );
272 auto surface = SH3::makeDigitalSurface( bimage, K, params );
273
274 // Compute interior boundary points
275 // They are less immediate interior points than surfels.
276 std::vector< Point > points;
277 std::map< SCell, int > surfel2idx;
278 std::map< Point, int > point2idx;
279 int idx = 0;
280 for ( auto s : (*surface) )
281 {
282 // get inside point on the border of the shape.
283 Dimension k = K.sOrthDir( s );
284 auto voxel = K.sIncident( s, k, K.sDirect( s, k ) );
285 Point p = K.sCoords( voxel );
286 auto it = point2idx.find( p );
287 if ( it == point2idx.end() )
288 {
289 points.push_back( p );
290 surfel2idx[ s ] = idx;
291 point2idx [ p ] = idx++;
292 }
293 else
294 surfel2idx[ s ] = it->second;
295 }
296 trace.info() << "Shape has " << points.size() << " interior boundary points"
297 << std::endl;
298 if ( N != 0 )
299 {
300 std::vector< int > result;
301 trace.beginBlock ( "Single scale analysis" );
302 if ( N == 1 ) result = Analyzer< KSpace, 1 >::run( K, points, bimage );
303 if ( N == 2 ) result = Analyzer< KSpace, 2 >::run( K, points, bimage );
304 if ( N == 3 ) result = Analyzer< KSpace, 3 >::run( K, points, bimage );
305 if ( N == 4 ) result = Analyzer< KSpace, 4 >::run( K, points, bimage );
306 if ( N == 5 ) result = Analyzer< KSpace, 5 >::run( K, points, bimage );
307 trace.endBlock();
308 SCell dummy;
309 Color colors[ 4 ] =
310 { Color( 255, 0, 0, 255 ), Color( 0, 255, 0, 255 ),
311 Color( 0, 0, 255, 255 ), Color( 255, 255, 255, 255 ) };
312 auto surfels = SH3::getSurfelRange( surface, params );
313 SH3::Colors all_colors( surfels.size() );
314 for ( int i = 0; i < surfels.size(); i++ )
315 {
316 const auto j = surfel2idx[ surfels[ i ] ];
317 all_colors[ i ] = colors[ result[ j ] ];
318 }
319 SH3::saveOBJ( surface, SH3::RealVectors(), all_colors, "geom-cvx.obj" );
320 Viewer3D<> viewer;
321 viewer.setWindowTitle("fullConvexityAnalysis3D");
322 viewer.show();
323 int i = 0;
324 viewer << SetMode3D( dummy.className(), "Basic" );
325 for ( auto s : (*surface) )
326 {
327 viewer << CustomColors3D( all_colors[ i ], all_colors[ i ] )
328 << s;
329 i++;
330 }
331 viewer<< Viewer3D<>::updateDisplay;
332 application.exec();
333 }
334 else
335 {
336 trace.beginBlock ( "Multiscale analysis" );
337 auto geometry =
338 MultiScaleAnalyzer< KSpace, 5 >::multiscale_run( K, points, bimage );
339 trace.endBlock();
340 Color colors_planar[ 6 ] =
341 { Color( 0, 255, 255, 255),
342 Color( 50, 255, 255, 255), Color( 100, 255, 255, 255),
343 Color( 150, 255, 255, 255), Color( 200, 255, 255, 255 ),
344 Color( 255, 255, 255, 255 ) };
345 Color color_atypical( 255, 0, 0, 255 );
346 Color colors_cvx[ 5 ] =
347 { Color( 0, 255, 0, 255 ), Color( 50, 255, 50, 255 ),
348 Color( 100, 255, 100, 255 ), Color( 150, 255, 150, 255 ),
349 Color( 200, 255, 200, 255 ) };
350 Color colors_ccv[ 5 ] =
351 { Color( 0, 0, 255, 255 ), Color( 50, 50, 255, 255 ),
352 Color( 100, 100, 255, 255 ), Color( 150, 150, 255, 255 ),
353 Color( 200, 200, 255, 255 ) };
354 auto surfels = SH3::getSurfelRange( surface, params );
355 SH3::Colors all_colors( surfels.size() );
356 for ( int i = 0; i < surfels.size(); i++ ) {
357 const auto j = surfel2idx[ surfels[ i ] ];
358 int m0 = std::min( geometry[ j ].first, geometry[ j ].second );
359 int m1 = std::max( geometry[ j ].first, geometry[ j ].second );
360 if ( m1 == 0 ) all_colors[ i ] = color_atypical;
361 else if ( m0 == m1 ) all_colors[ i ] = colors_planar[ 5 ];
362 else if ( geometry[ j ].first > geometry[ j ].second )
363 all_colors[ i ] = colors_cvx[ 5 - abs( m0 - m1 ) ];
364 else
365 all_colors[ i ] = colors_ccv[ 5 - abs( m0 - m1 ) ];
366 }
367 SH3::saveOBJ( surface, SH3::RealVectors(), all_colors, "geom-scale-cvx.obj" );
368 SCell dummy;
369 int i = 0;
370 Viewer3D<> viewer;
371 viewer.setWindowTitle("fullConvexityAnalysis3D");
372 viewer.show();
373 viewer << SetMode3D( dummy.className(), "Basic" );
374 for ( auto s : (*surface) )
375 {
376 viewer << CustomColors3D( all_colors[ i ], all_colors[ i ] )
377 << s;
378 i++;
379 }
380 viewer<< Viewer3D<>::updateDisplay;
381 application.exec();
382 }
383 return 0;
384}
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
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].
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
Definition: Shortcuts.h:332
std::vector< Color > Colors
Definition: Shortcuts.h:192
static SurfelRange getSurfelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1547
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1209
std::vector< RealVector > RealVectors
Definition: Shortcuts.h:179
static Parameters defaultParameters()
Definition: Shortcuts.h:203
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:1739
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
Definition: Shortcuts.h:561
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
DGtal::uint32_t Dimension
Definition: Common.h:137
Trace trace
Definition: Common.h:154
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
std::string className() const
Return the style name used for drawing this object.
KSpace K

References DGtal::Trace::beginBlock(), DGtal::SignedKhalimskyCell< dim, TInteger >::className(), DGtal::Shortcuts< TKSpace >::defaultParameters(), DGtal::Trace::endBlock(), DGtal::Shortcuts< TKSpace >::getKSpace(), DGtal::Shortcuts< TKSpace >::getSurfelRange(), DGtal::Trace::info(), K, DGtal::Shortcuts< TKSpace >::makeBinaryImage(), DGtal::Shortcuts< TKSpace >::makeDigitalSurface(), DGtal::Shortcuts< TKSpace >::saveOBJ(), DGtal::KhalimskySpaceND< dim, TInteger >::sCoords(), DGtal::KhalimskySpaceND< dim, TInteger >::sDirect(), DGtal::Viewer3D< TSpace, TKSpace >::show(), DGtal::KhalimskySpaceND< dim, TInteger >::sIncident(), DGtal::KhalimskySpaceND< dim, TInteger >::sOrthDir(), and DGtal::trace.