66 #include "DGtal/base/Common.h"
67 #include "DGtal/shapes/SurfaceMesh.h"
68 #include "DGtal/shapes/SurfaceMeshHelper.h"
70 #include "DGtal/geometry/meshes/CorrectedNormalCurrentComputer.h"
72 #include "DGtal/io/readers/SurfaceMeshReader.h"
73 #include "DGtal/io/writers/SurfaceMeshWriter.h"
74 #include "DGtal/io/colormaps/GradientColorMap.h"
75 #include "DGtal/io/colormaps/QuantifiedColorMap.h"
89 void usage(
int argc,
char* argv[] )
91 std::cout <<
"Usage: " << std::endl
92 <<
"\t" << argv[ 0 ] <<
" <filename.obj> <R> <Hmax> <Gmax>" << std::endl
94 <<
"Computation of mean and Gaussian curvatures on a mesh, " << std::endl
95 <<
"using interpolated corrected curvature measures (based " << std::endl
96 <<
"on the theory of corrected normal currents)." << std::endl
97 <<
"- builds the surface mesh from file <filename.obj>" << std::endl
98 <<
"- <R> is the radius of the measuring balls" << std::endl
99 <<
"- <Hmax> gives the colormap range [-Hmax,Hmax] for" << std::endl
100 <<
" the output of mean curvature estimates" << std::endl
101 <<
"- <Gmax> gives the colormap range [-Gmax,Gmax] for" << std::endl
102 <<
" the output of mean curvature estimates" << std::endl
103 <<
"It produces several OBJ files to display mean and" << std::endl
104 <<
"Gaussian curvature estimation results: `example-cnc-H.obj`" << std::endl
105 <<
"and `example-cnc-G.obj` as well as the associated MTL file." << std::endl;
108 int main(
int argc,
char* argv[] )
116 using namespace DGtal;
123 std::string input = argv[ 1 ];
124 const double R = argc > 2 ? atof( argv[ 2 ] ) : 0.0;
125 const double Hmax = argc > 3 ? atof( argv[ 3 ] ) : 5.0;
126 const double Gmax = argc > 4 ? atof( argv[ 4 ] ) : 0.5*Hmax*Hmax;
129 std::ifstream obj_stream( input.c_str() );
130 bool ok = SMR::readOBJ( obj_stream, smesh );
133 trace.
error() <<
"Unable to read file <" << input.c_str() <<
">" << std::endl;
138 for (
const auto& p : smesh.positions() )
139 lo = lo.
inf( p ), up = up.
sup( p );
140 const auto diameter = (up - lo).norm();
142 <<
" diameter=" << diameter
143 <<
" radius=" << R << std::endl;
150 if ( smesh.vertexNormals().empty() )
152 if ( smesh.faceNormals().empty() )
153 smesh.computeFaceNormalsFromPositions();
154 smesh.computeVertexNormalsFromFaceNormals();
157 auto mu0 = cnc.computeMu0();
158 auto mu1 = cnc.computeMu1();
159 auto mu2 = cnc.computeMu2();
164 std::vector< double >
H( smesh.nbFaces() );
165 std::vector< double > G( smesh.nbFaces() );
166 for (
auto f = 0; f < smesh.nbFaces(); ++f )
168 const auto b = smesh.faceCentroid( f );
169 const auto area = mu0.measure( b, R, f );
170 H[ f ] = cnc.meanCurvature ( area, mu1.measure( b, R, f ) );
171 G[ f ] = cnc.GaussianCurvature( area, mu2.measure( b, R, f ) );
176 auto H_min_max = std::minmax_element(
H.cbegin(),
H.cend() );
177 auto G_min_max = std::minmax_element( G.cbegin(), G.cend() );
178 std::cout <<
"Computed mean curvatures:"
179 <<
" min=" << *H_min_max.first <<
" max=" << *H_min_max.second
181 std::cout <<
"Computed Gaussian curvatures:"
182 <<
" min=" << *G_min_max.first <<
" max=" << *G_min_max.second
190 auto colorsH = SMW::Colors( smesh.nbFaces() );
191 auto colorsG = SMW::Colors( smesh.nbFaces() );
192 for (
auto i = 0; i < smesh.nbFaces(); i++ )
194 colorsH[ i ] = colormapH(
H[ i ] );
195 colorsG[ i ] = colormapG( G[ i ] );
197 SMW::writeOBJ(
"example-cnc-H", smesh, colorsH );
198 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.
auto inf(const PointVector< dim, OtherComponent, OtherStorage > &aPoint) const -> decltype(DGtal::inf(*this, aPoint))
Implements the infimum (or greatest lower bound).
auto sup(const PointVector< dim, OtherComponent, OtherStorage > &aPoint) const -> decltype(DGtal::sup(*this, aPoint))
Implements the supremum (or least upper bound).
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)
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[])
Aim: Utility class to compute curvature measures induced by (1) a corrected normal current defined by...
Aim: An helper class for reading mesh files (Wavefront OBJ at this point) and creating a SurfaceMesh.
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 ...