DGtal 1.4.0
Loading...
Searching...
No Matches
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/Viewer3D.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];
87 Image image = VolReader<Image>::importVol( filename );
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
156 QApplication application( argc, argv );
158 Viewer viewer( KSpaceShape );
159 viewer.setWindowTitle("example Integral Invariant 3D");
160 viewer.show();
161
162 typedef GradientColorMap< Value > Gradient;
163 Gradient cmap_grad( min, max );
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 VisitorRange range2( new Visitor( digSurf, *digSurf.begin() ) );
169 abegin = range2.begin();
170
171 Z3i::KSpace::Cell dummy_cell;
172 viewer << SetMode3D( dummy_cell.className(), "Basic" );
173
174 for ( unsigned int i = 0; i < results.size(); ++i )
175 {
176 viewer << CustomColors3D( Color::Black, cmap_grad( results[ i ] ))
177 << KSpaceShape.unsigns( *abegin );
178 ++abegin;
179 }
180
181 viewer << Viewer3D<>::updateDisplay;
182
183 trace.endBlock();
184 return application.exec();
185}
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...
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 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...
void init(const double _h, SurfelConstIterator itb, SurfelConstIterator ite)
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.
Cell unsigns(const SCell &p) const
Creates an unsigned cell from a signed one.
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...
void beginBlock(const std::string &keyword="")
std::ostream & error()
std::ostream & info()
double endBlock()
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
BreadthFirstVisitor< MyDigitalSurface > Visitor
Trace trace
Definition Common.h:153
std::string className() const
Return the style name used for drawing this object.
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.
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
Aim: A functor Real -> Real that returns the 3d mean curvature by transforming the given volume....
int max(int a, int b)
Domain domain
ImageContainerBySTLVector< Domain, Value > Image

References DGtal::DigitalSurface< TDigitalSurfaceContainer >::begin(), DGtal::Trace::beginBlock(), DGtal::Color::Black, DGtal::KhalimskyCell< dim, TInteger >::className(), domain, DGtal::Trace::endBlock(), DGtal::Trace::error(), DGtal::Surfaces< TKSpace >::findABel(), DGtal::VolReader< TImageContainer, TFunctor >::importVol(), DGtal::Trace::info(), DGtal::IntegralInvariantVolumeEstimator< TKSpace, TPointPredicate, TVolumeFunctor >::init(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::HyperRectDomain< TSpace >::lowerBound(), max(), DGtal::Viewer3D< TSpace, TKSpace >::show(), DGtal::trace, DGtal::KhalimskySpaceND< dim, TInteger >::unsigns(), and DGtal::HyperRectDomain< TSpace >::upperBound().