120int main( 
int argc, 
char* argv[] )
 
  128  using namespace DGtal;
 
  136  std::string input = argv[ 1 ];
 
  137  const double    R = argc > 2 ? atof( argv[ 2 ] ) : 2.0; 
 
  138  const int       m = argc > 3 ? atoi( argv[ 3 ] ) : 0; 
 
  139  const int       M = argc > 4 ? atoi( argv[ 4 ] ) : 1; 
 
  140  const double Hmax = argc > 5 ? atof( argv[ 5 ] ) : 0.33; 
 
  141  const double Gmax = argc > 6 ? atof( argv[ 6 ] ) : 0.1; 
 
  145  auto params = SH::defaultParameters() | SHG::defaultParameters();
 
  146  params( 
"thresholdMin", m )( 
"thresholdMax", M )( 
"closed", 1);
 
  147  params( 
"t-ring", 3 )( 
"surfaceTraversal", 
"Default" );
 
  148  auto bimage = SH::makeBinaryImage( input.c_str(), params );
 
  149  if ( bimage == 
nullptr ) 
 
  151      trace.error() <<  
"Unable to read file <" << input.c_str() << 
">" << std::endl;
 
  154  auto K      = SH::getKSpace( bimage, params );
 
  155  auto sembedder   = SH::getSCellEmbedder( 
K );
 
  156  auto embedder    = SH::getCellEmbedder( 
K );
 
  157  auto surface     = SH::makeDigitalSurface( bimage, 
K, params );
 
  158  auto surfels     = SH::getSurfelRange( 
surface, params );
 
  159  trace.info() << 
"- surface has " << surfels.size()<< 
" surfels." << std::endl;
 
  164  std::vector< SM::Vertices > faces;
 
  166  auto pointels = SH::getPointelRange( c2i, 
surface );
 
  167  auto vertices = SH::RealPoints( pointels.size() );
 
  168  std::transform( pointels.cbegin(), pointels.cend(), vertices.begin(),
 
  169                  [&] (
const SH::Cell& c) { return embedder( c ); } ); 
 
  170  for ( 
auto&& surfel : *
surface )
 
  172      const auto primal_surfel_vtcs = SH::getPointelRange( 
K, surfel );
 
  174      for ( 
auto&& primal_vtx : primal_surfel_vtcs )
 
  175        face.push_back( c2i[ primal_vtx ] );
 
  176      faces.push_back( face );
 
  178  smesh.init( vertices.cbegin(), vertices.cend(),
 
  179              faces.cbegin(),    faces.cend() );
 
  180  trace.info() << smesh << std::endl;
 
  187  auto face_normals = SHG::getCTrivialNormalVectors( 
surface, surfels, params );
 
  188  smesh.setFaceNormals( face_normals.cbegin(), face_normals.cend() );
 
  192  std::cout << 
"Compute mu0" << std::endl;
 
  193  auto mu0 = cnc.computeMu0();
 
  194  std::cout << 
"Compute mu1" << std::endl;
 
  195  auto mu1 = cnc.computeMu1();
 
  196  std::cout << 
"Compute mu2" << std::endl;
 
  197  auto mu2 = cnc.computeMu2();
 
  202  std::vector< double > 
H( smesh.nbFaces() );
 
  203  std::vector< double > G( smesh.nbFaces() );
 
  204  for ( 
auto f = 0; f < smesh.nbFaces(); ++f )
 
  206      const auto b    = smesh.faceCentroid( f );
 
  207      const auto area = mu0.measure( b, R, f );
 
  208      H[ f ] = cnc.meanCurvature    ( area, mu1.measure( b, R, f ) );
 
  209      G[ f ] = cnc.GaussianCurvature( area, mu2.measure( b, R, f ) );
 
  214  auto H_min_max = std::minmax_element( 
H.cbegin(), 
H.cend() );
 
  215  auto G_min_max = std::minmax_element( G.cbegin(), G.cend() );
 
  216  std::cout << 
"Computed mean curvatures:" 
  217            << 
" min=" << *H_min_max.first << 
" max=" << *H_min_max.second
 
  219  std::cout << 
"Computed Gaussian curvatures:" 
  220            << 
" min=" << *G_min_max.first << 
" max=" << *G_min_max.second
 
  226  smesh.vertexNormals() = SH::RealVectors();
 
  227  smesh.faceNormals()   = SH::RealVectors();
 
  231  auto colorsH = SMW::Colors( smesh.nbFaces() );
 
  232  auto colorsG = SMW::Colors( smesh.nbFaces() );
 
  233  for ( 
auto i = 0; i < smesh.nbFaces(); i++ )
 
  235      colorsH[ i ] = colormapH( 
H[ i ] );
 
  236      colorsG[ i ] = colormapG( G[ i ] );
 
  238  SMW::writeOBJ( 
"example-cnc-H", smesh, colorsH );
 
  239  SMW::writeOBJ( 
"example-cnc-G", smesh, colorsG );