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" );
75 auto params = SH3::defaultParameters();
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 );
107 bimage = SH3::makeBinaryImage( fn, params );
108 K = SH3::getKSpace( bimage );
113 if ( (*bimage)( p ) ) shape_set.insert( p );
115 std::set< Point > origin_set( shape_set );
119 params(
"surfaceComponents" ,
"All" );
120 auto surface = SH3::makeDigitalSurface( bimage,
K, params );
121 SH3::saveOBJ(
surface,
"source.obj" );
125 SH3::BinaryImage&
image = *bimage;
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;
140 nca.setCenter( p,
image );
142 ? nca.isFullyConvexCollapsible()
143 : nca.is0ConvexCollapsible() )
145 std::vector< Point > neighbors;
146 nca.getLocalX( neighbors,
false );
147 for (
auto q : neighbors ) next_to_process.insert( q );
148 shape_set.erase( p );
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" );
162 auto surface = SH3::makeDigitalSurface( bimage,
K, params );
163 SH3::saveOBJ(
surface,
"geom-thinned.obj" );
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);
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.