82#include "DGtal/base/Common.h"
83#include "DGtal/shapes/SurfaceMesh.h"
84#include "DGtal/shapes/SurfaceMeshHelper.h"
86#include "DGtal/geometry/meshes/NormalCycleComputer.h"
88#include "DGtal/io/writers/SurfaceMeshWriter.h"
89#include "DGtal/io/colormaps/GradientColorMap.h"
90#include "DGtal/io/colormaps/QuantifiedColorMap.h"
104void usage(
int argc,
char* argv[] )
106 std::cout <<
"Usage: " << std::endl
107 <<
"\t" << argv[ 0 ] <<
" <shape> <m> <n> <R>" << std::endl
109 <<
"Computation of mean and Gaussian curvatures on a shape, " << std::endl
110 <<
"using Normal cycle curvature measures (based on the" << std::endl
111 <<
"theory of Normal cycle)" << std::endl
112 <<
"- builds a <shape> in {torus,lantern,sphere}, with " << std::endl
113 <<
" <m> latitude points and <n> longitude points." << std::endl
114 <<
"- <R> is the radius of the measuring balls." << std::endl
115 <<
"It produces several OBJ files to display mean and" << std::endl
116 <<
"Gaussian curvature estimation results: `example-cnc-H.obj`" << std::endl
117 <<
"and `example-cnc-G.obj` as well as the associated MTL file." << std::endl;
120int main(
int argc,
char* argv[] )
128 using namespace DGtal;
134 std::string input = argv[ 1 ];
135 int m = argc > 2 ? atoi( argv[ 2 ] ) : 20;
136 int n = argc > 3 ? atoi( argv[ 3 ] ) : 20;
137 double R = argc > 4 ? atof( argv[ 4 ] ) : 0.5;
141 double exp_H_min = 0.0;
142 double exp_H_max = 0.0;
143 double exp_G_min = 0.0;
144 double exp_G_max = 0.0;
145 if ( input ==
"torus" )
147 const double big_radius = 3.0;
148 const double small_radius = 1.0;
149 smesh = SMH::makeTorus( big_radius, small_radius,
151 SMH::NormalsType::VERTEX_NORMALS );
152 exp_H_min = ( 0.5 / ( small_radius - big_radius ) + 0.5 / small_radius );
153 exp_H_max = ( 0.5 / ( big_radius + small_radius ) + 0.5 / small_radius );
154 exp_G_min = ( 1.0 / ( small_radius - big_radius ) * 1.0 / small_radius );
155 exp_G_max = ( 1.0 / ( big_radius + small_radius ) * 1.0 / small_radius );
157 else if ( input ==
"sphere" )
159 const double radius = 2.0;
160 smesh = SMH::makeSphere( radius,
RealPoint { 0.0, 0.0, 0.0 }, m, n,
161 SMH::NormalsType::VERTEX_NORMALS );
162 exp_H_min = 1.0 / radius;
163 exp_H_max = 1.0 / radius;
164 exp_G_min = 1.0 / ( radius * radius );
165 exp_G_max = 1.0 / ( radius * radius );
167 else if ( input ==
"lantern" )
169 const double radius = 2.0;
170 smesh = SMH::makeLantern( radius, 1.0,
RealPoint { 0.0, 0.0, 0.0 }, m, n,
171 SMH::NormalsType::VERTEX_NORMALS );
172 exp_H_min = 0.5 / radius;
173 exp_H_max = 0.5 / radius;
183 auto mu0 = nc.computeMu0();
184 auto mu1 = nc.computeMu1();
185 auto mu2 = nc.computeMu2();
190 std::vector< double > H( smesh.nbFaces() );
191 std::vector< double > G( smesh.nbFaces() );
192 for (
auto f = 0; f < smesh.nbFaces(); ++f )
194 const auto b = smesh.faceCentroid( f );
195 const auto area = mu0.measure( b, R, f );
196 H[ f ] = nc.meanCurvature ( area, mu1.measure( b, R, f ) );
197 G[ f ] = nc.GaussianCurvature( area, mu2.measure( b, R, f ) );
202 auto H_min_max = std::minmax_element( H.cbegin(), H.cend() );
203 auto G_min_max = std::minmax_element( G.cbegin(), G.cend() );
204 std::cout <<
"Expected mean curvatures:"
205 <<
" min=" << exp_H_min <<
" max=" << exp_H_max
207 std::cout <<
"Computed mean curvatures:"
208 <<
" min=" << *H_min_max.first <<
" max=" << *H_min_max.second
210 std::cout <<
"Expected Gaussian curvatures:"
211 <<
" min=" << exp_G_min <<
" max=" << exp_G_max
213 std::cout <<
"Computed Gaussian curvatures:"
214 <<
" min=" << *G_min_max.first <<
" max=" << *G_min_max.second
220 const auto colormapH = makeQuantifiedColorMap(
makeColorMap( -0.625, 0.625 ) );
221 const auto colormapG = makeQuantifiedColorMap(
makeColorMap( -0.625, 0.625 ) );
222 auto colorsH = SMW::Colors( smesh.nbFaces() );
223 auto colorsG = SMW::Colors( smesh.nbFaces() );
224 for (
auto i = 0; i < smesh.nbFaces(); i++ )
226 colorsH[ i ] = colormapH( H[ i ] );
227 colorsG[ i ] = colormapG( G[ i ] );
229 SMW::writeOBJ(
"example-nc-H", smesh, colorsH );
230 SMW::writeOBJ(
"example-nc-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)
DGtal::GradientColorMap< double > makeColorMap(double min_value, double max_value)
[curvature-measures-Includes]
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: Utility class to compute curvatures measures induced by (1) the normal cycle induced by a Surfac...
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 ...