DGtal  1.2.0
Functions
digitalSurfaceSlice.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/topology/KhalimskySpaceND.h"
#include "DGtal/topology/SurfelAdjacency.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/topology/SetOfSurfels.h"
#include "DGtal/topology/DigitalSurface2DSlice.h"
#include "DGtal/topology/helpers/Surfaces.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/DrawWithDisplay3DModifier.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
#include "DGtal/io/Color.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "ConfigExamples.h"
Include dependency graph for digitalSurfaceSlice.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Bertrand Kerautret (kerau.nosp@m.tre@.nosp@m.loria.nosp@m..fr ) LORIA (CNRS, UMR 7503), University of Nancy, France
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2012/02/29

An example file named digitalSurfaceSlice.

This file is part of the DGtal library.

Definition in file digitalSurfaceSlice.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

[digitalSurfaceSlice-readVol]

[digitalSurfaceSlice-readVol]

[digitalSurfaceSlice-KSpace]

[digitalSurfaceSlice-KSpace]

[digitalSurfaceSlice-SurfelAdjacency]

[digitalSurfaceSlice-SurfelAdjacency]

[digitalSurfaceSlice-ExtractingSurface]

[digitalSurfaceSlice-ExtractingSurface]

[digitalSurfaceSlice-ExtractingSlice]

[digitalSurfaceSlice-ExtractingSlice]

[digitalSurfaceSlice-displayingAll]

[digitalSurfaceSlice-displayingAll]

Definition at line 70 of file digitalSurfaceSlice.cpp.

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();
85  trace.endBlock();
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  }
98  trace.endBlock();
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." );
125  typedef MyDigitalSurface::DigitalSurfaceTracker MyTracker;
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 }
Structure representing an RGB triple with alpha component.
Definition: Color.h:67
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...
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
DigitalSurfaceContainer::DigitalSurfaceTracker DigitalSurfaceTracker
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...
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....
Definition: SetOfSurfels.h:74
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:79
std::ostream & error()
void beginBlock(const std::string &keyword="")
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::ConstIterator ConstIterator
MyDigitalSurface::SurfelSet SurfelSet
Trace trace
Definition: Common.h:154
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:64
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.
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:90
ImageContainerBySTLVector< Domain, Value > Image

References DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::addColor(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::begin(), DGtal::Trace::beginBlock(), DGtal::Color::blue(), DGtal::SignedKhalimskyCell< dim, TInteger >::className(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::container(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::domain(), DGtal::Trace::endBlock(), DGtal::Trace::error(), DGtal::Color::green(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::Color::red(), DGtal::KhalimskySpaceND< dim, TInteger >::sDirs(), DGtal::Display3D< Space, KSpace >::setFillColor(), DGtal::Viewer3D< TSpace, TKSpace >::show(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::size(), and DGtal::trace.