DGtal  0.9.3beta
volTrackBoundary.cpp
1 
14 #include <iostream>
17 #include <queue>
18 #include "DGtal/base/Common.h"
19 #include "DGtal/io/viewers/Viewer3D.h"
20 #include "DGtal/io/readers/VolReader.h"
21 #include "DGtal/io/DrawWithDisplay3DModifier.h"
22 #include "DGtal/io/Color.h"
23 #include "DGtal/images/ImageSelector.h"
24 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
25 #include "DGtal/shapes/Shapes.h"
26 #include "DGtal/helpers/StdDefs.h"
27 #include "DGtal/topology/helpers/Surfaces.h"
29 
31 
32 using namespace std;
33 using namespace DGtal;
34 using namespace Z3i;
35 
37 
38 void usage( int /*argc*/, char** argv )
39 {
40  std::cerr << "Usage: " << argv[ 0 ] << " <fileName.vol> <minT> <maxT>" << std::endl;
41  std::cerr << "\t - displays the boundary of the shape stored in vol file <fileName.vol>." << std::endl;
42  std::cerr << "\t - voxel v belongs to the shape iff its value I(v) follows minT <= I(v) <= maxT." << std::endl;
43 }
44 
45 int main( int argc, char** argv )
46 {
47  if ( argc < 4 )
48  {
49  usage( argc, argv );
50  return 1;
51  }
52  std::string inputFilename = argv[ 1 ];
53  unsigned int minThreshold = atoi( argv[ 2 ] );
54  unsigned int maxThreshold = atoi( argv[ 3 ] );
55 
57  trace.beginBlock( "Reading vol file into an image." );
59  Image image = VolReader<Image>::importVol(inputFilename);
60  DigitalSet set3d (image.domain());
61  SetFromImage<DigitalSet>::append<Image>(set3d, image,
62  minThreshold, maxThreshold);
63  trace.endBlock();
65 
66 
68  trace.beginBlock( "Construct the Khalimsky space from the image domain." );
69  KSpace ks;
70  bool space_ok = ks.init( image.domain().lowerBound(),
71  image.domain().upperBound(), true );
72  if (!space_ok)
73  {
74  trace.error() << "Error in the Khamisky space construction."<<std::endl;
75  return 2;
76  }
77  trace.endBlock();
79 
81  typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
82  MySurfelAdjacency surfAdj( true ); // interior in all directions.
84 
86  trace.beginBlock( "Extracting boundary by tracking from an initial bel." );
87  KSpace::SCellSet boundary;
88  SCell bel = Surfaces<KSpace>::findABel( ks, set3d, 100000 );
89  Surfaces<KSpace>::trackBoundary( boundary, ks,
90  surfAdj,
91  set3d, bel );
92  trace.endBlock();
94 
96  trace.beginBlock( "Displaying surface in Viewer3D." );
97  QApplication application(argc,argv);
98  Viewer3D<> viewer( ks );
99  viewer.show();
100  viewer << SetMode3D( bel.className(), "Basic" );
101  viewer << CustomColors3D(Color(250, 0, 0 ), Color( 128, 128, 128 ) );
102  unsigned long nbSurfels = 0;
103  for ( KSpace::SCellSet::const_iterator it = boundary.begin(),
104  it_end = boundary.end(); it != it_end; ++it, ++nbSurfels )
105  viewer << *it;
106  viewer << Viewer3D<>::updateDisplay;
107  trace.info() << "nb surfels = " << nbSurfels << std::endl;
108  trace.endBlock();
109  return application.exec();
111 }
112 
void beginBlock(const std::string &keyword="")
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
Trace trace
Definition: Common.h:137
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: 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()
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
const Domain & domain() const
Definition: Image.h:192
std::ostream & error()
Modifier class in a Display3D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithDisplay3D.