86 #include "DGtal/base/Common.h"
87 #include "DGtal/shapes/SurfaceMesh.h"
88 #include "DGtal/shapes/SurfaceMeshHelper.h"
90 #include "DGtal/geometry/meshes/CorrectedNormalCurrentComputer.h"
92 #include "DGtal/io/writers/SurfaceMeshWriter.h"
93 #include "DGtal/io/colormaps/GradientColorMap.h"
94 #include "DGtal/io/colormaps/QuantifiedColorMap.h"
108 void usage(
int argc,
char* argv[] )
110 std::cout <<
"Usage: " << std::endl
111 <<
"\t" << argv[ 0 ] <<
" <shape> <m> <n> <R>" << std::endl
113 <<
"Computation of mean and Gaussian curvatures on a shape, " << std::endl
114 <<
"using interpolated corrected curvature measures (based " << std::endl
115 <<
"on the theory of corrected normal currents)." << std::endl
116 <<
"- builds a <shape> in {torus,lantern,sphere}, with " << std::endl
117 <<
" <m> latitude points and <n> longitude points." << std::endl
118 <<
"- <R> is the radius of the measuring balls." << std::endl
119 <<
"It produces several OBJ files to display mean and" << std::endl
120 <<
"Gaussian curvature estimation results: `example-cnc-H.obj`" << std::endl
121 <<
"and `example-cnc-G.obj` as well as the associated MTL file." << std::endl;
124 int main(
int argc,
char* argv[] )
132 using namespace DGtal;
139 std::string input = argv[ 1 ];
140 int m = argc > 2 ? atoi( argv[ 2 ] ) : 20;
141 int n = argc > 3 ? atoi( argv[ 3 ] ) : 20;
142 double R = argc > 4 ? atof( argv[ 4 ] ) : 0.5;
146 double exp_H_min = 0.0;
147 double exp_H_max = 0.0;
148 double exp_G_min = 0.0;
149 double exp_G_max = 0.0;
150 if ( input ==
"torus" )
152 const double big_radius = 3.0;
153 const double small_radius = 1.0;
154 smesh = SMH::makeTorus( big_radius, small_radius,
156 SMH::NormalsType::VERTEX_NORMALS );
157 exp_H_min = ( 0.5 / ( small_radius - big_radius ) + 0.5 / small_radius );
158 exp_H_max = ( 0.5 / ( big_radius + small_radius ) + 0.5 / small_radius );
159 exp_G_min = ( 1.0 / ( small_radius - big_radius ) * 1.0 / small_radius );
160 exp_G_max = ( 1.0 / ( big_radius + small_radius ) * 1.0 / small_radius );
162 else if ( input ==
"sphere" )
164 const double radius = 2.0;
165 smesh = SMH::makeSphere( radius,
RealPoint { 0.0, 0.0, 0.0 }, m, n,
166 SMH::NormalsType::VERTEX_NORMALS );
167 exp_H_min = 1.0 / radius;
168 exp_H_max = 1.0 / radius;
169 exp_G_min = 1.0 / ( radius * radius );
170 exp_G_max = 1.0 / ( radius * radius );
172 else if ( input ==
"lantern" )
174 const double radius = 2.0;
175 smesh = SMH::makeLantern( radius, 1.0,
RealPoint { 0.0, 0.0, 0.0 }, m, n,
176 SMH::NormalsType::VERTEX_NORMALS );
177 exp_H_min = 0.5 / radius;
178 exp_H_max = 0.5 / radius;
188 auto mu0 = cnc.computeMu0();
189 auto mu1 = cnc.computeMu1();
190 auto mu2 = cnc.computeMu2();
195 std::vector< double >
H( smesh.nbFaces() );
196 std::vector< double > G( smesh.nbFaces() );
197 for (
auto f = 0; f < smesh.nbFaces(); ++f )
199 const auto b = smesh.faceCentroid( f );
200 const auto area = mu0.measure( b, R, f );
201 H[ f ] = cnc.meanCurvature ( area, mu1.measure( b, R, f ) );
202 G[ f ] = cnc.GaussianCurvature( area, mu2.measure( b, R, f ) );
207 auto H_min_max = std::minmax_element(
H.cbegin(),
H.cend() );
208 auto G_min_max = std::minmax_element( G.cbegin(), G.cend() );
209 std::cout <<
"Expected mean curvatures:"
210 <<
" min=" << exp_H_min <<
" max=" << exp_H_max
212 std::cout <<
"Computed mean curvatures:"
213 <<
" min=" << *H_min_max.first <<
" max=" << *H_min_max.second
215 std::cout <<
"Expected Gaussian curvatures:"
216 <<
" min=" << exp_G_min <<
" max=" << exp_G_max
218 std::cout <<
"Computed Gaussian curvatures:"
219 <<
" min=" << *G_min_max.first <<
" max=" << *G_min_max.second
227 auto colorsH = SMW::Colors( smesh.nbFaces() );
228 auto colorsG = SMW::Colors( smesh.nbFaces() );
229 for (
auto i = 0; i < smesh.nbFaces(); i++ )
231 colorsH[ i ] = colormapH(
H[ i ] );
232 colorsG[ i ] = colormapG( G[ i ] );
234 SMW::writeOBJ(
"example-cnc-H", smesh, colorsH );
235 SMW::writeOBJ(
"example-cnc-G", smesh, colorsG );
Structure representing an RGB triple with alpha component.
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void addColor(const Color &color)
Aim: Implements basic operations that will be used in Point and Vector classes.
int main(int argc, char *argv[])
DGtal::GradientColorMap< double > makeColorMap(double min_value, double max_value)
[curvature-measures-Includes]
void usage(int argc, char *argv[])
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
QuantifiedColorMap< TColorMap > makeQuantifiedColorMap(TColorMap colormap, int nb=50)
Aim: Utility class to compute curvature measures induced by (1) a corrected normal current defined by...
Aim: An helper class for building classical meshes.
Aim: An helper class for writing mesh file formats (Waverfront OBJ at this point) and creating a Surf...
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...