DGtal 1.4.0
Loading...
Searching...
No Matches
digitalSurfaceSlice.cpp
Go to the documentation of this file.
1
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/DrawWithDisplay3DModifier.h"
56#include "DGtal/io/viewers/Viewer3D.h"
57#include "DGtal/images/ImageSelector.h"
58#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
59#include "DGtal/io/Color.h"
60#include "DGtal/io/colormaps/GradientColorMap.h"
61
62#include "ConfigExamples.h"
63
65using namespace std;
66using namespace DGtal;
67using namespace Z3i;
69
70int main( int argc, char** argv )
71{
72 // for 3D display with Viewer3D
73 QApplication application(argc,argv);
74
76 trace.beginBlock( "Reading vol file into an image." );
78 std::string inputFilename = examplesPath + "samples/Al.100.vol";
79 Image image = VolReader<Image>::importVol(inputFilename);
80 DigitalSet set3d (image.domain());
82 0, 1 );
83 Viewer3D<> viewer;
84 viewer.show();
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 }
100
102 typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
103 MySurfelAdjacency surfAdj( true ); // interior in all directions.
105
107 trace.beginBlock( "Extracting boundary by scanning the space. " );
108 typedef KSpace::Surfel Surfel;
110 typedef SetOfSurfels< KSpace, SurfelSet > MySetOfSurfels;
112 MySetOfSurfels theSetOfSurfels( ks, surfAdj );
113 Surfaces<KSpace>::sMakeBoundary( theSetOfSurfels.surfelSet(),
114 ks, set3d,
115 image.domain().lowerBound(),
116 image.domain().upperBound() );
117 MyDigitalSurface digSurf( theSetOfSurfels );
118 trace.info() << "Digital surface has " << digSurf.size() << " surfels."
119 << std::endl;
120 trace.endBlock();
122
124 trace.beginBlock( "Extract slices." );
126 typedef DigitalSurface2DSlice< MyTracker > My2DSlice;
127 //Extract an initial boundary cell
128 Surfel surf = *digSurf.begin();
129 MyTracker* tracker1 = digSurf.container().newTracker( surf );
130 MyTracker* tracker2 = digSurf.container().newTracker( surf );
131 // Extract the bondary contour associated to the initial surfel in
132 // its first direction
133 My2DSlice slice1( tracker1, *(ks.sDirs( surf )) );
134 // Extract the bondary contour associated to the initial surfel in
135 // its second direction
136 My2DSlice slice2( tracker2, *++(ks.sDirs( surf )) );
137 delete tracker1;
138 delete tracker2;
139 trace.endBlock();
141
142 ASSERT( slice1.start() == slice1.begin() );
143 ASSERT( slice1.cstart() == slice1.c() );
144 ASSERT( *slice1.begin() == surf );
145 ASSERT( *slice1.c() == surf );
146 ASSERT( *slice1.start() == surf );
147 ASSERT( *slice1.cstart() == surf );
148 ASSERT( *slice1.rcstart() == surf );
149 ASSERT( slice1.rcstart() == slice1.rc() );
150 ASSERT( *slice1.rc() == surf );
151 ASSERT( *(slice1.c()+1) == *(slice1.begin()+1) );
152 ASSERT( *(slice1.rc()+1) == *(slice1.rbegin()) );
153
155 trace.beginBlock( "Display all with QGLViewer." );
156 // Displaying all the surfels in transparent mode
157 viewer << SetMode3D( surf.className(), "Transparent");
158 for( MyDigitalSurface::ConstIterator it = theSetOfSurfels.begin(),
159 it_end = theSetOfSurfels.end(); it != it_end; ++it )
160 viewer<< *it;
161
162 // Displaying First surfels cut with gradient colors.;
163 GradientColorMap<int> cmap_grad( 0, slice1.size() );
164 cmap_grad.addColor( Color( 50, 50, 255 ) );
165 cmap_grad.addColor( Color( 255, 0, 0 ) );
166 cmap_grad.addColor( Color( 255, 255, 10 ) );
167
168 // Need to avoid surfel superposition (the surfel size in increased)
169 viewer << Viewer3D<>::shiftSurfelVisu;
170 viewer << SetMode3D( surf.className(), "");
171 viewer.setFillColor(Color(180, 200, 25, 255));
172
173 int d=0;
174 for ( My2DSlice::ConstIterator it = slice1.begin(),
175 it_end = slice1.end(); it != it_end; ++it )
176 {
177 Color col= cmap_grad(d);
178 viewer.setFillColor(Color(col.red(),col.green() ,col.blue(), 255));
179 viewer<< *it;
180 d++;
181 }
182
183 GradientColorMap<int> cmap_grad2( 0, slice2.size() );
184 cmap_grad2.addColor( Color( 50, 50, 255 ) );
185 cmap_grad2.addColor( Color( 255, 0, 0 ) );
186 cmap_grad2.addColor( Color( 255, 255, 10 ) );
187
188 d=0;
189 for ( My2DSlice::ConstIterator it = slice2.begin(),
190 it_end = slice2.end(); it != it_end; ++it )
191 {
192 Color col= cmap_grad2(d);
193 viewer.setFillColor(Color(col.red(),col.green() ,col.blue(), 255));
194 viewer<< *it;
195 d++;
196 }
197
198 // One need once again to avoid superposition.
199 viewer << Viewer3D<>::shiftSurfelVisu;
200 viewer.setFillColor(Color(18, 200, 25, 255));
201 viewer << surf ;
202 viewer << Viewer3D<>::updateDisplay;
203 trace.endBlock();
204
205 return application.exec();
207}
208// //
Structure representing an RGB triple with alpha component.
Definition Color.h:68
void green(const unsigned char aGreenValue)
void red(const unsigned char aRedValue)
void blue(const unsigned char aBlueValue)
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
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
virtual void setFillColor(DGtal::Color aColor)
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
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
std::set< SCell > SurfelSet
Preferred type for defining a set of surfels (always signed cells).
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.
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
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...
void beginBlock(const std::string &keyword="")
std::ostream & error()
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...
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
MyDigitalSurface::SurfelSet SurfelSet
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition Common.h:153
STL namespace.
ImageContainerBySTLVector< Domain, Value > Type
static void append(Set &aSet, const ForegroundPredicate &isForeground, typename Image::Domain::ConstIterator itBegin, typename Image::Domain::ConstIterator itEnd)
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.
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
int main()
Definition testBits.cpp:56
ImageContainerBySTLVector< Domain, Value > Image