Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
exampleGridCurve3d-2.cpp
Go to the documentation of this file.
1
16
29
52
54#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/PolyscopeViewer.h"
66#include "DGtal/io/readers/VolReader.h"
67#include "DGtal/images/ImageSelector.h"
68#include "DGtal/images/ImageHelper.h"
69#include "DGtal/kernel/sets/DigitalSetInserter.h"
70#include "DGtal/io/Color.h"
71
72#include "DGtal/geometry/curves/GridCurve.h"
73
74#include "ConfigExamples.h"
75
76
77
79using namespace std;
80using namespace DGtal;
81using namespace Z3i;
83
84int main( int argc, char** argv )
85{
86 trace.info() << "exampleGridCurve3d-2: the type of data to be displayed "
87 << "may be given as argument as follows: "
88 << argv[0] << " inner" << endl;
89 trace.info() << "Available types are: gridcurve (default), inner, outer, incident" << endl;
90
91 string type = (argc > 1) ? string(argv[1]) : "gridcurve";
92 trace.info() << "Chosen type: " << type << endl;
93
94 //vol reading and digital set construction
95 trace.beginBlock( "Reading vol file into an image." );
97 std::string inputFilename = examplesPath + "samples/cat10.vol";
99 DigitalSet set3d (image.domain());
101 trace.info() << set3d.size() << " voxels." << std::endl;
102 trace.endBlock();
103
104 //Khalimsky space construction
105 trace.beginBlock( "Construct the Khalimsky space from the image domain." );
106 KSpace ks;
107 trace.endBlock();
108
109 //digital surface construction
110 typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
111 MySurfelAdjacency surfAdj( true ); // interior in all directions.
112
113 trace.beginBlock( "Extracting boundary by scanning the space. " );
114 typedef KSpace::Surfel Surfel;
116 typedef SetOfSurfels< KSpace, SurfelSet > MySetOfSurfels;
118 MySetOfSurfels theSetOfSurfels( ks, surfAdj );
119 Surfaces<KSpace>::sMakeBoundary( theSetOfSurfels.surfelSet(),
120 ks, set3d,
121 image.domain().lowerBound(),
122 image.domain().upperBound() );
123 MyDigitalSurface digSurf( theSetOfSurfels );
124 trace.info() << digSurf.size() << " surfels." << std::endl;
125 trace.endBlock();
126
127 //slice retrieving
128 trace.beginBlock( "Extracting slice and constructing a grid curve. " );
130 typedef DigitalSurface2DSlice< MyTracker > My2DSlice;
131
132 //Extract an initial boundary cell
133 Surfel surf = *digSurf.begin();
134 MyTracker* tracker = digSurf.container().newTracker( surf );
135
136 // Extract the bondary contour associated to the initial surfel in
137 // its first direction
138 My2DSlice slice( tracker, *(ks.sDirs( surf )) );
139 delete tracker;
140
142 GridCurve<KSpace> gc(ks);
143 gc.initFromSCellsRange( slice.begin(), slice.end() );
145
146 trace.endBlock();
147
148
149 // for 3D display with PolyscopeViewer
150 trace.beginBlock( "Display all with Viewer." );
152 // Displaying all the surfels in transparent mode
153 viewer.allowReuseList = true;
154 for( MyDigitalSurface::ConstIterator it = theSetOfSurfels.begin(),
155 it_end = theSetOfSurfels.end(); it != it_end; ++it )
156 viewer<< *it;
157
158 // Displaying slice
159 viewer << Color( 50, 50, 255 );
160
161 if (type == "gridcurve")
162 {
163 viewer << gc;
164 }
165 else if (type == "inner")
166 {
167 viewer << gc.getInnerPointsRange();
168 }
169 else if (type == "outer")
170 {
171 viewer << gc.getOuterPointsRange();
172 }
173 else if (type == "incident")
174 {
175 viewer << gc.getIncidentPointsRange();
176 }
177 else
178 {
179 trace.info() << "Display type not known." << std::endl;
180 }
181
182 trace.endBlock();
183
184 viewer.show();
185 return 0;
186}
187// //
Structure representing an RGB triple with alpha component.
Definition Color.h:77
DigitalSurfaceTracker * newTracker(const Surfel &s) const
Aim: this output iterator class is designed to allow algorithms to insert points in the digital set....
Aim: Represents a 2-dimensional slice in a DigitalSurface. In a sense, it is a 4-connected contour,...
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
const DigitalSurfaceContainer & container() const
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
DigitalSurfaceContainer::DigitalSurfaceTracker DigitalSurfaceTracker
ConstIterator begin() const
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition GridCurve.h:173
IncidentPointsRange getIncidentPointsRange() const
Definition GridCurve.h:478
OuterPointsRange getOuterPointsRange() const
Definition GridCurve.h:466
InnerPointsRange getInnerPointsRange() const
Definition GridCurve.h:454
bool initFromSCellsRange(const TIterator &itb, const TIterator &ite)
Aim: implements association bewteen points lying in a digital domain and values.
Definition Image.h:70
DirIterator sDirs(const SCell &p) const
Given a signed cell [p], returns an iterator to iterate over each coordinate the cell spans.
void show() override
Starts the event loop and display of elements.
static void sMakeBoundary(SCellSet &aBoundary, const KSpace &aKSpace, const PointPredicate &pp, const Point &aLowerBound, const Point &aUpperBound)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
MyDigitalSurface::SurfelSet SurfelSet
Z3i this namespace gathers the standard of types for 3D imagery.
KhalimskySpaceND< 3, Integer > KSpace
Definition StdDefs.h:146
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition StdDefs.h:173
DGtal is the top-level namespace which contains all DGtal functions and types.
void setFromImage(const I &aImg, const O &ito, const typename I::Value &aThreshold=0)
Trace trace
STL namespace.
ImageContainerBySTLVector< Domain, Value > Type
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
int main()
Definition testBits.cpp:56
Image image(domain)