DGtal 1.3.0
Loading...
Searching...
No Matches
geometry/meshes/curvature-measures-nc-3d.cpp

Computation of curvatures on a torus mesh, using Normal cycle curvature measures (based on the theory of Normal cycle)

./examples/geometry/meshes/curvature-measures-nc-3d torus 20 20 0.5 

outputs

Expected mean curvatures: min=0.25 max=0.625
Computed mean curvatures: min=0.189446 max=0.772277
Expected Gaussian curvatures: min=-0.5 max=0.25
Computed Gaussian curvatures: min=-0.682996 max=0.547296

It also produces several OBJ files to display curvature estimation results, example-nc-H.obj and example-nc-G.obj as well as the associated MTL file.

Warning
Normal cycle curvature estimation have meaning only for a big enough radius to capture edge/vertex information. This is in opposition with interpolated corrected curvature measures.
Normal cycle mean curvature measure, r=0.5
Normal cycle Gaussian curvature measure, r=0.5
See also
Curvature measures on meshes and digital surfaces
Note
Normal cycle theory fails on bad sampling of smooth surfaces. A well known example is the Schwarz lantern. You may try the following:
./examples/geometry/meshes/curvature-measures-nc-3d lantern 20 20 0.5

outputs

Expected mean curvatures: min=0.25 max=0.25
Computed mean curvatures: min=0.795695 max=1.41211
Expected Gaussian curvatures: min=0 max=0
Computed Gaussian curvatures: min=-6.79045e-14 max=15.0937
#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"
makeColorMap( double min_value, double max_value )
{
DGtal::GradientColorMap< double > gradcmap( min_value, max_value );
gradcmap.addColor( DGtal::Color( 0, 0, 255 ) );
gradcmap.addColor( DGtal::Color( 0, 255, 255 ) );
gradcmap.addColor( DGtal::Color( 255, 255, 255 ) );
gradcmap.addColor( DGtal::Color( 255, 255, 0 ) );
gradcmap.addColor( DGtal::Color( 255, 0, 0 ) );
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;
}
using namespace DGtal;
using namespace DGtal::Z3i;
std::string input = argv[ 1 ];
int m = argc > 2 ? atoi( argv[ 2 ] ) : 20; // nb latitude points
int n = argc > 3 ? atoi( argv[ 3 ] ) : 20; // nb longitude points
double R = argc > 4 ? atof( argv[ 4 ] ) : 0.5; // radius of measuring ball
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,
RealPoint { 0.0, 0.0, 0.0 }, m, n, 0,
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;
}
// builds a NormalCycleComputer object onto the mesh
NC nc( smesh );
// computes area, mean and Gaussian curvature measures
auto mu0 = nc.computeMu0();
auto mu1 = nc.computeMu1();
auto mu2 = nc.computeMu2();
// estimates mean (H) and Gaussian (G) curvatures by measure normalization.
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;
const auto colormapH = makeQuantifiedColorMap( makeColorMap( -0.625, 0.625 ) );
const auto colormapG = makeQuantifiedColorMap( makeColorMap( -0.625, 0.625 ) );
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.
Definition: Color.h:68
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 ...
Definition: SurfaceMesh.h:92
Z2i::RealPoint RealPoint
int main()
Definition: testBits.cpp:56