DGtal  0.9.3
Functions
volDistanceTraversal.cpp File Reference
#include <iostream>
#include <queue>
#include <QImageReader>
#include "DGtal/base/BasicFunctors.h"
#include "DGtal/topology/CanonicSCellEmbedder.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/graph/DistanceBreadthFirstVisitor.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/topology/LightImplicitDigitalSurface.h"
#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/io/Color.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
Include dependency graph for volDistanceTraversal.cpp:

Go to the source code of this file.

Functions

void usage (int, char **argv)
 
int main (int argc, char **argv)
 

Detailed Description

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/02/06

An example file named volDistanceTraversal.

This file is part of the DGtal library.

Definition in file volDistanceTraversal.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

[volDistanceTraversal-readVol]

[volDistanceTraversal-readVol]

[volDistanceTraversal-KSpace]

[volDistanceTraversal-KSpace]

[volDistanceTraversal-SurfelAdjacency]

[volDistanceTraversal-SurfelAdjacency]

[volDistanceTraversal-SetUpDigitalSurface]

[volDistanceTraversal-SetUpDigitalSurface]

[volDistanceTraversal-ExtractingSurface]

[volDistanceTraversal-ExtractingSurface]

[volDistanceTraversal-DisplayingSurface]

[volDistanceTraversal-DisplayingSurface]

Definition at line 69 of file volDistanceTraversal.cpp.

References DGtal::DigitalSurface< TDigitalSurfaceContainer >::begin(), DGtal::Trace::beginBlock(), DGtal::SignedKhalimskyCell< dim, TInteger >::className(), DGtal::Image< TImageContainer >::domain(), DGtal::Trace::endBlock(), DGtal::Trace::error(), image(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::Viewer3D< Space, KSpace >::show(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::size(), DGtal::trace, and usage().

70 {
71  if ( argc < 4 )
72  {
73  usage( argc, argv );
74  return 1;
75  }
76  std::string inputFilename = argv[ 1 ];
77  unsigned int minThreshold = atoi( argv[ 2 ] );
78  unsigned int maxThreshold = atoi( argv[ 3 ] );
79  unsigned int idxP = (argc <= 4) ? 0 : atoi( argv[ 4 ] );
80 
82  trace.beginBlock( "Reading vol file into an image." );
84  Image image = VolReader<Image>::importVol(inputFilename);
85  DigitalSet set3d (image.domain());
87  minThreshold, maxThreshold);
88  trace.endBlock();
90 
91 
93  trace.beginBlock( "Construct the Khalimsky space from the image domain." );
94  KSpace ks;
95  bool space_ok = ks.init( image.domain().lowerBound(),
96  image.domain().upperBound(), true );
97  if (!space_ok)
98  {
99  trace.error() << "Error in the Khamisky space construction."<<std::endl;
100  return 2;
101  }
102  trace.endBlock();
104 
106  typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
107  MySurfelAdjacency surfAdj( true ); // interior in all directions.
109 
111  trace.beginBlock( "Set up digital surface." );
115  SCell bel = Surfaces<KSpace>::findABel( ks, set3d, 100000 );
116  MyDigitalSurfaceContainer* ptrSurfContainer =
117  new MyDigitalSurfaceContainer( ks, set3d, surfAdj, bel );
118  MyDigitalSurface digSurf( ptrSurfContainer ); // acquired
119  trace.endBlock();
120  // Find first bel.
121  MyDigitalSurface::ConstIterator it = digSurf.begin();
122  for ( idxP = idxP % digSurf.size(); idxP != 0; --idxP ) ++it;
123  bel = *it;
125 
127  trace.beginBlock( "Extracting boundary by distance tracking from an initial bel." );
128  typedef CanonicSCellEmbedder<KSpace> SCellEmbedder;
130  typedef RealPoint::Coordinate Scalar;
132 
133  typedef std::binder1st< Distance > DistanceToPoint;
136  MyDistanceVisitor;
137  typedef MyDistanceVisitor::Node MyNode;
138  typedef MyDistanceVisitor::Scalar MySize;
139 
140  SCellEmbedder embedder( ks );
141  Distance distance;
142  DistanceToPoint distanceToPoint = std::bind1st( distance, embedder( bel ) );
143  VertexFunctor vfunctor( embedder, distanceToPoint );
144  MyDistanceVisitor visitor( digSurf, vfunctor, bel );
145 
146  unsigned long nbSurfels = 0;
147  MyNode node;
148  while ( ! visitor.finished() )
149  {
150  node = visitor.current();
151  ++nbSurfels;
152  visitor.expand();
153  }
154  MySize maxDist = node.second;
155  trace.endBlock();
157 
159  trace.beginBlock( "Displaying surface in Viewer3D." );
160  QApplication application(argc,argv);
161  Viewer3D<> viewer( ks );
162  viewer.show();
163  HueShadeColorMap<MySize,1> hueShade( 0, maxDist );
164  MyDistanceVisitor visitor2( digSurf, vfunctor, bel );
165  viewer << SetMode3D( bel.className(), "Basic" );
166  viewer << CustomColors3D( Color::Black, Color::White )
167  << bel;
168  visitor2.expand();
169  std::vector< MyDistanceVisitor::Node > layer;
170  while ( ! visitor2.finished() )
171  {
172  MyNode n = visitor2.current();
173  Color c = hueShade( n.second );
174  viewer << CustomColors3D( Color::Red, c )
175  << n.first;
176  visitor2.expand();
177  }
178  viewer << Viewer3D<>::updateDisplay;
179  trace.info() << "nb surfels = " << nbSurfels << std::endl;
180  trace.endBlock();
181  return application.exec();
183 }
Aim: This class is useful to perform an exploration of a graph given a starting point or set (called ...
void usage(int, char **argv)
void beginBlock(const std::string &keyword="")
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Trace trace
Definition: Common.h:137
Component Coordinate
Type for Point elements.
Definition: PointVector.h:158
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
double endBlock()
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:141
Aim: implements separable l_p metrics with exact predicates.
Aim: Define a new Functor from the composition of two other functors.
std::string className() const
bool init(const Point &lower, const Point &upper, bool isClosed)
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:89
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:63
std::ostream & info()
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value...
ImageContainerBySTLVector< Domain, Value > Image
const Domain & domain() const
Definition: Image.h:192
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
DigitalSetBoundary< KSpace, DigitalSet > MyDigitalSurfaceContainer
std::ostream & error()
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex...
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
Image image(domain)
Modifier class in a Display3D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithDisplay3D.

◆ usage()

void usage ( int  ,
char **  argv 
)

Definition at line 61 of file volDistanceTraversal.cpp.

Referenced by main().

62 {
63  std::cerr << "Usage: " << argv[ 0 ] << " <fileName.vol> <minT> <maxT> <idxP>" << std::endl;
64  std::cerr << "\t - displays the Euclidean distance to the specified surfel on the boundary of the shape stored in vol file <fileName.vol>." << std::endl;
65  std::cerr << "\t - the shape is defined implicitly: voxel v belongs to the shape iff its value I(v) follows minT < I(v) <= maxT." << std::endl;
66  std::cerr << "\t - starts from the <idxP>-th surfel or first one if invalid." << std::endl;
67 }