DGtal  1.5.beta
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/LpMetric.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.

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;
131  typedef LpMetric<Space> Distance;
132  using DistanceToPoint = std::function<double(const Space::RealPoint &)>;
135  MyDistanceVisitor;
136  typedef MyDistanceVisitor::Node MyNode;
137  typedef MyDistanceVisitor::Scalar MySize;
138 
139  SCellEmbedder embedder( ks );
140  Distance distance(2.0);
141  DistanceToPoint distanceToPoint = std::bind( distance, embedder( bel ), std::placeholders::_1 );
142  VertexFunctor vfunctor( embedder, distanceToPoint );
143  MyDistanceVisitor visitor( digSurf, vfunctor, bel );
144 
145  unsigned long nbSurfels = 0;
146  MyNode node;
147  while ( ! visitor.finished() )
148  {
149  node = visitor.current();
150  ++nbSurfels;
151  visitor.expand();
152  }
153  MySize maxDist = node.second;
154  trace.endBlock();
156 
158  trace.beginBlock( "Displaying surface in Viewer3D." );
159  QApplication application(argc,argv);
160  Viewer3D<> viewer( ks );
161  viewer.show();
162  HueShadeColorMap<MySize,1> hueShade( 0, maxDist );
163  MyDistanceVisitor visitor2( digSurf, vfunctor, bel );
164  viewer << SetMode3D( bel.className(), "Basic" );
165  viewer << CustomColors3D( Color::Black, Color::White )
166  << bel;
167  visitor2.expand();
168  std::vector< MyDistanceVisitor::Node > layer;
169  while ( ! visitor2.finished() )
170  {
171  MyNode n = visitor2.current();
172  Color c = hueShade( n.second );
173  viewer << CustomColors3D( Color::Red, c )
174  << n.first;
175  visitor2.expand();
176  }
177  viewer << Viewer3D<>::updateDisplay;
178  trace.info() << "nb surfels = " << nbSurfels << std::endl;
179  trace.endBlock();
180  return application.exec();
182 }
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
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...
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
Aim: This class is useful to perform an exploration of a graph given a starting point or set (called ...
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
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.
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Aim: implements l_p metrics.
Definition: LpMetric.h:75
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
Component Coordinate
Type for Point elements.
Definition: PointVector.h:617
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:79
std::ostream & error()
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
Aim: Define a new Functor from the composition of two other functors.
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
DigitalSetBoundary< KSpace, DigitalSet > MyDigitalSurfaceContainer
Trace trace
Definition: Common.h:153
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:64
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
std::string className() const
Return the style name used for drawing this object.
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:90
ImageContainerBySTLVector< Domain, Value > Image
PointVector< 3, double > RealPoint
void usage(int, char **argv)

References DGtal::DigitalSurface< TDigitalSurfaceContainer >::begin(), DGtal::Trace::beginBlock(), DGtal::SignedKhalimskyCell< dim, TInteger >::className(), DGtal::Trace::endBlock(), DGtal::Trace::error(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::Viewer3D< TSpace, TKSpace >::show(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::size(), DGtal::trace, and usage().

◆ usage()

void usage ( int  ,
char **  argv 
)

Definition at line 61 of file volDistanceTraversal.cpp.

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 }

Referenced by main().