DGtal  0.9.3beta
volBreadthFirstTraversal.cpp
1 
14 #include <iostream>
17 #include <queue>
18 #include <QImageReader>
19 
20 #include "DGtal/io/readers/VolReader.h"
21 #include "DGtal/io/DrawWithDisplay3DModifier.h"
22 #include "DGtal/io/Color.h"
23 #include "DGtal/io/colormaps/HueShadeColorMap.h"
24 #include "DGtal/images/ImageSelector.h"
25 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
26 #include "DGtal/shapes/Shapes.h"
27 #include "DGtal/helpers/StdDefs.h"
28 #include "DGtal/topology/DigitalSurface.h"
29 #include "DGtal/topology/LightImplicitDigitalSurface.h"
30 #include "DGtal/io/viewers/Viewer3D.h"
31 
33 
35 
36 using namespace std;
37 using namespace DGtal;
38 using namespace Z3i;
39 
41 
42 void usage( int, char** argv )
43 {
44  std::cerr << "Usage: " << argv[ 0 ] << " <fileName.vol> <minT> <maxT>" << std::endl;
45  std::cerr << "\t - displays the boundary of the shape stored in vol file <fileName.vol>." << std::endl;
46  std::cerr << "\t - voxel v belongs to the shape iff its value I(v) follows minT <= I(v) <= maxT." << std::endl;
47 }
48 
49 int main( int argc, char** argv )
50 {
51  if ( argc < 4 )
52  {
53  usage( argc, argv );
54  return 1;
55  }
56  std::string inputFilename = argv[ 1 ];
57  unsigned int minThreshold = atoi( argv[ 2 ] );
58  unsigned int maxThreshold = atoi( argv[ 3 ] );
59 
61  trace.beginBlock( "Reading vol file into an image." );
63  Image image = VolReader<Image>::importVol(inputFilename);
64  DigitalSet set3d (image.domain());
65  SetFromImage<DigitalSet>::append<Image>(set3d, image,
66  minThreshold, maxThreshold);
67  trace.endBlock();
69 
70 
72  trace.beginBlock( "Construct the Khalimsky space from the image domain." );
73  KSpace ks;
74  bool space_ok = ks.init( image.domain().lowerBound(),
75  image.domain().upperBound(), true );
76  if (!space_ok)
77  {
78  trace.error() << "Error in the Khamisky space construction."<<std::endl;
79  return 2;
80  }
81  trace.endBlock();
83 
85  typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
86  MySurfelAdjacency surfAdj( true ); // interior in all directions.
88 
90  trace.beginBlock( "Set up digital surface." );
94  SCell bel = Surfaces<KSpace>::findABel( ks, set3d, 100000 );
95  MyDigitalSurfaceContainer* ptrSurfContainer =
96  new MyDigitalSurfaceContainer( ks, set3d, surfAdj, bel );
97  MyDigitalSurface digSurf( ptrSurfContainer ); // acquired
98  trace.endBlock();
100 
102  trace.beginBlock( "Extracting boundary by tracking from an initial bel." );
103  typedef BreadthFirstVisitor<MyDigitalSurface> MyBreadthFirstVisitor;
104  typedef MyBreadthFirstVisitor::Node MyNode;
105  typedef MyBreadthFirstVisitor::Size MySize;
106  MyBreadthFirstVisitor visitor( digSurf, bel );
107  unsigned long nbSurfels = 0;
108  MyNode node;
109  while ( ! visitor.finished() )
110  {
111  node = visitor.current();
112  ++nbSurfels;
113  visitor.expand();
114  }
115  MySize maxDist = node.second;
116  trace.endBlock();
118 
120  trace.beginBlock( "Displaying surface in Viewer3D." );
121  QApplication application(argc,argv);
122  Viewer3D<> viewer;
123  viewer.show();
124  HueShadeColorMap<MySize,1> hueShade( 0, maxDist );
125  MyBreadthFirstVisitor visitor2( digSurf, bel );
126  viewer << CustomColors3D( Color::Black, Color::White )
127  << ks.unsigns( bel );
128  visitor2.expand();
129  while ( ! visitor2.finished() )
130  {
131  node = visitor2.current();
132  Color c = hueShade( node.second );
133  viewer << CustomColors3D( Color::Red, c )
134  << ks.unsigns( node.first );
135  visitor2.expand();
136  }
137  viewer << Viewer3D<>::updateDisplay;
138  trace.info() << "nb surfels = " << nbSurfels << std::endl;
139  trace.endBlock();
140  return application.exec();
142 }
143 
void beginBlock(const std::string &keyword="")
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
Trace trace
Definition: Common.h:137
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
KhalimskySpaceND< 2, Integer > KSpace
Definition: StdDefs.h:77
STL namespace.
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: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of a given...
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:88
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:63
std::ostream & info()
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:66
const Domain & domain() const
Definition: Image.h:192
std::ostream & error()