DGtal 1.3.0
Loading...
Searching...
No Matches
exampleIntegralInvariantCurvature2D.cpp
Go to the documentation of this file.
1
32#include <iostream>
33#include "DGtal/base/Common.h"
34
35// Shape construction
36#include "DGtal/shapes/parametric/Flower2D.h"
37#include "DGtal/shapes/GaussDigitizer.h"
38#include "DGtal/topology/LightImplicitDigitalSurface.h"
39#include "DGtal/topology/DigitalSurface.h"
40#include "DGtal/graph/DepthFirstVisitor.h"
41#include "DGtal/graph/GraphVisitorRange.h"
42 #include "DGtal/images/ImageHelper.h"
43
45#include "DGtal/geometry/surfaces/estimation/IIGeometricFunctors.h"
46#include "DGtal/geometry/surfaces/estimation/IntegralInvariantVolumeEstimator.h"
47
48// Drawing
49#include "DGtal/io/boards/Board2D.h"
50#include "DGtal/io/colormaps/GradientColorMap.h"
51
53
54using namespace DGtal;
55
57
58int main( int argc, char** argv )
59{
60 trace.beginBlock ( "Example IntegralInvariantCurvature2D" );
61 trace.info() << "Args:";
62 for ( int i = 0; i < argc; ++i )
63 trace.info() << " " << argv[ i ];
64 trace.info() << std::endl;
65
67 double h = 0.5;
68
69 typedef Flower2D< Z2i::Space > MyShape;
70 typedef GaussDigitizer< Z2i::Space, MyShape > MyGaussDigitizer;
73
74 MyShape shape( 0, 0, 20.00000124, 10.0000123, 6, 3.0 );
75
76 MyGaussDigitizer digShape;
77 digShape.attach( shape );
78 digShape.init( shape.getLowerBound() + Z2i::Point::diagonal(-1), shape.getUpperBound() + Z2i::Point::diagonal(1), h );
79 Z2i::Domain domainShape = digShape.getDomain();
80 Z2i::KSpace KSpaceShape;
81 bool space_ok = KSpaceShape.init( domainShape.lowerBound(), domainShape.upperBound(), true );
82 if ( !space_ok )
83 {
84 trace.error() << "Error in the Khamisky space construction." << std::endl;
85 return 2;
86 }
87
89 Image image( domainShape );
90 DGtal::imageFromRangeAndValue( domainShape.begin(), domainShape.end(), image );
91
93 Z2i::KSpace::Surfel bel = Surfaces<Z2i::KSpace>::findABel( KSpaceShape, digShape, 100000 );
94 LightImplicitDigSurface LightImplDigSurf( KSpaceShape, digShape, SAdj, bel );
95 MyDigitalSurface digSurf( LightImplDigSurf );
96
98 typedef GraphVisitorRange< Visitor > VisitorRange;
99 typedef VisitorRange::ConstIterator SurfelConstIterator;
100
101 VisitorRange range( new Visitor( digSurf, *digSurf.begin() ) );
102 SurfelConstIterator abegin = range.begin();
103 SurfelConstIterator aend = range.end();
104
107 double re_convolution_kernel = 4.5; // Euclidean radius of the convolution kernel. Set by user.
108
109 typedef functors::IICurvatureFunctor<Z2i::Space> MyIICurvatureFunctor;
111 typedef MyIICurvatureFunctor::Value Value;
112
113 MyIICurvatureFunctor curvatureFunctor;
114 curvatureFunctor.init( h, re_convolution_kernel ); // Initialisation for a grid step and a given Euclidean radius of convolution kernel
115
116 MyIICurvatureEstimator curvatureEstimator( curvatureFunctor );
117 curvatureEstimator.attach( KSpaceShape, digShape );
118 curvatureEstimator.setParams( re_convolution_kernel/h );
119 curvatureEstimator.init( h, abegin, aend );
120
121 std::vector< Value > results;
122 std::back_insert_iterator< std::vector< Value > > resultsIt( results );
123 curvatureEstimator.eval( abegin, aend, resultsIt );
125
127 Value min = std::numeric_limits < Value >::max();
128 Value max = std::numeric_limits < Value >::min();
129 for ( unsigned int i = 0; i < results.size(); ++i )
130 {
131 if ( results[ i ] < min )
132 {
133 min = results[ i ];
134 }
135 else if ( results[ i ] > max )
136 {
137 max = results[ i ];
138 }
139 }
140 Board2D board;
141 VisitorRange range2( new Visitor( digSurf, *digSurf.begin() ) );
142 abegin = range2.begin();
143
144 typedef GradientColorMap< Value > Gradient;
145 Gradient cmap_grad( min, max );
146 cmap_grad.addColor( Color( 50, 50, 255 ) );
147 cmap_grad.addColor( Color( 255, 0, 0 ) );
148 cmap_grad.addColor( Color( 255, 255, 10 ) );
149
150 board << SetMode( (*abegin).className(), "Paving" );
151 std::string specificStyle = (*abegin).className() + "/Paving";
152 for ( unsigned int i = 0; i < results.size(); ++i )
153 {
154 Z2i::KSpace::SCell currentCell = KSpaceShape.sIndirectIncident( *abegin, *KSpaceShape.sOrthDirs( *abegin ) ); // We apply the color to the inner spel (more visible than surfel)
155 board << CustomStyle( specificStyle, new CustomColors( Color::Black, cmap_grad( results[ i ] )))
156 << currentCell;
157 ++abegin;
158 }
159 board.saveSVG ( "example-integralinvariant2D.svg" );
160 trace.endBlock();
161 return 0;
162}
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
static const Color Black
Definition: Color.h:413
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...
ConstIterator begin() const
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 & begin() const
const Point & lowerBound() const
const Point & upperBound() const
const ConstIterator & end() 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...
static Self diagonal(Component val=1)
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
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()
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
BreadthFirstVisitor< MyDigitalSurface > Visitor
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
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)
int main()
Definition: testBits.cpp:56