41#include "DGtal/base/Common.h"
42#include "DGtal/io/viewers/PolyscopeViewer.h"
43#include "DGtal/io/Color.h"
44#include "DGtal/shapes/Shapes.h"
45#include "DGtal/helpers/StdDefs.h"
46#include "DGtal/helpers/Shortcuts.h"
47#include "DGtal/images/ImageContainerBySTLVector.h"
48#include "DGtal/geometry/volumes/NeighborhoodConvexityAnalyzer.h"
61int main(
int argc,
char** argv )
63 trace.info() <<
"Usage: " << argv[ 0 ] <<
" <thickness> <convexity> <input.vol> <m> <M>" << std::endl;
64 trace.info() <<
" - convexity in {0,1}: 0=0-convexity, 1=full-convexity"<< std::endl;
66 int thickness = argc > 1 ? atoi( argv[ 1 ] ) : 2;
67 bool full_cvx = argc > 2 ? atoi( argv[ 2 ] ) == 1 :
false;
68 std::string fn= argc > 3 ? argv[ 3 ] :
"";
69 int m = argc > 4 ? atoi( argv[ 4 ] ) : 0;
70 int M = argc > 5 ? atoi( argv[ 5 ] ) : 255;
71 trace.beginBlock (
"Example of 3D shape thinning with full convexity properties" );
78 trace.info() <<
"Building set or importing vol ... ";
80 Point p1( -50, -50, -50 );
81 Point p2( 50, 50, 50 );
84 std::set< Point > shape_set;
88 K.init( p1, p2,
true );
92 if ( ((p - c ).norm() <= 22+thickness ) && ((p - c ).norm() >= 20-thickness)
93 && ( ((p[0] <= thickness)&& (p[0] >= -thickness))
94 || ((p[1] <= thickness)&& (p[1] >= -thickness))))
96 shape_set.insert( p );
97 bimage->setValue( p,
true );
100 bimage->setValue( p,
false );
105 params(
"thresholdMin", m );
106 params(
"thresholdMax", M );
113 if ( (*bimage)( p ) ) shape_set.insert( p );
115 std::set< Point > origin_set( shape_set );
116 trace.info() <<
" [Done]" << std::endl;
119 params(
"surfaceComponents" ,
"All" );
124 trace.beginBlock (
"Thinning" );
126 NCA nca( p1, p2, 10000 );
128 std::set< Point >::iterator it, itE;
129 std::set< Point > to_process( shape_set );
132 std::set< Point > next_to_process;
134 trace.info() <<
"Pass #S=" << shape_set.size()
135 <<
" #Q=" << to_process.size() << std::endl;
136 for ( it = to_process.begin(), itE = to_process.end(); it != itE; ++it )
139 if ( !
image( p ) )
continue;
145 std::vector< Point > neighbors;
147 for (
auto q : neighbors ) next_to_process.insert( q );
148 shape_set.erase( p );
149 image.setValue( p,
false );
153 trace.info() <<
" => nb_removed=" << nb_simple<< std::endl;
154 if ( nb_simple != 0 )
155 std::swap( to_process, next_to_process );
157 while ( nb_simple != 0 );
161 params(
"surfaceComponents" ,
"All" );
169 for (
auto p : origin_set ) origin.
insert( p );
170 for (
auto p : shape_set ) output.
insert( p );
172 viewer <<
Color(25,25,255, 255);
175 viewer <<
Color(250, 0,0, 25);
61int main(
int argc,
char** argv ) {
…}
Structure representing an RGB triple with alpha component.
Aim: Smart pointer based on reference counts.
void insert(const Point &p)
bool is0ConvexCollapsible()
void setCenter(Point c, const PointPredicate &X)
bool isFullyConvexCollapsible()
void getLocalX(std::vector< Point > &localX, bool with_center) const
void show() override
Starts the event loop and display of elements.
ImageContainerBySTLVector< Domain, bool > BinaryImage
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters ¶ms=parametersDigitalSurface())
static Parameters defaultParameters()
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)
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
CountedPtr< SH3::DigitalSurface > surface
NeighborhoodConvexityAnalyzer< KSpace, 1 > NCA
Z3i this namespace gathers the standard of types for 3D imagery.
HyperRectDomain< Space > Domain
KhalimskySpaceND< 3, Integer > KSpace
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
DGtal is the top-level namespace which contains all DGtal functions and types.