Computation of curvatures on a torus mesh, using Normal cycle curvature measures (based on the theory of Normal cycle)
#include <iostream>
#include <algorithm>
#include "DGtal/base/Common.h"
#include "DGtal/shapes/SurfaceMesh.h"
#include "DGtal/shapes/SurfaceMeshHelper.h"
#include "DGtal/geometry/meshes/NormalCycleComputer.h"
#include "DGtal/io/writers/SurfaceMeshWriter.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/io/colormaps/QuantifiedColorMap.h"
{
return gradcmap;
}
void usage( int argc, char* argv[] )
{
std::cout << "Usage: " << std::endl
<< "\t" << argv[ 0 ] << " <shape> <m> <n> <R>" << std::endl
<< std::endl
<< "Computation of mean and Gaussian curvatures on a shape, " << std::endl
<< "using Normal cycle curvature measures (based on the" << std::endl
<< "theory of Normal cycle)" << std::endl
<< "- builds a <shape> in {torus,lantern,sphere}, with " << std::endl
<< " <m> latitude points and <n> longitude points." << std::endl
<< "- <R> is the radius of the measuring balls." << std::endl
<< "It produces several OBJ files to display mean and" << std::endl
<< "Gaussian curvature estimation results: `example-cnc-H.obj`" << std::endl
<< "and `example-cnc-G.obj` as well as the associated MTL file." << std::endl;
}
int main(
int argc,
char* argv[] )
{
if ( argc <= 1 )
{
usage( argc, argv );
return 0;
}
std::string input = argv[ 1 ];
int m = argc > 2 ? atoi( argv[ 2 ] ) : 20;
int n = argc > 3 ? atoi( argv[ 3 ] ) : 20;
double R = argc > 4 ? atof( argv[ 4 ] ) : 0.5;
SM smesh;
double exp_H_min = 0.0;
double exp_H_max = 0.0;
double exp_G_min = 0.0;
double exp_G_max = 0.0;
if ( input == "torus" )
{
const double big_radius = 3.0;
const double small_radius = 1.0;
smesh = SMH::makeTorus( big_radius, small_radius,
SMH::NormalsType::VERTEX_NORMALS );
exp_H_min = ( 0.5 / ( small_radius - big_radius ) + 0.5 / small_radius );
exp_H_max = ( 0.5 / ( big_radius + small_radius ) + 0.5 / small_radius );
exp_G_min = ( 1.0 / ( small_radius - big_radius ) * 1.0 / small_radius );
exp_G_max = ( 1.0 / ( big_radius + small_radius ) * 1.0 / small_radius );
}
else if ( input == "sphere" )
{
const double radius = 2.0;
smesh = SMH::makeSphere( radius,
RealPoint { 0.0, 0.0, 0.0 }, m, n,
SMH::NormalsType::VERTEX_NORMALS );
exp_H_min = 1.0 / radius;
exp_H_max = 1.0 / radius;
exp_G_min = 1.0 / ( radius * radius );
exp_G_max = 1.0 / ( radius * radius );
}
else if ( input == "lantern" )
{
const double radius = 2.0;
smesh = SMH::makeLantern( radius, 1.0,
RealPoint { 0.0, 0.0, 0.0 }, m, n,
SMH::NormalsType::VERTEX_NORMALS );
exp_H_min = 0.5 / radius;
exp_H_max = 0.5 / radius;
exp_G_min = 0.0;
exp_G_max = 0.0;
}
NC nc( smesh );
auto mu0 = nc.computeMu0();
auto mu1 = nc.computeMu1();
auto mu2 = nc.computeMu2();
std::vector< double >
H( smesh.nbFaces() );
std::vector< double > G( smesh.nbFaces() );
for ( auto f = 0; f < smesh.nbFaces(); ++f )
{
const auto b = smesh.faceCentroid( f );
const auto area = mu0.measure( b, R, f );
H[ f ] = nc.meanCurvature ( area, mu1.measure( b, R, f ) );
G[ f ] = nc.GaussianCurvature( area, mu2.measure( b, R, f ) );
}
auto H_min_max = std::minmax_element(
H.cbegin(),
H.cend() );
auto G_min_max = std::minmax_element( G.cbegin(), G.cend() );
std::cout << "Expected mean curvatures:"
<< " min=" << exp_H_min << " max=" << exp_H_max
<< std::endl;
std::cout << "Computed mean curvatures:"
<< " min=" << *H_min_max.first << " max=" << *H_min_max.second
<< std::endl;
std::cout << "Expected Gaussian curvatures:"
<< " min=" << exp_G_min << " max=" << exp_G_max
<< std::endl;
std::cout << "Computed Gaussian curvatures:"
<< " min=" << *G_min_max.first << " max=" << *G_min_max.second
<< std::endl;
auto colorsH = SMW::Colors( smesh.nbFaces() );
auto colorsG = SMW::Colors( smesh.nbFaces() );
for ( auto i = 0; i < smesh.nbFaces(); i++ )
{
colorsH[ i ] = colormapH( H[ i ] );
colorsG[ i ] = colormapG( G[ i ] );
}
SMW::writeOBJ( "example-nc-H", smesh, colorsH );
SMW::writeOBJ( "example-nc-G", smesh, colorsG );
return 0;
}
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-comparator-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.
QuantifiedColorMap< TColorMap > makeQuantifiedColorMap(TColorMap colormap, int nb=50)
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 ...