DGtal  1.4.beta
volScanBoundary.cpp
Go to the documentation of this file.
1 
38 #include <iostream>
39 #include <queue>
40 #include "DGtal/helpers/StdDefs.h"
41 #include "DGtal/io/readers/VolReader.h"
42 #include "DGtal/io/DrawWithDisplay3DModifier.h"
43 #include "DGtal/io/Color.h"
44 #include "DGtal/images/ImageSelector.h"
45 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
46 #include "DGtal/shapes/Shapes.h"
47 #include "DGtal/topology/helpers/Surfaces.h"
48 #include "DGtal/io/viewers/Viewer3D.h"
50 
52 
53 using namespace std;
54 using namespace DGtal;
55 using namespace Z3i;
56 
58 
59 void usage( int, char** argv )
60 {
61  std::cerr << "Usage: " << argv[ 0 ] << " <fileName.vol> <minT> <maxT>" << std::endl;
62  std::cerr << "\t - displays the boundary of the shape stored in vol file <fileName.vol>." << std::endl;
63  std::cerr << "\t - voxel v belongs to the shape iff its value I(v) follows minT <= I(v) <= maxT." << std::endl;
64 }
65 
66 int main( int argc, char** argv )
67 {
68  if ( argc < 4 )
69  {
70  usage( argc, argv );
71  return 1;
72  }
73  std::string inputFilename = argv[ 1 ];
74  unsigned int minThreshold = atoi( argv[ 2 ] );
75  unsigned int maxThreshold = atoi( argv[ 3 ] );
76 
78  trace.beginBlock( "Reading vol file into an image." );
80  Image image = VolReader<Image>::importVol(inputFilename);
81  DigitalSet set3d (image.domain());
83  minThreshold, maxThreshold);
84  trace.endBlock();
86 
87 
89  trace.beginBlock( "Construct the Khalimsky space from the image domain." );
90  KSpace ks;
91  bool space_ok = ks.init( image.domain().lowerBound(),
92  image.domain().upperBound(), true );
93  if (!space_ok)
94  {
95  trace.error() << "Error in the Khamisky space construction."<<std::endl;
96  return 2;
97  }
98  trace.endBlock();
100 
102  trace.beginBlock( "Extracting boundary by scanning the space. " );
103  KSpace::SCellSet boundary;
104  Surfaces<KSpace>::sMakeBoundary( boundary, ks, set3d,
105  image.domain().lowerBound(),
106  image.domain().upperBound() );
107  trace.endBlock();
109 
111  trace.beginBlock( "Displaying surface in Viewer3D." );
112  QApplication application(argc,argv);
113  Viewer3D<> viewer( ks );
114  viewer.show();
115  KSpace::SCell dummy_scell;
116  viewer << SetMode3D( dummy_scell.className(), "Basic" );
117  viewer << CustomColors3D(Color(250, 0, 0 ), Color( 128, 128, 128 ) );
118  unsigned long nbSurfels = 0;
119  for ( KSpace::SCellSet::const_iterator it = boundary.begin(),
120  it_end = boundary.end(); it != it_end; ++it, ++nbSurfels )
121  viewer << *it;
122  viewer << Viewer3D<>::updateDisplay;
123  trace.info() << "nb surfels = " << nbSurfels << std::endl;
124  trace.endBlock();
125  return application.exec();
127 }
128 
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
std::set< SCell > SCellSet
Preferred type for defining a set of SCell(s).
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:79
std::ostream & error()
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:64
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
std::string className() const
Return the style name used for drawing this object.
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:90
ImageContainerBySTLVector< Domain, Value > Image
void usage(int, char **argv)
int main(int argc, char **argv)