Computation of mean and Gaussian curvatures on a mesh defined by a an implicit shape discretized as a digital surface, using Integral Invariant (II) method or constant (CCNC) or interpolated corrected curvature measures (ICNC) (based on the theory of corrected normal currents). For CCNC and ICNC, we use also II normal vector estimations. Timings and errors with respect to true expected curvatures are computed.
This first example compares II with CCNC for estimating curvatures on "goursat" polynomial, for gridstep 0.25
This second example compares II with ICNC for estimating curvatures on "goursat" polynomial, for gridstep 0.25
#include <iostream>
#include <fstream>
#include <algorithm>
#include "DGtal/base/Common.h"
#include "DGtal/shapes/SurfaceMesh.h"
#include "DGtal/geometry/meshes/CorrectedNormalCurrentComputer.h"
#include "DGtal/helpers/Shortcuts.h"
#include "DGtal/helpers/ShortcutsGeometry.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 ] << " <P> <B> <h> <mode>" << std::endl
<< std::endl
<< "Compare Integral Invariant (II) curvature estimations " << std::endl
<< "with Corrected Normal Current (CNC) estimations, either "<< std::endl
<< "interpolated (Interp) or constant per face (Const)." << std::endl
<< "- builds the surface mesh from polynomial <P>" << std::endl
<< "- <B> defines the digitization space size [-B,B]^3" << std::endl
<< "- <h> is the gridstep digitization" << std::endl
<< "- <mode> is either Const for constant corrected normal" << std::endl
<< " vector field or Interp for interpolated corrected" << std::endl
<< " normal vector field." << std::endl
<< "It outputs timings and accuracy statistics for both " << std::endl
<< "methods." << std::endl;
std::cout << "You may either write your own polynomial as 3*x^2-z^2*x*y+1" << std::endl
<<"or use a predefined polynomial in the following list:" << std::endl;
auto L = SH::getPolynomialList();
for ( const auto& p : L )
std::cout << p.first <<
" : " << p.second <<
std::endl;
}
int main(
int argc,
char* argv[] )
{
if ( argc <= 1 )
{
usage( argc, argv );
return 0;
}
std::string poly = argv[ 1 ];
const double B = argc > 2 ? atof( argv[ 2 ] ) : 1.0;
const double h = argc > 3 ? atof( argv[ 3 ] ) : 1.0;
std::string mode = argc > 4 ? argv[ 4 ] : "Const";
bool interpolated = mode == "Interp";
if ( interpolated )
trace.
info() <<
"Using vertex-*Interpolated* Corrected Normal Current" << std::endl;
else
trace.
info() <<
"Using face-*Constant* Corrected Normal Current" << std::endl;
auto params = SH::defaultParameters() | SHG::defaultParameters();
params( "surfaceTraversal", "DepthFirst" );
params( "t-ring", 3 );
params( "polynomial", poly )( "gridstep", h );
params( "minAABB", -B )( "maxAABB", B );
params( "offset", 3.0 );
auto shape = SH::makeImplicitShape3D( params );
auto K = SH::getKSpace( params );
auto dshape = SH::makeDigitizedImplicitShape3D( shape, params );
auto bimage = SH::makeBinaryImage( dshape, params );
if ( bimage == nullptr )
{
<< poly.c_str() << ">" << std::endl;
return 1;
}
auto sembedder = SH::getSCellEmbedder(
K );
auto embedder = SH::getCellEmbedder(
K );
auto surface = SH::makeDigitalSurface( bimage,
K, params );
auto surfels = SH::getSurfelRange(
surface, params );
trace.
info() <<
"- surface has " << surfels.size()<<
" surfels." << std::endl;
params( "r-radius", 3.0 );
params( "alpha", 0.33 );
double ii_r = 3.0 * pow( h, 0.33 );
std::vector< double > HII = SHG::getIIMeanCurvatures ( bimage, surfels, params );
std::vector< double > GII = SHG::getIIGaussianCurvatures( bimage, surfels, params );
SM smesh;
std::vector< SM::Vertices > faces;
SH::Cell2Index c2i;
auto pointels = SH::getPointelRange( c2i,
surface );
auto vertices = SH::RealPoints( pointels.size() );
std::transform( pointels.cbegin(), pointels.cend(),
vertices.begin(),
[&] (const SH::Cell& c) { return h * embedder( c ); } );
for ( auto&& surfel : surfels )
{
const auto primal_surfel_vtcs = SH::getPointelRange(
K, surfel );
SM::Vertices face;
for ( auto&& primal_vtx : primal_surfel_vtcs )
face.push_back( c2i[ primal_vtx ] );
faces.push_back( face );
}
faces.cbegin(), faces.cend() );
auto exp_H = SHG::getMeanCurvatures( shape,
K, surfels, params );
auto exp_G = SHG::getGaussianCurvatures( shape,
K, surfels, params );
CNC cnc( smesh );
auto face_normals = SHG::getIINormalVectors( bimage, surfels, params );
smesh.setFaceNormals( face_normals.cbegin(), face_normals.cend() );
if ( interpolated ) smesh.computeVertexNormalsFromFaceNormals();
auto mu0 = cnc.computeMu0();
auto mu1 = cnc.computeMu1();
auto mu2 = cnc.computeMu2();
double cnc_mr = 1.0 * sqrt( h );
trace.
info() <<
"CNC measuring radius = " << cnc_mr << std::endl;
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, cnc_mr, f );
H[ f ] = cnc.meanCurvature ( area, mu1.measure( b, cnc_mr, f ) );
G[ f ] = cnc.GaussianCurvature( area, mu2.measure( b, cnc_mr, f ) );
}
auto HII_min_max = std::minmax_element( HII.cbegin(), HII.cend() );
auto GII_min_max = std::minmax_element( GII.cbegin(), GII.cend() );
auto H_min_max = std::minmax_element(
H.cbegin(),
H.cend() );
auto G_min_max = std::minmax_element( G.cbegin(), G.cend() );
auto exp_H_min_max = std::minmax_element( exp_H.cbegin(), exp_H.cend() );
auto exp_G_min_max = std::minmax_element( exp_G.cbegin(), exp_G.cend() );
<< " min=" << *exp_H_min_max.first << " max=" << *exp_H_min_max.second
<< std::endl;
trace.
info() <<
"Computed II mean curvatures:"
<< " min=" << *HII_min_max.first << " max=" << *HII_min_max.second
<< std::endl;
trace.
info() <<
"Computed CNC mean curvatures:"
<< " min=" << *H_min_max.first << " max=" << *H_min_max.second
<< std::endl;
trace.
info() <<
"Expected Gaussian curvatures:"
<< " min=" << *exp_G_min_max.first << " max=" << *exp_G_min_max.second
<< std::endl;
trace.
info() <<
"Computed II Gaussian curvatures:"
<< " min=" << *GII_min_max.first << " max=" << *GII_min_max.second
<< std::endl;
trace.
info() <<
"Computed CNC Gaussian curvatures:"
<< " min=" << *G_min_max.first << " max=" << *G_min_max.second
<< std::endl;
const auto error_HII = SHG::getScalarsAbsoluteDifference( HII, exp_H );
const auto stat_error_HII = SHG::getStatistic( error_HII );
const auto error_HII_l2 = SHG::getScalarsNormL2( HII, exp_H );
trace.
info() <<
"|H-H_II|_oo = " << stat_error_HII.max() << std::endl;
trace.
info() <<
"|H-H_II|_2 = " << error_HII_l2 << std::endl;
const auto error_H = SHG::getScalarsAbsoluteDifference( H, exp_H );
const auto stat_error_H = SHG::getStatistic( error_H );
const auto error_H_l2 = SHG::getScalarsNormL2( H, exp_H );
trace.
info() <<
"|H-H_CNC|_oo = " << stat_error_H.max() << std::endl;
trace.
info() <<
"|H-H_CNC|_2 = " << error_H_l2 << std::endl;
const auto error_GII = SHG::getScalarsAbsoluteDifference( GII, exp_G );
const auto stat_error_GII = SHG::getStatistic( error_GII );
const auto error_GII_l2 = SHG::getScalarsNormL2( GII, exp_G );
trace.
info() <<
"|G-G_II|_oo = " << stat_error_GII.max() << std::endl;
trace.
info() <<
"|G-G_II|_2 = " << error_GII_l2 << std::endl;
const auto error_G = SHG::getScalarsAbsoluteDifference( G, exp_G );
const auto stat_error_G = SHG::getStatistic( error_G );
const auto error_G_l2 = SHG::getScalarsNormL2( G, exp_G );
trace.
info() <<
"|G-G_CNC|_oo = " << stat_error_G.max() << std::endl;
trace.
info() <<
"|G-G_CNC|_2 = " << error_G_l2 << std::endl;
std::cout << "# " << argv[ 0 ] << std::endl
<< "# polynomial: " << poly << std::endl
<< "# CNC mode: " << mode << std::endl;
std::cout << "# h nb_surfels ii_t ii_r ii_Hoo ii_H2 ii_Goo ii_G2 ";
std::cout << "cnc_tn cnc_t cnc_mr cnc_Hoo cnc_H2 cnc_Goo cnc_G2" << std::endl;
std::cout << h << " " << surfels.size() << " " << ii_t << " " << ii_r
<< " " << stat_error_HII.max() << " " << error_HII_l2
<< " " << stat_error_GII.max() << " " << error_GII_l2
<< " " << cnc_tn << " " << cnc_t << " " << cnc_mr
<< " " << stat_error_H.max() << " " << error_H_l2
<< " " << stat_error_G.max() << " " << error_G_l2 << std::endl;
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)
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
void beginBlock(const std::string &keyword="")
DGtal::GradientColorMap< double > makeColorMap(double min_value, double max_value)
[curvature-comparator-Includes]
CountedPtr< SH3::DigitalSurface > surface
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator > vertices(const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
Aim: Utility class to compute curvature measures induced by (1) a corrected normal current defined by...
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...