DGtal  0.9.3beta
volScanBoundary.cpp
1 
14 #include <iostream>
17 #include <queue>
18 #include "DGtal/helpers/StdDefs.h"
19 #include "DGtal/io/readers/VolReader.h"
20 #include "DGtal/io/DrawWithDisplay3DModifier.h"
21 #include "DGtal/io/Color.h"
22 #include "DGtal/images/ImageSelector.h"
23 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
24 #include "DGtal/shapes/Shapes.h"
25 #include "DGtal/topology/helpers/Surfaces.h"
26 #include "DGtal/io/viewers/Viewer3D.h"
28 
30 
31 using namespace std;
32 using namespace DGtal;
33 using namespace Z3i;
34 
36 
37 void usage( int, char** argv )
38 {
39  std::cerr << "Usage: " << argv[ 0 ] << " <fileName.vol> <minT> <maxT>" << std::endl;
40  std::cerr << "\t - displays the boundary of the shape stored in vol file <fileName.vol>." << std::endl;
41  std::cerr << "\t - voxel v belongs to the shape iff its value I(v) follows minT <= I(v) <= maxT." << std::endl;
42 }
43 
44 int main( int argc, char** argv )
45 {
46  if ( argc < 4 )
47  {
48  usage( argc, argv );
49  return 1;
50  }
51  std::string inputFilename = argv[ 1 ];
52  unsigned int minThreshold = atoi( argv[ 2 ] );
53  unsigned int maxThreshold = atoi( argv[ 3 ] );
54 
56  trace.beginBlock( "Reading vol file into an image." );
58  Image image = VolReader<Image>::importVol(inputFilename);
59  DigitalSet set3d (image.domain());
60  SetFromImage<DigitalSet>::append<Image>(set3d, image,
61  minThreshold, maxThreshold);
62  trace.endBlock();
64 
65 
67  trace.beginBlock( "Construct the Khalimsky space from the image domain." );
68  KSpace ks;
69  bool space_ok = ks.init( image.domain().lowerBound(),
70  image.domain().upperBound(), true );
71  if (!space_ok)
72  {
73  trace.error() << "Error in the Khamisky space construction."<<std::endl;
74  return 2;
75  }
76  trace.endBlock();
78 
80  trace.beginBlock( "Extracting boundary by scanning the space. " );
81  KSpace::SCellSet boundary;
82  Surfaces<KSpace>::sMakeBoundary( boundary, ks, set3d,
83  image.domain().lowerBound(),
84  image.domain().upperBound() );
85  trace.endBlock();
87 
89  trace.beginBlock( "Displaying surface in Viewer3D." );
90  QApplication application(argc,argv);
91  Viewer3D<> viewer( ks );
92  viewer.show();
93  KSpace::SCell dummy_scell;
94  viewer << SetMode3D( dummy_scell.className(), "Basic" );
95  viewer << CustomColors3D(Color(250, 0, 0 ), Color( 128, 128, 128 ) );
96  unsigned long nbSurfels = 0;
97  for ( KSpace::SCellSet::const_iterator it = boundary.begin(),
98  it_end = boundary.end(); it != it_end; ++it, ++nbSurfels )
99  viewer << *it;
100  viewer << Viewer3D<>::updateDisplay;
101  trace.info() << "nb surfels = " << nbSurfels << std::endl;
102  trace.endBlock();
103  return application.exec();
105 }
106 
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.