DGtal  0.9.2
exampleGridCurve3d-2.cpp
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 
34 #include "DGtal/helpers/StdDefs.h"
35 #include "DGtal/topology/KhalimskySpaceND.h"
36 #include "DGtal/topology/SurfelAdjacency.h"
37 #include "DGtal/topology/DigitalSurface.h"
38 #include "DGtal/topology/SetOfSurfels.h"
39 #include "DGtal/topology/DigitalSurface2DSlice.h"
40 #include "DGtal/topology/helpers/Surfaces.h"
41 
42 #include "DGtal/io/viewers/Viewer3D.h"
43 #include "DGtal/io/readers/VolReader.h"
44 #include "DGtal/io/DrawWithDisplay3DModifier.h"
45 #include "DGtal/images/ImageSelector.h"
46 #include "DGtal/images/ImageHelper.h"
47 #include "DGtal/kernel/sets/DigitalSetInserter.h"
48 #include "DGtal/io/Color.h"
49 
50 #include "DGtal/geometry/curves/GridCurve.h"
51 
52 #include "ConfigExamples.h"
53 
54 
55 
57 using namespace std;
58 using namespace DGtal;
59 using namespace Z3i;
61 
62 int main( int argc, char** argv )
63 {
64  trace.info() << "exampleGridCurve3d-2: the type of data to be displayed "
65  << "may be given as argument as follows: "
66  << argv[0] << " inner" << endl;
67  trace.info() << "Available types are: gridcurve (default), inner, outer, incident" << endl;
68 
69  string type = (argc > 1) ? string(argv[1]) : "gridcurve";
70  trace.info() << "Chosen type: " << type << endl;
71 
72  //vol reading and digital set construction
73  trace.beginBlock( "Reading vol file into an image." );
75  std::string inputFilename = examplesPath + "samples/cat10.vol";
76  Image image = VolReader<Image>::importVol(inputFilename);
77  DigitalSet set3d (image.domain());
79  trace.info() << set3d.size() << " voxels." << std::endl;
80  trace.endBlock();
81 
82  //Khalimsky space construction
83  trace.beginBlock( "Construct the Khalimsky space from the image domain." );
84  KSpace ks;
85  trace.endBlock();
86 
87  //digital surface construction
88  typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
89  MySurfelAdjacency surfAdj( true ); // interior in all directions.
90 
91  trace.beginBlock( "Extracting boundary by scanning the space. " );
92  typedef KSpace::Surfel Surfel;
93  typedef KSpace::SurfelSet SurfelSet;
94  typedef SetOfSurfels< KSpace, SurfelSet > MySetOfSurfels;
96  MySetOfSurfels theSetOfSurfels( ks, surfAdj );
97  Surfaces<KSpace>::sMakeBoundary( theSetOfSurfels.surfelSet(),
98  ks, set3d,
99  image.domain().lowerBound(),
100  image.domain().upperBound() );
101  MyDigitalSurface digSurf( theSetOfSurfels );
102  trace.info() << digSurf.size() << " surfels." << std::endl;
103  trace.endBlock();
104 
105  //slice retrieving
106  trace.beginBlock( "Extracting slice and constructing a grid curve. " );
107  typedef MyDigitalSurface::DigitalSurfaceTracker MyTracker;
108  typedef DigitalSurface2DSlice< MyTracker > My2DSlice;
109 
110  //Extract an initial boundary cell
111  Surfel surf = *digSurf.begin();
112  MyTracker* tracker = digSurf.container().newTracker( surf );
113 
114  // Extract the bondary contour associated to the initial surfel in
115  // its first direction
116  My2DSlice slice( tracker, *(ks.sDirs( surf )) );
117  delete tracker;
118 
120  GridCurve<KSpace> gc(ks);
121  gc.initFromSCellsRange( slice.begin(), slice.end() );
123 
124  trace.endBlock();
125 
126 
127  // for 3D display with Viewer3D
128  QApplication application(argc,argv);
129  trace.beginBlock( "Display all with QGLViewer." );
130  Viewer3D<Space, KSpace> viewer(ks);
131  viewer.show();
132  // Displaying all the surfels in transparent mode
133  viewer << SetMode3D( surf.className(), "Transparent");
134  for( MyDigitalSurface::ConstIterator it = theSetOfSurfels.begin(),
135  it_end = theSetOfSurfels.end(); it != it_end; ++it )
136  viewer<< *it;
137 
138 
139  // Displaying slice
140  viewer << Viewer3D<Space, KSpace>::shiftSurfelVisu;
141  viewer << SetMode3D( surf.className(), "");
142  viewer.setFillColor( Color( 50, 50, 255 ) );
143 
144  if (type == "gridcurve")
145  {
146  viewer << gc;
147  }
148  else if (type == "inner")
149  {
150  viewer << gc.getInnerPointsRange();
151  }
152  else if (type == "outer")
153  {
154  viewer << gc.getOuterPointsRange();
155  }
156  else if (type == "incident")
157  {
158  viewer << gc.getIncidentPointsRange();
159  }
160  else
161  {
162  trace.info() << "Display type not known." << std::endl;
163  }
164 
165  viewer << Viewer3D<Space, KSpace>::updateDisplay;
166  trace.endBlock();
167 
168  return application.exec();
169 }
170 // //
void beginBlock(const std::string &keyword="")
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
Trace trace
Definition: Common.h:130
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
std::set< SCell > SurfelSet
Preferred type for defining a set of surfels (always signed cells).
STL namespace.
double endBlock()
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
DigitalSurfaceContainer::DigitalSurfaceTracker DigitalSurfaceTracker
DirIterator sDirs(const SCell &p) const
ConstIterator begin() const
Aim: Represents a 2-dimensional slice in a DigitalSurface. In a sense, it is a 4-connected contour...
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:88
void setFromImage(const I &aImg, const O &ito, const typename I::Value &aThreshold=0)
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
std::ostream & info()
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value...
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels...
Definition: SetOfSurfels.h:73
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
const Domain & domain() const
Definition: Image.h:192
Aim: this output iterator class is designed to allow algorithms to insert points in the digital set...
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition: GridCurve.h:172
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex...
Modifier class in a Display3D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithDisplay3D.