DGtal  1.2.0
Typedefs | Functions
greedy-plane-segmentation-ex2.cpp File Reference
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include "DGtal/base/Common.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/Display3D.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/io/DrawWithDisplay3DModifier.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/topology/DigitalSetBoundary.h"
#include "DGtal/graph/BreadthFirstVisitor.h"
#include "DGtal/geometry/surfaces/COBANaivePlaneComputer.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.h"
Include dependency graph for greedy-plane-segmentation-ex2.cpp:

Go to the source code of this file.

Typedefs

typedef DGtal::int64_t InternalInteger
 
typedef COBANaivePlaneComputer< Z3, InternalIntegerNaivePlaneComputer
 
typedef DigitalSetBoundary< KSpace, DigitalSetMyDigitalSurfaceContainer
 
typedef DigitalSurface< MyDigitalSurfaceContainerMyDigitalSurface
 
typedef MyDigitalSurface::ConstIterator ConstIterator
 
typedef MyDigitalSurface::Vertex Vertex
 
typedef MyDigitalSurface::SurfelSet SurfelSet
 
typedef SurfelSet::iterator SurfelSetIterator
 
typedef BreadthFirstVisitor< MyDigitalSurfaceVisitor
 

Functions

bool operator< (const VertexSize &vs1, const VertexSize &vs2)
 
int main (int argc, char **argv)
 [greedy-plane-segmentation-ex2-typedefs] More...
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2012/10/01

An example file named greedy-plane-segmentation-ex2.

This file is part of the DGtal library.

Definition in file greedy-plane-segmentation-ex2.cpp.

Typedef Documentation

◆ ConstIterator

Examples
arithmetic/convergents-biginteger.cpp, arithmetic/convergents.cpp, dec/exampleDECSurface.cpp, doc-examples/kernelDomain.cpp, examples/tutorial-examples/polyhedralizer.cpp, geometry/curves/estimation/exampleCurvature.cpp, geometry/curves/estimation/exampleLMST2D.cpp, geometry/curves/estimation/exampleLMST3D.cpp, geometry/curves/estimation/exampleLMST3DBy2D.cpp, geometry/curves/exampleAlphaThickSegment.cpp, geometry/curves/exampleArithmeticalDSL.cpp, geometry/curves/exampleArithmeticalDSS.cpp, geometry/curves/exampleArithmeticalDSSComputer.cpp, geometry/curves/exampleGridCurve2d.cpp, geometry/curves/exampleGridCurve3d-2.cpp, geometry/curves/exampleNaive3DDSSComputer.cpp, geometry/curves/greedyAlphaThickDecomposition.cpp, geometry/surfaces/dvcm-2d-curvature.cpp, geometry/surfaces/greedy-plane-segmentation-ex2.cpp, geometry/surfaces/greedy-plane-segmentation.cpp, geometry/tools/examplePreimage.cpp, geometry/volumes/distance/distancetransform2D.cpp, geometry/volumes/distance/distancetransform3D.cpp, geometry/volumes/distance/exampleFMM2D.cpp, geometry/volumes/distance/voronoimap2D.cpp, graph/graphTraversal.cpp, graph/volDistanceTraversal.cpp, images/exampleImageFactoryFromHDF5.cpp, images/exampleRigidtransformation2d.cpp, images/exampleRigidtransformation3d.cpp, io/boards/dgtalBoard2D-4-colormaps.cpp, io/viewDualSurface.cpp, io/viewers/viewer3D-7-planes.cpp, io/viewers/viewer3D-7-stdplane.cpp, io/viewers/viewer3D-7bis-planes.cpp, io/viewers/viewer3D-7bis-stdplane.cpp, io/viewers/viewer3D-9-3Dimages.cpp, topology/3dBorderExtraction.cpp, topology/3dKSSurfaceExtraction.cpp, topology/ctopo-fillContours.cpp, topology/digitalSurfaceSlice.cpp, topology/frontierAndBoundary.cpp, topology/generateSimplicityTables2D.cpp, topology/homotopicThinning3D.cpp, tutorial-examples/FMMErosion.cpp, tutorial-examples/polyhedralizer.cpp, and tutorial-examples/volDTGranulo.cpp.

Definition at line 93 of file greedy-plane-segmentation-ex2.cpp.

◆ InternalInteger

◆ MyDigitalSurface

◆ MyDigitalSurfaceContainer

◆ NaivePlaneComputer

◆ SurfelSet

◆ SurfelSetIterator

typedef SurfelSet::iterator SurfelSetIterator

◆ Vertex

Definition at line 94 of file greedy-plane-segmentation-ex2.cpp.

◆ Visitor

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

[greedy-plane-segmentation-ex2-typedefs]

[greedy-plane-segmentation-ex2-parseCommandLine]

[greedy-plane-segmentation-ex2-parseCommandLine]

[greedy-plane-segmentation-ex2-loadVolume]

[greedy-plane-segmentation-ex2-loadVolume]

[greedy-plane-segmentation-ex2-makeSurface]

[greedy-plane-segmentation-ex2-makeSurface]

[greedy-plane-segmentation-ex2-segment]

[greedy-plane-segmentation-ex2-segment]

[greedy-plane-segmentation-ex2-visualization]

[greedy-plane-segmentation-ex2-visualization]

[greedy-plane-segmentation-ex2-freeMemory]

[greedy-plane-segmentation-ex2-freeMemory]

Definition at line 123 of file greedy-plane-segmentation-ex2.cpp.

124 {
126  trace.info() << "Segments the surface at given threshold within given volume into digital planes of rational width num/den." << std::endl;
127  // Setting default options: ----------------------------------------------
128  // input file used:
129  string inputFilename = examplesPath + "samples/Al.100.vol" ;
130  trace.info() << "input file used " << inputFilename << std::endl;
131  // parameter threshold
132  unsigned int threshold = 0;
133  trace.info() << "the value that defines the isosurface in the image (an integer between 0 and 255)= " << threshold<< std::endl;
134  // parameter widthNum
135  unsigned int widthNum = 1;
136  trace.info() << "the numerator of the rational width (a non-null integer) =" << widthNum<< std::endl;
137  // parameter widthDen
138  unsigned int widthDen = 1;
139  trace.info() << "the denominator of the rational width (a non-null integer)= " << widthDen<< std::endl;
141 
143  QApplication application(argc,argv);
145  Image image = VolReader<Image>::importVol(inputFilename);
146  DigitalSet set3d (image.domain());
147  SetFromImage<DigitalSet>::append<Image>(set3d, image, threshold,255);
149 
151  trace.beginBlock( "Set up digital surface." );
152  // We initializes the cellular grid space used for defining the
153  // digital surface.
154  KSpace ks;
155  bool ok = ks.init( set3d.domain().lowerBound(),
156  set3d.domain().upperBound(), true );
157  if ( ! ok ) std::cerr << "[KSpace.init] Failed." << std::endl;
158  SurfelAdjacency<KSpace::dimension> surfAdj( true ); // interior in all directions.
159  MyDigitalSurfaceContainer* ptrSurfContainer =
160  new MyDigitalSurfaceContainer( ks, set3d, surfAdj );
161  MyDigitalSurface digSurf( ptrSurfContainer ); // acquired
162  trace.endBlock();
164 
166  Point p;
167  Dimension axis;
168  unsigned int j = 0;
169  unsigned int nb = digSurf.size();
170 
171  // First pass to find biggest planes.
172  trace.beginBlock( "1) Segmentation first pass. Computes all planes so as to sort vertices by the plane size." );
173  std::map<Vertex,unsigned int> v2size;
174  NaivePlaneComputer planeComputer;
175  std::priority_queue<VertexSize> Q;
176  for ( ConstIterator it = digSurf.begin(), itE= digSurf.end(); it != itE; ++it )
177  {
178  if ( ( (++j) % 50 == 0 ) || ( j == nb ) ) trace.progressBar( j, nb );
179  Vertex v = *it;
180  axis = ks.sOrthDir( v );
181  planeComputer.init( axis, 500, widthNum, widthDen );
182  // The visitor takes care of all the breadth-first traversal.
183  Visitor visitor( digSurf, v );
184  while ( ! visitor.finished() )
185  {
186  Visitor::Node node = visitor.current();
187  v = node.first;
188  axis = ks.sOrthDir( v );
189  p = ks.sCoords( ks.sDirectIncident( v, axis ) );
190  bool isExtended = planeComputer.extend( p );
191  if ( isExtended )
192  // surfel is in plane.
193  visitor.expand();
194  else // surfel is not in plane and should not be used in the visit.
195  visitor.ignore();
196  }
197  Q.push( VertexSize( v, planeComputer.size() ) );
198  }
199  trace.endBlock();
200 
201  trace.beginBlock( "2) Segmentation second pass. Visits vertices from the one with biggest plane to the one with smallest plane." );
202  std::set<Vertex> processedVertices;
203  std::vector<SegmentedPlane*> segmentedPlanes;
204  std::map<Vertex,SegmentedPlane*> v2plane;
205  j = 0;
206  while ( ! Q.empty() )
207  {
208  if ( ( (++j) % 50 == 0 ) || ( j == nb ) ) trace.progressBar( j, nb );
209  Vertex v = Q.top().v;
210  Q.pop();
211  if ( processedVertices.find( v ) != processedVertices.end() ) // already in set
212  continue; // process to next vertex
213 
214  SegmentedPlane* ptrSegment = new SegmentedPlane;
215  segmentedPlanes.push_back( ptrSegment ); // to delete them afterwards.
216  axis = ks.sOrthDir( v );
217  ptrSegment->plane.init( axis, 500, widthNum, widthDen );
218  // The visitor takes care of all the breadth-first traversal.
219  Visitor visitor( digSurf, v );
220  while ( ! visitor.finished() )
221  {
222  Visitor::Node node = visitor.current();
223  v = node.first;
224  if ( processedVertices.find( v ) == processedVertices.end() )
225  { // Vertex is not in processedVertices
226  axis = ks.sOrthDir( v );
227  p = ks.sCoords( ks.sDirectIncident( v, axis ) );
228  bool isExtended = ptrSegment->plane.extend( p );
229  if ( isExtended )
230  { // surfel is in plane.
231  processedVertices.insert( v );
232  v2plane[ v ] = ptrSegment;
233  visitor.expand();
234  }
235  else // surfel is not in plane and should not be used in the visit.
236  visitor.ignore();
237  }
238  else // surfel is already in some plane.
239  visitor.ignore();
240  }
241  // Assign random color for each plane.
242  ptrSegment->color = Color( rand() % 256, rand() % 256, rand() % 256, 255 );
243  }
244  trace.endBlock();
246 
248  Viewer3D<> viewer( ks );
249  viewer.show();
250  for ( std::map<Vertex,SegmentedPlane*>::const_iterator
251  it = v2plane.begin(), itE = v2plane.end();
252  it != itE; ++it )
253  {
254  viewer << CustomColors3D( it->second->color, it->second->color );
255  viewer << ks.unsigns( it->first );
256  }
257  viewer << Viewer3D<>::updateDisplay;
259 
261  for ( std::vector<SegmentedPlane*>::iterator
262  it = segmentedPlanes.begin(), itE = segmentedPlanes.end();
263  it != itE; ++it )
264  delete *it;
265  segmentedPlanes.clear();
266  v2plane.clear();
268 
269  return application.exec();
270 }
Aim: This class is useful to perform a breadth-first exploration of a graph given a starting point or...
std::pair< Vertex, Data > Node
FIXME.
void init(Dimension axis, InternalInteger diameter, InternalInteger widthNumerator=NumberTraits< InternalInteger >::ONE, InternalInteger widthDenominator=NumberTraits< InternalInteger >::ONE)
bool extend(const Point &p)
Structure representing an RGB triple with alpha component.
Definition: Color.h:67
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of a given...
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
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...
Cell unsigns(const SCell &p) const
Creates an unsigned cell from a signed one.
Point sCoords(const SCell &c) const
Return its digital coordinates.
SCell sDirectIncident(const SCell &p, Dimension k) const
Return the direct incident cell of [p] along [k] (the incident cell along [k])
static Dimension size()
void beginBlock(const std::string &keyword="")
std::ostream & info()
void progressBar(const double currentValue, const double maximalValue)
double endBlock()
MyDigitalSurface::ConstIterator ConstIterator
DigitalSetBoundary< KSpace, DigitalSet > MyDigitalSurfaceContainer
DGtal::uint32_t Dimension
Definition: Common.h:137
Trace trace
Definition: Common.h:154
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:64
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:90
ImageContainerBySTLVector< Domain, Value > Image
TriMesh::Vertex Vertex

References DGtal::DigitalSurface< TDigitalSurfaceContainer >::begin(), DGtal::Trace::beginBlock(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::current(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::domain(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::end(), DGtal::Trace::endBlock(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::expand(), DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::extend(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::finished(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::ignore(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::init(), DGtal::Trace::progressBar(), DGtal::KhalimskySpaceND< dim, TInteger >::sCoords(), DGtal::KhalimskySpaceND< dim, TInteger >::sDirectIncident(), DGtal::Viewer3D< TSpace, TKSpace >::show(), DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::size(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::size(), DGtal::KhalimskySpaceND< dim, TInteger >::sOrthDir(), DGtal::trace, and DGtal::KhalimskySpaceND< dim, TInteger >::unsigns().

◆ operator<()

bool operator< ( const VertexSize &  vs1,
const VertexSize &  vs2 
)
inline