62int 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" );
129 SH3::BinaryImage& image = *bimage;
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;
144 nca.setCenter( p, image );
146 ? nca.isFullyConvexCollapsible()
147 : nca.is0ConvexCollapsible() )
149 std::vector< Point > neighbors;
150 nca.getLocalX( neighbors,
false );
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();
Iterator for HyperRectDomain.
const ConstIterator & begin() const
const ConstIterator & end() const
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.