DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
volScanBoundary.cpp
1 
14 
15 
16 #include <iostream>
17 #include <queue>
18 #include <QtGui/qapplication.h>
19 #include "DGtal/kernel/sets/SetPredicate.h"
20 #include "DGtal/io/readers/VolReader.h"
21 #include "DGtal/io/viewers/Viewer3D.h"
22 #include "DGtal/io/DrawWithDisplay3DModifier.h"
23 #include "DGtal/io/Color.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/helpers/Surfaces.h"
30 
32 
33 using namespace std;
34 using namespace DGtal;
35 using namespace Z3i;
36 
38 
39 void usage( int, char** argv )
40 {
41  std::cerr << "Usage: " << argv[ 0 ] << " <fileName.vol> <minT> <maxT>" << std::endl;
42  std::cerr << "\t - displays the boundary of the shape stored in vol file <fileName.vol>." << std::endl;
43  std::cerr << "\t - voxel v belongs to the shape iff its value I(v) follows minT <= I(v) <= maxT." << std::endl;
44 }
45 
46 int main( int argc, char** argv )
47 {
48  if ( argc < 4 )
49  {
50  usage( argc, argv );
51  return 1;
52  }
53  std::string inputFilename = argv[ 1 ];
54  unsigned int minThreshold = atoi( argv[ 2 ] );
55  unsigned int maxThreshold = atoi( argv[ 3 ] );
56 
58  trace.beginBlock( "Reading vol file into an image." );
60  Image image = VolReader<Image>::importVol(inputFilename);
61  DigitalSet set3d (image.domain());
62  SetPredicate<DigitalSet> set3dPredicate( set3d );
63  SetFromImage<DigitalSet>::append<Image>(set3d, image,
64  minThreshold, maxThreshold);
65  trace.endBlock();
67 
68 
70  trace.beginBlock( "Construct the Khalimsky space from the image domain." );
71  KSpace ks;
72  bool space_ok = ks.init( image.domain().lowerBound(),
73  image.domain().upperBound(), true );
74  if (!space_ok)
75  {
76  trace.error() << "Error in the Khamisky space construction."<<std::endl;
77  return 2;
78  }
79  trace.endBlock();
81 
83  trace.beginBlock( "Extracting boundary by scanning the space. " );
84  KSpace::SCellSet boundary;
85  Surfaces<KSpace>::sMakeBoundary( boundary, ks, set3dPredicate,
86  image.domain().lowerBound(),
87  image.domain().upperBound() );
88  trace.endBlock();
90 
92  trace.beginBlock( "Displaying surface in Viewer3D." );
93  QApplication application(argc,argv);
94  Viewer3D viewer;
95  viewer.show();
96  viewer << CustomColors3D(Color(250, 0, 0 ), Color( 128, 128, 128 ) );
97  unsigned long nbSurfels = 0;
98  for ( KSpace::SCellSet::const_iterator it = boundary.begin(),
99  it_end = boundary.end(); it != it_end; ++it, ++nbSurfels )
100  viewer << *it;
101  viewer << Viewer3D::updateDisplay;
102  trace.info() << "nb surfels = " << nbSurfels << std::endl;
103  trace.endBlock();
104  return application.exec();
106 }
107