DGtal  1.5.beta
exampleIntegralInvariantCurvature2D.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/shapes/parametric/Flower2D.h"
#include "DGtal/shapes/GaussDigitizer.h"
#include "DGtal/topology/LightImplicitDigitalSurface.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/graph/DepthFirstVisitor.h"
#include "DGtal/graph/GraphVisitorRange.h"
#include "DGtal/images/ImageHelper.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/geometry/surfaces/estimation/IIGeometricFunctors.h"
#include "DGtal/geometry/surfaces/estimation/IntegralInvariantVolumeEstimator.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
Include dependency graph for exampleIntegralInvariantCurvature2D.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
Jérémy Levallois (jerem.nosp@m.y.le.nosp@m.vallo.nosp@m.is@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), INSA-Lyon, France LAboratoire de MAthématiques - LAMA (CNRS, UMR 5127), Université de Savoie, France
Date
2012/12/17

An example file named exampleIntegralInvariantCurvature2D.

This file is part of the DGtal library.

Definition in file exampleIntegralInvariantCurvature2D.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Construction of the shape + digitalization

Integral Invariant stuff [IntegralInvariantUsage]

Functor used to convert volume -> curvature

Setting a KSpace and a predicate on the object to evaluate

Setting the digital radius of the convolution kernel

Initialisation for a given h

output iterator for results of Integral Invariant curvature computation

Computation

[IntegralInvariantUsage]

Drawing results

Definition at line 59 of file exampleIntegralInvariantCurvature2D.cpp.

60 {
61  trace.beginBlock ( "Example IntegralInvariantCurvature2D" );
62  trace.info() << "Args:";
63  for ( int i = 0; i < argc; ++i )
64  trace.info() << " " << argv[ i ];
65  trace.info() << std::endl;
66 
68  double h = 0.5;
69 
70  typedef Flower2D< Z2i::Space > MyShape;
71  typedef GaussDigitizer< Z2i::Space, MyShape > MyGaussDigitizer;
74 
75  MyShape shape( 0, 0, 20.00000124, 10.0000123, 6, 3.0 );
76 
77  MyGaussDigitizer digShape;
78  digShape.attach( shape );
79  digShape.init( shape.getLowerBound() + Z2i::Point::diagonal(-1), shape.getUpperBound() + Z2i::Point::diagonal(1), h );
80  Z2i::Domain domainShape = digShape.getDomain();
81  Z2i::KSpace KSpaceShape;
82  bool space_ok = KSpaceShape.init( domainShape.lowerBound(), domainShape.upperBound(), true );
83  if ( !space_ok )
84  {
85  trace.error() << "Error in the Khamisky space construction." << std::endl;
86  return 2;
87  }
88 
90  Image image( domainShape );
91  DGtal::imageFromRangeAndValue( domainShape.begin(), domainShape.end(), image );
92 
94  Z2i::KSpace::Surfel bel = Surfaces<Z2i::KSpace>::findABel( KSpaceShape, digShape, 100000 );
95  LightImplicitDigSurface LightImplDigSurf( KSpaceShape, digShape, SAdj, bel );
96  MyDigitalSurface digSurf( LightImplDigSurf );
97 
99  typedef GraphVisitorRange< Visitor > VisitorRange;
100  typedef VisitorRange::ConstIterator SurfelConstIterator;
101 
102  VisitorRange range( new Visitor( digSurf, *digSurf.begin() ) );
103  SurfelConstIterator abegin = range.begin();
104  SurfelConstIterator aend = range.end();
105 
108  double re_convolution_kernel = 4.5; // Euclidean radius of the convolution kernel. Set by user.
109 
110  typedef functors::IICurvatureFunctor<Z2i::Space> MyIICurvatureFunctor;
113 
114  MyIICurvatureFunctor curvatureFunctor;
115  curvatureFunctor.init( h, re_convolution_kernel ); // Initialisation for a grid step and a given Euclidean radius of convolution kernel
116 
117  MyIICurvatureEstimator curvatureEstimator( curvatureFunctor );
118  curvatureEstimator.attach( KSpaceShape, digShape );
119  curvatureEstimator.setParams( re_convolution_kernel/h );
120  curvatureEstimator.init( h, abegin, aend );
121 
122  std::vector< Value > results;
123  std::back_insert_iterator< std::vector< Value > > resultsIt( results );
124  curvatureEstimator.eval( abegin, aend, resultsIt );
126 
129  Value max = std::numeric_limits < Value >::min();
130  for ( unsigned int i = 0; i < results.size(); ++i )
131  {
132  if ( results[ i ] < min )
133  {
134  min = results[ i ];
135  }
136  else if ( results[ i ] > max )
137  {
138  max = results[ i ];
139  }
140  }
141  Board2D board;
142  VisitorRange range2( new Visitor( digSurf, *digSurf.begin() ) );
143  abegin = range2.begin();
144 
145  typedef GradientColorMap< Value > Gradient;
146  Gradient cmap_grad( min, max );
147  cmap_grad.addColor( Color( 50, 50, 255 ) );
148  cmap_grad.addColor( Color( 255, 0, 0 ) );
149  cmap_grad.addColor( Color( 255, 255, 10 ) );
150 
151  board << SetMode( (*abegin).className(), "Paving" );
152  std::string specificStyle = (*abegin).className() + "/Paving";
153  for ( unsigned int i = 0; i < results.size(); ++i )
154  {
155  Z2i::KSpace::SCell currentCell = KSpaceShape.sIndirectIncident( *abegin, *KSpaceShape.sOrthDirs( *abegin ) ); // We apply the color to the inner spel (more visible than surfel)
156  board << CustomStyle( specificStyle, new CustomColors( Color::Black, cmap_grad( results[ i ] )))
157  << currentCell;
158  ++abegin;
159  }
160  board.saveSVG ( "example-integralinvariant2D.svg" );
161  trace.endBlock();
162  return 0;
163 }
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
Aim: This class is useful to perform a depth-first exploration of a graph given a starting point or s...
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:65
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: Transforms a graph visitor into a single pass input range.
const ConstIterator & end() const
const ConstIterator & begin() const
const Point & lowerBound() const
const Point & upperBound() const
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
Aim: This class implement an Integral Invariant estimator which computes for each surfel the volume o...
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
SCell sIndirectIncident(const SCell &p, Dimension k) const
Return the indirect incident cell of [p] along [k] (the incident cell along [k] whose sign is negativ...
DirIterator sOrthDirs(const SCell &p) const
Given a signed cell [p], returns an iterator to iterate over each coordinate the cell does not span.
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:79
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
std::ostream & error()
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1011
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
MyDigitalSurface::ConstIterator ConstIterator
BreadthFirstVisitor< MyDigitalSurface > Visitor
Trace trace
Definition: Common.h:153
void imageFromRangeAndValue(const It &itb, const It &ite, Im &aImg, const typename Im::Value &aValue=0)
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:279
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Aim: A functor Real -> Real that returns the 2d curvature by transforming the given volume....
int max(int a, int b)
Image image(domain)
ImageContainerBySTLVector< Domain, Value > Image

References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::begin(), DGtal::Trace::beginBlock(), DGtal::Color::Black, DGtal::PointVector< dim, Integer >::diagonal(), DGtal::HyperRectDomain< TSpace >::end(), DGtal::Trace::endBlock(), DGtal::Trace::error(), DGtal::Surfaces< TKSpace >::findABel(), image(), DGtal::imageFromRangeAndValue(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::HyperRectDomain< TSpace >::lowerBound(), max(), LibBoard::Board::saveSVG(), DGtal::KhalimskySpaceND< dim, TInteger >::sIndirectIncident(), DGtal::KhalimskySpaceND< dim, TInteger >::sOrthDirs(), DGtal::trace, and DGtal::HyperRectDomain< TSpace >::upperBound().