DGtal  0.9.3
exampleGridCurve3d-2.cpp
Go to the documentation of this file.
1 
53 #include <iostream>
55 #include "DGtal/base/Common.h"
56 
57 #include "DGtal/helpers/StdDefs.h"
58 #include "DGtal/topology/KhalimskySpaceND.h"
59 #include "DGtal/topology/SurfelAdjacency.h"
60 #include "DGtal/topology/DigitalSurface.h"
61 #include "DGtal/topology/SetOfSurfels.h"
62 #include "DGtal/topology/DigitalSurface2DSlice.h"
63 #include "DGtal/topology/helpers/Surfaces.h"
64 
65 #include "DGtal/io/viewers/Viewer3D.h"
66 #include "DGtal/io/readers/VolReader.h"
67 #include "DGtal/io/DrawWithDisplay3DModifier.h"
68 #include "DGtal/images/ImageSelector.h"
69 #include "DGtal/images/ImageHelper.h"
70 #include "DGtal/kernel/sets/DigitalSetInserter.h"
71 #include "DGtal/io/Color.h"
72 
73 #include "DGtal/geometry/curves/GridCurve.h"
74 
75 #include "ConfigExamples.h"
76 
77 
78 
80 using namespace std;
81 using namespace DGtal;
82 using namespace Z3i;
84 
85 int main( int argc, char** argv )
86 {
87  trace.info() << "exampleGridCurve3d-2: the type of data to be displayed "
88  << "may be given as argument as follows: "
89  << argv[0] << " inner" << endl;
90  trace.info() << "Available types are: gridcurve (default), inner, outer, incident" << endl;
91 
92  string type = (argc > 1) ? string(argv[1]) : "gridcurve";
93  trace.info() << "Chosen type: " << type << endl;
94 
95  //vol reading and digital set construction
96  trace.beginBlock( "Reading vol file into an image." );
98  std::string inputFilename = examplesPath + "samples/cat10.vol";
99  Image image = VolReader<Image>::importVol(inputFilename);
100  DigitalSet set3d (image.domain());
101  setFromImage( image, DigitalSetInserter<DigitalSet>(set3d), 1);
102  trace.info() << set3d.size() << " voxels." << std::endl;
103  trace.endBlock();
104 
105  //Khalimsky space construction
106  trace.beginBlock( "Construct the Khalimsky space from the image domain." );
107  KSpace ks;
108  trace.endBlock();
109 
110  //digital surface construction
111  typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
112  MySurfelAdjacency surfAdj( true ); // interior in all directions.
113 
114  trace.beginBlock( "Extracting boundary by scanning the space. " );
115  typedef KSpace::Surfel Surfel;
117  typedef SetOfSurfels< KSpace, SurfelSet > MySetOfSurfels;
119  MySetOfSurfels theSetOfSurfels( ks, surfAdj );
120  Surfaces<KSpace>::sMakeBoundary( theSetOfSurfels.surfelSet(),
121  ks, set3d,
122  image.domain().lowerBound(),
123  image.domain().upperBound() );
124  MyDigitalSurface digSurf( theSetOfSurfels );
125  trace.info() << digSurf.size() << " surfels." << std::endl;
126  trace.endBlock();
127 
128  //slice retrieving
129  trace.beginBlock( "Extracting slice and constructing a grid curve. " );
130  typedef MyDigitalSurface::DigitalSurfaceTracker MyTracker;
131  typedef DigitalSurface2DSlice< MyTracker > My2DSlice;
132 
133  //Extract an initial boundary cell
134  Surfel surf = *digSurf.begin();
135  MyTracker* tracker = digSurf.container().newTracker( surf );
136 
137  // Extract the bondary contour associated to the initial surfel in
138  // its first direction
139  My2DSlice slice( tracker, *(ks.sDirs( surf )) );
140  delete tracker;
141 
143  GridCurve<KSpace> gc(ks);
144  gc.initFromSCellsRange( slice.begin(), slice.end() );
146 
147  trace.endBlock();
148 
149 
150  // for 3D display with Viewer3D
151  QApplication application(argc,argv);
152  trace.beginBlock( "Display all with QGLViewer." );
153  Viewer3D<Space, KSpace> viewer(ks);
154  viewer.show();
155  // Displaying all the surfels in transparent mode
156  viewer << SetMode3D( surf.className(), "Transparent");
157  for( MyDigitalSurface::ConstIterator it = theSetOfSurfels.begin(),
158  it_end = theSetOfSurfels.end(); it != it_end; ++it )
159  viewer<< *it;
160 
161 
162  // Displaying slice
163  viewer << Viewer3D<Space, KSpace>::shiftSurfelVisu;
164  viewer << SetMode3D( surf.className(), "");
165  viewer.setFillColor( Color( 50, 50, 255 ) );
166 
167  if (type == "gridcurve")
168  {
169  viewer << gc;
170  }
171  else if (type == "inner")
172  {
173  viewer << gc.getInnerPointsRange();
174  }
175  else if (type == "outer")
176  {
177  viewer << gc.getOuterPointsRange();
178  }
179  else if (type == "incident")
180  {
181  viewer << gc.getIncidentPointsRange();
182  }
183  else
184  {
185  trace.info() << "Display type not known." << std::endl;
186  }
187 
188  viewer << Viewer3D<Space, KSpace>::updateDisplay;
189  trace.endBlock();
190 
191  return application.exec();
192 }
193 // //
virtual void setFillColor(DGtal::Color aColor)
void beginBlock(const std::string &keyword="")
InnerPointsRange getInnerPointsRange() const
Definition: GridCurve.h:462
MyDigitalSurface::SurfelSet SurfelSet
Trace trace
Definition: Common.h:137
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
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
OuterPointsRange getOuterPointsRange() const
Definition: GridCurve.h:474
DirIterator sDirs(const SCell &p) 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:89
void setFromImage(const I &aImg, const O &ito, const typename I::Value &aThreshold=0)
bool initFromSCellsRange(const TIterator &itb, const TIterator &ite)
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...
ImageContainerBySTLVector< Domain, Value > Image
const Domain & domain() const
Definition: Image.h:192
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
int main(int argc, char **argv)
Aim: this output iterator class is designed to allow algorithms to insert points in the digital set...
IncidentPointsRange getIncidentPointsRange() const
Definition: GridCurve.h:486
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...
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
Modifier class in a Display3D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithDisplay3D.