DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
volTrackBoundary.cpp
1 
14 
15 
16 #include <iostream>
17 #include <queue>
18 #include <QImageReader>
19 #include <QtGui/qapplication.h>
20 #include "DGtal/kernel/sets/SetPredicate.h"
21 #include "DGtal/io/readers/VolReader.h"
22 #include "DGtal/io/viewers/Viewer3D.h"
23 #include "DGtal/io/DrawWithDisplay3DModifier.h"
24 #include "DGtal/io/Color.h"
25 #include "DGtal/images/ImageSelector.h"
26 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
27 #include "DGtal/shapes/Shapes.h"
28 #include "DGtal/helpers/StdDefs.h"
29 #include "DGtal/topology/helpers/Surfaces.h"
31 
33 
34 using namespace std;
35 using namespace DGtal;
36 using namespace Z3i;
37 
39 
40 void usage( int /*argc*/, char** argv )
41 {
42  std::cerr << "Usage: " << argv[ 0 ] << " <fileName.vol> <minT> <maxT>" << std::endl;
43  std::cerr << "\t - displays the boundary of the shape stored in vol file <fileName.vol>." << std::endl;
44  std::cerr << "\t - voxel v belongs to the shape iff its value I(v) follows minT <= I(v) <= maxT." << std::endl;
45 }
46 
47 int main( int argc, char** argv )
48 {
49  if ( argc < 4 )
50  {
51  usage( argc, argv );
52  return 1;
53  }
54  std::string inputFilename = argv[ 1 ];
55  unsigned int minThreshold = atoi( argv[ 2 ] );
56  unsigned int maxThreshold = atoi( argv[ 3 ] );
57 
59  trace.beginBlock( "Reading vol file into an image." );
61  Image image = VolReader<Image>::importVol(inputFilename);
62  DigitalSet set3d (image.domain());
63  SetPredicate<DigitalSet> set3dPredicate( set3d );
64  SetFromImage<DigitalSet>::append<Image>(set3d, image,
65  minThreshold, maxThreshold);
66  trace.endBlock();
68 
69 
71  trace.beginBlock( "Construct the Khalimsky space from the image domain." );
72  KSpace ks;
73  bool space_ok = ks.init( image.domain().lowerBound(),
74  image.domain().upperBound(), true );
75  if (!space_ok)
76  {
77  trace.error() << "Error in the Khamisky space construction."<<std::endl;
78  return 2;
79  }
80  trace.endBlock();
82 
84  typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
85  MySurfelAdjacency surfAdj( true ); // interior in all directions.
87 
89  trace.beginBlock( "Extracting boundary by tracking from an initial bel." );
90  KSpace::SCellSet boundary;
91  SCell bel = Surfaces<KSpace>::findABel( ks, set3dPredicate, 100000 );
92  Surfaces<KSpace>::trackBoundary( boundary, ks,
93  surfAdj,
94  set3dPredicate, bel );
95  trace.endBlock();
97 
99  trace.beginBlock( "Displaying surface in Viewer3D." );
100  QApplication application(argc,argv);
101  Viewer3D viewer;
102  viewer.show();
103  viewer << CustomColors3D(Color(250, 0, 0 ), Color( 128, 128, 128 ) );
104  unsigned long nbSurfels = 0;
105  for ( KSpace::SCellSet::const_iterator it = boundary.begin(),
106  it_end = boundary.end(); it != it_end; ++it, ++nbSurfels )
107  viewer << *it;
108  viewer << Viewer3D::updateDisplay;
109  trace.info() << "nb surfels = " << nbSurfels << std::endl;
110  trace.endBlock();
111  return application.exec();
113 }
114