158{
159 string inputFilename = argc > 1 ? argv[ 1 ] : examplesPath+"/samples/Al.100.vol";
160 int threshold = argc > 2 ? atoi( argv[ 2 ] ) : 0;
161 int widthNum = argc > 3 ? atoi( argv[ 3 ] ) : 2;
162 int widthDen = argc > 4 ? atoi( argv[ 4 ] ) : 1;
163
169 DigitalObject digitalObject(
image, threshold );
172
174 trace.
beginBlock(
"Construct the Khalimsky space from the image domain." );
177 if (!space_ok)
178 {
179 trace.
error() <<
"Error in the Khamisky space construction."<<endl;
180 return 2;
181 }
184
187 MySurfelAdjacency surfAdj( false );
189
197 MyContainer container( ks, digitalObject, surfAdj, start_surfel );
199 trace.
info() <<
"Digital surface has " << digSurf.size() <<
" surfels."
200 << endl;
203
205
206 trace.
beginBlock(
"Decomposition first pass. Computes all planes so as to sort vertices by the plane size." );
209 map<Surfel,unsigned int> v2size;
210 for (
ConstIterator it = digSurf.begin(), itE= digSurf.end(); it != itE; ++it )
211 v2size[ *it ] = 0;
212 int j = 0;
213 int nb = digSurf.
size();
215 vector<Point> layer;
216 vector<Surfel> layer_surfel;
217 for (
ConstIterator it = digSurf.begin(), itE= digSurf.end(); it != itE; ++it )
218 {
221 planeComputer.
init( widthNum, widthDen );
222
224 layer.clear();
225 layer_surfel.clear();
226 Visitor::Size currentSize = visitor.current().second;
227 while ( ! visitor.finished() )
228 {
229 Visitor::Node node = visitor.current();
230 v = node.first;
233 if ( node.second != currentSize )
234 {
235 bool isExtended = planeComputer.
extend( layer.begin(), layer.end() );
236 if ( isExtended )
237 {
238 for ( vector<Surfel>::const_iterator it_layer = layer_surfel.begin(),
239 it_layer_end = layer_surfel.end(); it_layer != it_layer_end; ++it_layer )
240 {
241 ++v2size[ *it_layer ];
242 }
243 layer_surfel.clear();
244 layer.clear();
245 currentSize = node.second;
246 }
247 else
248 break;
249 }
250 layer_surfel.push_back( v );
251 layer.push_back( p );
252 visitor.expand();
253 }
254 }
255
257 priority_queue<SurfelWeight> Q;
258 for (
ConstIterator it = digSurf.begin(), itE= digSurf.end(); it != itE; ++it )
259 Q.push( SurfelWeight( *it, v2size[ *it ] ) );
262
264
265 trace.
beginBlock(
"Decomposition second pass. Visits vertices from the one with biggest plane to the one with smallest plane." );
267 set<Surfel> processedVertices;
268 vector<RoundPlane*> roundPlanes;
269 map<Surfel,RoundPlane*> v2plane;
270 j = 0;
271 while ( ! Q.empty() )
272 {
275 Q.pop();
276 if ( processedVertices.find( v ) != processedVertices.end() )
277 continue;
278
279 RoundPlane* ptrRoundPlane = new RoundPlane;
280 roundPlanes.push_back( ptrRoundPlane );
281 v2plane[ v ] = ptrRoundPlane;
282 ptrRoundPlane->first.init( widthNum, widthDen );
284
286 layer.clear();
287 layer_surfel.clear();
288 Visitor::Size currentSize = visitor.current().second;
289 while ( ! visitor.finished() )
290 {
291 Visitor::Node node = visitor.current();
292 v = node.first;
295 if ( node.second != currentSize )
296 {
297 bool isExtended = ptrRoundPlane->first.extend( layer.begin(), layer.end() );
298 if ( isExtended )
299 {
300 for ( vector<Surfel>::const_iterator it_layer = layer_surfel.begin(),
301 it_layer_end = layer_surfel.end(); it_layer != it_layer_end; ++it_layer )
302 {
304 processedVertices.insert( s );
305 if ( v2plane.find( s ) == v2plane.end() )
306 v2plane[ s ] = ptrRoundPlane;
307 }
308 layer.clear();
309 layer_surfel.clear();
310 currentSize = node.second;
311 }
312 else break;
313 }
314 layer_surfel.push_back( v );
315 layer.push_back( p );
316 if ( processedVertices.find( v ) != processedVertices.end() )
317
318 visitor.ignore();
319 else
320 visitor.expand();
321 }
322 if ( visitor.finished() )
323 {
324 for ( vector<Surfel>::const_iterator it_layer = layer_surfel.begin(),
325 it_layer_end = layer_surfel.end(); it_layer != it_layer_end; ++it_layer )
326 {
328 processedVertices.insert( s );
329 if ( v2plane.find( s ) == v2plane.end() )
330 v2plane[ s ] = ptrRoundPlane;
331 }
332 }
333
334 ptrRoundPlane->second =
Color( rand() % 192 + 64, rand() % 192 + 64, rand() % 192 + 64, 255 );
335 }
338
340 for ( vector<RoundPlane*>::iterator
341 it = roundPlanes.begin(), itE = roundPlanes.end();
342 it != itE; ++it )
343 {
346 double mu =
LSF( normal, computer.
begin(), computer.
end() );
347 (*it)->third = make_pair( normal, mu );
348 }
350
352 map<Surfel, RealPoint> coordinates;
353 for ( map<Surfel,RoundPlane*>::const_iterator
354 it = v2plane.begin(), itE = v2plane.end();
355 it != itE; ++it )
356 {
358 RoundPlane* rplane = it->second;
360 RealPoint rp( (
double)p[ 0 ]/2.0, (
double)p[ 1 ]/2.0, (
double)p[ 2 ]/2.0 );
361 double mu = rplane->third.second;
363 double lambda = mu - rp.
dot( normal );
364 coordinates[ v ] = rp + lambda*normal;
365 }
366 typedef vector<Surfel> SurfelRange;
367 map<Surfel, RealPoint> new_coordinates;
368 for (
ConstIterator it = digSurf.begin(), itE= digSurf.end(); it != itE; ++it )
369 {
371 SurfelRange neighbors;
372 back_insert_iterator<SurfelRange> writeIt = back_inserter( neighbors );
373 digSurf.writeNeighbors( writeIt, *it );
375 for ( SurfelRange::const_iterator its = neighbors.begin(), itsE = neighbors.end();
376 its != itsE; ++its )
377 x += coordinates[ *its ];
378 new_coordinates[ s ] = x / neighbors.
size();
379 }
381
383 typedef unsigned int Number;
385 typedef MyMesh::MeshFace MeshFace;
388 map<Surfel, Number>
index;
389 Number nbv = 0;
390 MyMesh polyhedron( true );
391
392 for (
ConstIterator it = digSurf.begin(), itE= digSurf.end(); it != itE; ++it )
393 {
394 polyhedron.addVertex( new_coordinates[ *it ] );
395 index[ *it ] = nbv++;
396 }
397
398 FaceSet faces = digSurf.allClosedFaces();
399 for ( typename FaceSet::const_iterator itf = faces.begin(), itf_end = faces.end();
400 itf != itf_end; ++itf )
401 {
402 MeshFace mface( itf->nbVertices );
403 VertexRange vtcs = digSurf.verticesAroundFace( *itf );
404 int i = 0;
405 for ( typename VertexRange::const_iterator itv = vtcs.begin(), itv_end = vtcs.end();
406 itv != itv_end; ++itv )
407 {
408 mface[ i++ ] =
index[ *itv ];
409 }
410 polyhedron.addFace( mface,
Color( 255, 243, 150, 255 ) );
411 }
413
416 MyViewer3D viewer( ks );
417
418
419 viewer << polyhedron;
420 viewer.show();
422
424 for ( vector<RoundPlane*>::iterator
425 it = roundPlanes.begin(), itE = roundPlanes.end();
426 it != itE; ++it )
427 delete *it;
429 return true;
430 }
Aim: This class is useful to perform a breadth-first exploration of a graph given a starting point or...
void init(Dimension axis, InternalInteger diameter, InternalInteger widthNumerator=NumberTraits< InternalInteger >::ONE, InternalInteger widthDenominator=NumberTraits< InternalInteger >::ONE)
ConstIterator end() const
ConstIterator begin() const
bool extend(const Point &p)
Aim: A class that recognizes pieces of digital planes of given axis width. When the width is 1,...
Structure representing an RGB triple with alpha component.
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
std::vector< Vertex > VertexRange
The range of vertices is defined as a vector.
std::set< Face > FaceSet
The set of faces is defined as set.
Aim: implements association bewteen points lying in a digital domain and values.
const Domain & domain() const
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
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.
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.
const Point & sKCoords(const SCell &c) const
Return its Khalimsky coordinates.
SCell sDirectIncident(const SCell &p, Dimension k) const
Return the direct incident cell of [p] along [k] (the incident cell along [k])
Aim: This class is defined to represent a surface mesh through a set of vertices and faces....
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
void beginBlock(const std::string &keyword="")
void progressBar(const double currentValue, const double maximalValue)
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
COBANaivePlaneComputer< Z3, InternalInteger > NaivePlaneComputer
BreadthFirstVisitor< MyDigitalSurface > Visitor
double LSF(RealVector &N, ConstIterator itB, ConstIterator itE)
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
[polyhedralizer-typedefs]
unsigned int index(DGtal::uint32_t n, unsigned int b)
TriMesh::VertexRange VertexRange