Loading [MathJax]/extensions/MathMenu.js
DGtal 2.0.0
exampleIntegralInvariantCurvature3D.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
#include "DGtal/topology/helpers/Surfaces.h"
#include "DGtal/topology/LightImplicitDigitalSurface.h"
#include "DGtal/images/ImageHelper.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/graph/DepthFirstVisitor.h"
#include "DGtal/graph/GraphVisitorRange.h"
#include "DGtal/geometry/surfaces/estimation/IIGeometricFunctors.h"
#include "DGtal/geometry/surfaces/estimation/IntegralInvariantVolumeEstimator.h"
#include "DGtal/io/viewers/PolyscopeViewer.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
Include dependency graph for exampleIntegralInvariantCurvature3D.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 exampleIntegralInvariantCurvature3D.

This file is part of the DGtal library.

Definition in file exampleIntegralInvariantCurvature3D.cpp.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Construction of the shape from vol file

Integral Invariant stuff [IntegralInvariantUsage]

[IntegralInvariantUsage]

Drawing results

Definition at line 61 of file exampleIntegralInvariantCurvature3D.cpp.

62{
63 if ( argc != 4 )
64 {
65 trace.error() << "Usage: " << argv[0]
66 << " <fileName.vol> <threshold> <radius>" << std::endl;
67 trace.error() << "Example : "<< argv[0] << " Al.150.vol 0 7" << std::endl;
68 return 0;
69 }
70
71 trace.beginBlock ( "Example IntegralInvariantCurvature3D" );
72 trace.info() << "Args:";
73 for ( int i = 0; i < argc; ++i )
74 trace.info() << " " << argv[ i ];
75 trace.info() << std::endl;
76
77 double h = 1.0;
78 unsigned int threshold = std::atoi( argv[ 2 ] );
79
83 typedef LightImplicitDigitalSurface< Z3i::KSpace, ImagePredicate > MyLightImplicitDigitalSurface;
85
86 std::string filename = argv[1];
88 ImagePredicate predicate = ImagePredicate( image, threshold );
89
90 Z3i::Domain domain = image.domain();
91
92 Z3i::KSpace KSpaceShape;
93
94 bool space_ok = KSpaceShape.init( domain.lowerBound(), domain.upperBound(), true );
95 if (!space_ok)
96 {
97 trace.error() << "Error in the Khalimsky space construction."<<std::endl;
98 return 2;
99 }
100
102 Z3i::KSpace::Surfel bel = Surfaces< Z3i::KSpace >::findABel( KSpaceShape, predicate, 100000 );
103 MyLightImplicitDigitalSurface LightImplDigSurf( KSpaceShape, predicate, SAdj, bel );
104 MyDigitalSurface digSurf( LightImplDigSurf );
105
107 typedef GraphVisitorRange< Visitor > VisitorRange;
108 typedef VisitorRange::ConstIterator SurfelConstIterator;
109
110 VisitorRange range( new Visitor( digSurf, *digSurf.begin() ) );
111 SurfelConstIterator abegin = range.begin();
112 SurfelConstIterator aend = range.end();
113
116 double radius = std::atof(argv[3]);
117
118 typedef functors::IIMeanCurvature3DFunctor<Z3i::Space> MyIICurvatureFunctor;
120
121 // For computing Gaussian curvature instead, for example, change the two typedef above by :
122 // typedef functors::IIGaussianCurvature3DFunctor<Z3i::Space> MyIICurvatureFunctor;
123 // typedef IntegralInvariantCovarianceEstimator< Z3i::KSpace, ImagePredicate, MyIICurvatureFunctor > MyIICurvatureEstimator;
124 // and it's done. The following part is exactly the same.
125
126 typedef MyIICurvatureFunctor::Value Value;
127
128 MyIICurvatureFunctor curvatureFunctor; // Functor used to convert volume -> curvature
129 curvatureFunctor.init( h, radius ); // Initialisation for a grid step and a given Euclidean radius of convolution kernel
130
131 MyIICurvatureEstimator curvatureEstimator( curvatureFunctor );
132 curvatureEstimator.attach( KSpaceShape, predicate ); // Setting a KSpace and a predicate on the object to evaluate
133 curvatureEstimator.setParams( radius / h ); // Setting the digital radius of the convolution kernel
134 curvatureEstimator.init( h, abegin, aend ); // Initialisation for a given h, and a range of surfels
135
136 std::vector< Value > results;
137 std::back_insert_iterator< std::vector< Value > > resultsIt( results ); // output iterator for results of Integral Invariant curvature computation
138 curvatureEstimator.eval( abegin, aend, resultsIt ); // Computation
140
142 Value min = std::numeric_limits < Value >::max();
143 Value max = std::numeric_limits < Value >::min();
144 for ( unsigned int i = 0; i < results.size(); ++i )
145 {
146 if ( results[ i ] < min )
147 {
148 min = results[ i ];
149 }
150 else if ( results[ i ] > max )
151 {
152 max = results[ i ];
153 }
154 }
155
157 Viewer viewer( KSpaceShape );
158 viewer.allowReuseList = true;
159
160 typedef GradientColorMap< Value > Gradient;
161 Gradient cmap_grad( min, max );
162 cmap_grad.addColor( Color( 50, 50, 255 ) );
163 cmap_grad.addColor( Color( 255, 0, 0 ) );
164 cmap_grad.addColor( Color( 255, 255, 10 ) );
165
166 VisitorRange range2( new Visitor( digSurf, *digSurf.begin() ) );
167 abegin = range2.begin();
168
169 Z3i::KSpace::Cell dummy_cell;
170
171 viewer.allowReuseList = true;
172 for ( unsigned int i = 0; i < results.size(); ++i )
173 {
174 viewer << WithQuantity(KSpaceShape.unsigns(*abegin), "Curvature", results[i]);
175 ++abegin;
176 }
177
178 trace.endBlock();
179 viewer.show();
180 return 0;
181}
Structure representing an RGB triple with alpha component.
Definition Color.h:77
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: 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.
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...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
Cell unsigns(const SCell &p) const
Creates an unsigned cell from a signed one.
KhalimskyCell< dim, Integer > Cell
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
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...
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
BreadthFirstVisitor< MyDigitalSurface > Visitor
HyperRectDomain< Space > Domain
Definition StdDefs.h:172
KhalimskySpaceND< 3, Integer > KSpace
Definition StdDefs.h:146
Trace trace
ImageContainerBySTLVector< Domain, Value > Type
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
Attach a property to an element.
Definition Display3D.h:327
Aim: A functor Real -> Real that returns the 3d mean curvature by transforming the given volume....
int max(int a, int b)
Domain domain
Image image(domain)

References DGtal::Display3D< Space, KSpace >::allowReuseList, DGtal::DigitalSurface< TDigitalSurfaceContainer >::begin(), domain, DGtal::Surfaces< TKSpace >::findABel(), image(), DGtal::VolReader< TImageContainer, TFunctor >::importVol(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), max(), DGtal::PolyscopeViewer< Space, KSpace >::show(), DGtal::trace, and DGtal::KhalimskySpaceND< dim, TInteger >::unsigns().