Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
digitalSurfaceSlice.cpp
Go to the documentation of this file.
1
16
31
39
40
42#include <iostream>
43
44#include "DGtal/base/Common.h"
45
46#include "DGtal/helpers/StdDefs.h"
47#include "DGtal/topology/KhalimskySpaceND.h"
48#include "DGtal/topology/SurfelAdjacency.h"
49#include "DGtal/topology/DigitalSurface.h"
50#include "DGtal/topology/SetOfSurfels.h"
51#include "DGtal/topology/DigitalSurface2DSlice.h"
52#include "DGtal/topology/helpers/Surfaces.h"
53
54#include "DGtal/io/readers/VolReader.h"
55#include "DGtal/io/viewers/PolyscopeViewer.h"
56#include "DGtal/images/ImageSelector.h"
57#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
58#include "DGtal/io/Color.h"
59#include "DGtal/io/colormaps/GradientColorMap.h"
60
61#include "ConfigExamples.h"
62
64using namespace std;
65using namespace DGtal;
66using namespace Z3i;
68
69int main( int argc, char** argv )
70{
72 trace.beginBlock( "Reading vol file into an image." );
74 std::string inputFilename = examplesPath + "samples/Al.100.vol";
76 DigitalSet set3d (image.domain());
78 0, 1 );
79 PolyscopeViewer<> viewer;
80 trace.endBlock();
82
84 trace.beginBlock( "Construct the Khalimsky space from the image domain." );
85 KSpace ks;
86 bool space_ok = ks.init( image.domain().lowerBound(),
87 image.domain().upperBound(), true );
88 if (!space_ok)
89 {
90 trace.error() << "Error in the Khamisky space construction."<<std::endl;
91 return 2;
92 }
93 trace.endBlock();
95
97 typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
98 MySurfelAdjacency surfAdj( true ); // interior in all directions.
100
102 trace.beginBlock( "Extracting boundary by scanning the space. " );
103 typedef KSpace::Surfel Surfel;
105 typedef SetOfSurfels< KSpace, SurfelSet > MySetOfSurfels;
107 MySetOfSurfels theSetOfSurfels( ks, surfAdj );
108 Surfaces<KSpace>::sMakeBoundary( theSetOfSurfels.surfelSet(),
109 ks, set3d,
110 image.domain().lowerBound(),
111 image.domain().upperBound() );
112 MyDigitalSurface digSurf( theSetOfSurfels );
113 trace.info() << "Digital surface has " << digSurf.size() << " surfels."
114 << std::endl;
115 trace.endBlock();
117
119 trace.beginBlock( "Extract slices." );
121 typedef DigitalSurface2DSlice< MyTracker > My2DSlice;
122 //Extract an initial boundary cell
123 Surfel surf = *digSurf.begin();
124 MyTracker* tracker1 = digSurf.container().newTracker( surf );
125 MyTracker* tracker2 = digSurf.container().newTracker( surf );
126 // Extract the bondary contour associated to the initial surfel in
127 // its first direction
128 My2DSlice slice1( tracker1, *(ks.sDirs( surf )) );
129 // Extract the bondary contour associated to the initial surfel in
130 // its second direction
131 My2DSlice slice2( tracker2, *++(ks.sDirs( surf )) );
132 delete tracker1;
133 delete tracker2;
134 trace.endBlock();
136
137 ASSERT( slice1.start() == slice1.begin() );
138 ASSERT( slice1.cstart() == slice1.c() );
139 ASSERT( *slice1.begin() == surf );
140 ASSERT( *slice1.c() == surf );
141 ASSERT( *slice1.start() == surf );
142 ASSERT( *slice1.cstart() == surf );
143 ASSERT( *slice1.rcstart() == surf );
144 ASSERT( slice1.rcstart() == slice1.rc() );
145 ASSERT( *slice1.rc() == surf );
146 ASSERT( *(slice1.c()+1) == *(slice1.begin()+1) );
147 ASSERT( *(slice1.rc()+1) == *(slice1.rbegin()) );
148
150 trace.beginBlock( "Display all with Viewer." );
151 // Displaying all the surfels in transparent mode
152 for( MyDigitalSurface::ConstIterator it = theSetOfSurfels.begin(),
153 it_end = theSetOfSurfels.end(); it != it_end; ++it )
154 viewer<< *it;
155
156 // Displaying First surfels cut with gradient colors.;
157 GradientColorMap<int> cmap_grad( 0, slice1.size() );
158 cmap_grad.addColor( Color( 50, 50, 255 ) );
159 cmap_grad.addColor( Color( 255, 0, 0 ) );
160 cmap_grad.addColor( Color( 255, 255, 10 ) );
161
162 // Need to avoid surfel superposition (the surfel size in increased)
163 viewer.drawColor(Color(180, 200, 25, 255));
164
165 int d=0;
166 for ( My2DSlice::ConstIterator it = slice1.begin(),
167 it_end = slice1.end(); it != it_end; ++it )
168 {
169 Color col= cmap_grad(d);
170 viewer.drawColor(Color(col.red(),col.green() ,col.blue(), 255));
171 viewer<< *it;
172 d++;
173 }
174
175 GradientColorMap<int> cmap_grad2( 0, slice2.size() );
176 cmap_grad2.addColor( Color( 50, 50, 255 ) );
177 cmap_grad2.addColor( Color( 255, 0, 0 ) );
178 cmap_grad2.addColor( Color( 255, 255, 10 ) );
179
180 d=0;
181 for ( My2DSlice::ConstIterator it = slice2.begin(),
182 it_end = slice2.end(); it != it_end; ++it )
183 {
184 Color col= cmap_grad2(d);
185 viewer.drawColor(Color(col.red(),col.green() ,col.blue(), 255));
186 viewer<< *it;
187 d++;
188 }
189
190 // One need once again to avoid superposition.
191 viewer.drawColor(Color(18, 200, 25, 255));
192 viewer << surf ;
193 trace.endBlock();
194
195 viewer.show();
196 return 0;
198}
199// //
Structure representing an RGB triple with alpha component.
Definition Color.h:77
void green(const unsigned char aGreenValue)
void red(const unsigned char aRedValue)
void blue(const unsigned char aBlueValue)
DigitalSurfaceTracker * newTracker(const Surfel &s) const
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
void drawColor(const DGtal::Color &color)
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void addColor(const Color &color)
Aim: implements association bewteen points lying in a digital domain and values.
Definition Image.h:70
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
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.
Trace trace
STL namespace.
ImageContainerBySTLVector< Domain, Value > Type
static void append(Set &aSet, const ForegroundPredicate &isForeground, typename Image::Domain::ConstIterator itBegin, typename Image::Domain::ConstIterator itEnd)
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
int main()
Definition testBits.cpp:56
Image image(domain)