41 #include "DGtal/base/Common.h"
42 #include "DGtal/io/viewers/Viewer3D.h"
43 #include "DGtal/io/DrawWithDisplay3DModifier.h"
44 #include "DGtal/io/Color.h"
45 #include "DGtal/shapes/Shapes.h"
46 #include "DGtal/helpers/StdDefs.h"
47 #include "DGtal/helpers/Shortcuts.h"
48 #include "DGtal/images/ImageContainerBySTLVector.h"
49 #include "DGtal/geometry/volumes/NeighborhoodConvexityAnalyzer.h"
54 using namespace DGtal;
62 int main(
int argc,
char** argv )
64 trace.
info() <<
"Usage: " << argv[ 0 ] <<
" <thickness> <convexity> <input.vol> <m> <M>" << std::endl;
65 trace.
info() <<
" - convexity in {0,1}: 0=0-convexity, 1=full-convexity"<< std::endl;
67 int thickness = argc > 1 ? atoi( argv[ 1 ] ) : 2;
68 bool full_cvx = argc > 2 ? atoi( argv[ 2 ] ) == 1 :
false;
69 std::string fn= argc > 3 ? argv[ 3 ] :
"";
70 int m = argc > 4 ? atoi( argv[ 4 ] ) : 0;
71 int M = argc > 5 ? atoi( argv[ 5 ] ) : 255;
72 trace.
beginBlock (
"Example of 3D shape thinning with full convexity properties" );
74 QApplication application(argc,argv);
76 viewer.setWindowTitle(
"fullConvexityThinning3D");
79 auto params = SH3::defaultParameters();
82 trace.
info() <<
"Building set or importing vol ... ";
84 Point p1( -50, -50, -50 );
85 Point p2( 50, 50, 50 );
88 std::set< Point > shape_set;
92 K.
init( p1, p2,
true );
96 if ( ((p - c ).norm() <= 22+thickness ) && ((p - c ).norm() >= 20-thickness)
97 && ( ((p[0] <= thickness)&& (p[0] >= -thickness))
98 || ((p[1] <= thickness)&& (p[1] >= -thickness))))
100 shape_set.insert( p );
101 bimage->setValue( p,
true );
104 bimage->setValue( p,
false );
109 params(
"thresholdMin", m );
110 params(
"thresholdMax", M );
111 bimage = SH3::makeBinaryImage( fn, params );
112 K = SH3::getKSpace( bimage );
117 if ( (*bimage)( p ) ) shape_set.insert( p );
119 std::set< Point > origin_set( shape_set );
123 params(
"surfaceComponents" ,
"All" );
124 auto surface = SH3::makeDigitalSurface( bimage,
K, params );
125 bool ok = SH3::saveOBJ(
surface,
"source.obj" );
130 NCA nca( p1, p2, 10000 );
132 std::set< Point >::iterator it, itE;
133 std::set< Point > to_process( shape_set );
136 std::set< Point > next_to_process;
138 trace.
info() <<
"Pass #S=" << shape_set.size()
139 <<
" #Q=" << to_process.size() << std::endl;
140 for (
auto it = to_process.begin(), itE = to_process.end(); it != itE; ++it )
143 if ( !
image( p ) )
continue;
149 std::vector< Point > neighbors;
151 for (
auto q : neighbors ) next_to_process.insert( q );
152 shape_set.erase( p );
153 image.setValue( p,
false );
157 trace.
info() <<
" => nb_removed=" << nb_simple<< std::endl;
158 if ( nb_simple != 0 )
159 std::swap( to_process, next_to_process );
161 while ( nb_simple != 0 );
165 params(
"surfaceComponents" ,
"All" );
166 auto surface = SH3::makeDigitalSurface( bimage,
K, params );
167 SH3::saveOBJ(
surface,
"geom-thinned.obj" );
173 for (
auto p : origin_set ) origin.
insert( p );
174 for (
auto p : shape_set ) output.
insert( p );
183 viewer<< Viewer3D<>::updateDisplay;
187 return application.exec();
Structure representing an RGB triple with alpha component.
Aim: Smart pointer based on reference counts.
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
std::string className() const
void insert(const Point &p)
Iterator for HyperRectDomain.
const ConstIterator & end() const
const ConstIterator & begin() const
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
const Point & lowerBound() const
Return the lower bound for digital points in this space.
const Point & upperBound() const
Return the upper bound for digital points in this space.
Aim: A class that models a neighborhood and that provides services to analyse the convexity properti...
bool is0ConvexCollapsible()
void setCenter(Point c, const PointPredicate &X)
bool isFullyConvexCollapsible()
void getLocalX(std::vector< Point > &localX, bool with_center) const
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
void beginBlock(const std::string &keyword="")
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
CountedPtr< SH3::DigitalSurface > surface
int main(int argc, char **argv)
NeighborhoodConvexityAnalyzer< KSpace, 1 > NCA
DGtal is the top-level namespace which contains all DGtal functions and types.
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
HyperRectDomain< Space > Domain