DGtal  1.5.beta
volBreadthFirstTraversal.cpp
Go to the documentation of this file.
1 
30 #include <iostream>
31 #include <queue>
32 #include <QImageReader>
33 
34 #include "DGtal/io/readers/VolReader.h"
35 #include "DGtal/io/DrawWithDisplay3DModifier.h"
36 #include "DGtal/io/Color.h"
37 #include "DGtal/io/colormaps/HueShadeColorMap.h"
38 #include "DGtal/images/ImageSelector.h"
39 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
40 #include "DGtal/shapes/Shapes.h"
41 #include "DGtal/helpers/StdDefs.h"
42 #include "DGtal/topology/DigitalSurface.h"
43 #include "DGtal/topology/LightImplicitDigitalSurface.h"
44 #include "DGtal/io/viewers/Viewer3D.h"
45 
47 
49 
50 using namespace std;
51 using namespace DGtal;
52 using namespace Z3i;
53 
55 
56 void usage( int, char** argv )
57 {
58  std::cerr << "Usage: " << argv[ 0 ] << " <fileName.vol> <minT> <maxT>" << std::endl;
59  std::cerr << "\t - displays the boundary of the shape stored in vol file <fileName.vol>." << std::endl;
60  std::cerr << "\t - voxel v belongs to the shape iff its value I(v) follows minT <= I(v) <= maxT." << std::endl;
61 }
62 
63 int main( int argc, char** argv )
64 {
65  if ( argc < 4 )
66  {
67  usage( argc, argv );
68  return 1;
69  }
70  std::string inputFilename = argv[ 1 ];
71  unsigned int minThreshold = atoi( argv[ 2 ] );
72  unsigned int maxThreshold = atoi( argv[ 3 ] );
73 
75  trace.beginBlock( "Reading vol file into an image." );
77  Image image = VolReader<Image>::importVol(inputFilename);
78  DigitalSet set3d (image.domain());
80  minThreshold, maxThreshold);
81  trace.endBlock();
83 
84 
86  trace.beginBlock( "Construct the Khalimsky space from the image domain." );
87  KSpace ks;
88  bool space_ok = ks.init( image.domain().lowerBound(),
89  image.domain().upperBound(), true );
90  if (!space_ok)
91  {
92  trace.error() << "Error in the Khamisky space construction."<<std::endl;
93  return 2;
94  }
95  trace.endBlock();
97 
99  typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
100  MySurfelAdjacency surfAdj( true ); // interior in all directions.
102 
104  trace.beginBlock( "Set up digital surface." );
108  SCell bel = Surfaces<KSpace>::findABel( ks, set3d, 100000 );
109  MyDigitalSurfaceContainer* ptrSurfContainer =
110  new MyDigitalSurfaceContainer( ks, set3d, surfAdj, bel );
111  MyDigitalSurface digSurf( ptrSurfContainer ); // acquired
112  trace.endBlock();
114 
116  trace.beginBlock( "Extracting boundary by tracking from an initial bel." );
117  typedef BreadthFirstVisitor<MyDigitalSurface> MyBreadthFirstVisitor;
118  typedef MyBreadthFirstVisitor::Node MyNode;
119  typedef MyBreadthFirstVisitor::Size MySize;
120  MyBreadthFirstVisitor visitor( digSurf, bel );
121  unsigned long nbSurfels = 0;
122  MyNode node;
123  while ( ! visitor.finished() )
124  {
125  node = visitor.current();
126  ++nbSurfels;
127  visitor.expand();
128  }
129  MySize maxDist = node.second;
130  trace.endBlock();
132 
134  trace.beginBlock( "Displaying surface in Viewer3D." );
135  QApplication application(argc,argv);
136  Viewer3D<> viewer;
137  viewer.show();
138  HueShadeColorMap<MySize,1> hueShade( 0, maxDist );
139  MyBreadthFirstVisitor visitor2( digSurf, bel );
140  viewer << CustomColors3D( Color::Black, Color::White )
141  << ks.unsigns( bel );
142  visitor2.expand();
143  while ( ! visitor2.finished() )
144  {
145  node = visitor2.current();
146  Color c = hueShade( node.second );
147  viewer << CustomColors3D( Color::Red, c )
148  << ks.unsigns( node.first );
149  visitor2.expand();
150  }
151  viewer << Viewer3D<>::updateDisplay;
152  trace.info() << "nb surfels = " << nbSurfels << std::endl;
153  trace.endBlock();
154  return application.exec();
156 }
157 
Aim: This class is useful to perform a breadth-first exploration of a graph given a starting point or...
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...
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.
Cell unsigns(const SCell &p) const
Creates an unsigned cell from a signed one.
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
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()
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
DigitalSetBoundary< KSpace, DigitalSet > MyDigitalSurfaceContainer
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:64
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:90
HalfEdgeDataStructure::Size Size
ImageContainerBySTLVector< Domain, Value > Image
void usage(int, char **argv)
int main(int argc, char **argv)