DGtal  1.5.beta
obj-curvature-measures-icnc-3d.cpp File Reference
#include <iostream>
#include <fstream>
#include <algorithm>
#include "DGtal/base/Common.h"
#include "DGtal/shapes/SurfaceMesh.h"
#include "DGtal/shapes/SurfaceMeshHelper.h"
#include "DGtal/geometry/meshes/CorrectedNormalCurrentComputer.h"
#include "DGtal/io/readers/SurfaceMeshReader.h"
#include "DGtal/io/writers/SurfaceMeshWriter.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/io/colormaps/QuantifiedColorMap.h"
Include dependency graph for obj-curvature-measures-icnc-3d.cpp:

Go to the source code of this file.

Functions

DGtal::GradientColorMap< double > makeColorMap (double min_value, double max_value)
 [curvature-measures-Includes] More...
 
void usage (int argc, char *argv[])
 
int main (int argc, char *argv[])
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2021/10/25

An example file named obj-curvature-measures-icnc-3d.

This file is part of the DGtal library.

Definition in file obj-curvature-measures-icnc-3d.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

[curvature-measures-Typedefs]

[curvature-measures-Typedefs]

[curvature-measures-SurfaceMesh]

[curvature-measures-SurfaceMesh]

[curvature-measures-CNC]

[curvature-measures-CNC]

[curvature-measures-estimations]

[curvature-measures-estimations]

[curvature-measures-check]

[curvature-measures-check]

[curvature-measures-output]

[curvature-measures-output]

Definition at line 108 of file obj-curvature-measures-icnc-3d.cpp.

109 {
110  if ( argc <= 1 )
111  {
112  usage( argc, argv );
113  return 0;
114  }
116  using namespace DGtal;
117  using namespace DGtal::Z3i;
122  // OBJ file
123  std::string input = argv[ 1 ];
124  const double R = argc > 2 ? atof( argv[ 2 ] ) : 0.0; // radius of measuring ball
125  const double Hmax = argc > 3 ? atof( argv[ 3 ] ) : 5.0; // range mean curvature colormap
126  const double Gmax = argc > 4 ? atof( argv[ 4 ] ) : 0.5*Hmax*Hmax; // range Gaussian curvature colormap
128  SM smesh;
129  std::ifstream obj_stream( input.c_str() );
130  bool ok = SMR::readOBJ( obj_stream, smesh );
131  if ( !ok )
132  {
133  trace.error() << "Unable to read file <" << input.c_str() << ">" << std::endl;
134  return 1;
135  }
136  RealPoint lo = smesh.position( 0 );
137  RealPoint up = smesh.position( 0 );
138  for ( const auto& p : smesh.positions() )
139  lo = lo.inf( p ), up = up.sup( p );
140  const auto diameter = (up - lo).norm();
141  trace.info() << "Mesh=" << smesh
142  << " diameter=" << diameter
143  << " radius=" << R << std::endl;
145 
147  // builds a CorrectedNormalCurrentComputer object onto the SurfaceMesh object
148  CNC cnc( smesh );
149  // computes normals if necessary
150  if ( smesh.vertexNormals().empty() )
151  {
152  if ( smesh.faceNormals().empty() )
153  smesh.computeFaceNormalsFromPositions();
154  smesh.computeVertexNormalsFromFaceNormals();
155  }
156  // computes area, mean and Gaussian curvature measures
157  auto mu0 = cnc.computeMu0();
158  auto mu1 = cnc.computeMu1();
159  auto mu2 = cnc.computeMu2();
161 
163  // estimates mean (H) and Gaussian (G) curvatures by measure normalization.
164  std::vector< double > H( smesh.nbFaces() );
165  std::vector< double > G( smesh.nbFaces() );
166  for ( auto f = 0; f < smesh.nbFaces(); ++f )
167  {
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 ) );
172  }
174 
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
180  << std::endl;
181  std::cout << "Computed Gaussian curvatures:"
182  << " min=" << *G_min_max.first << " max=" << *G_min_max.second
183  << std::endl;
185 
188  const auto colormapH = makeQuantifiedColorMap( makeColorMap( -Hmax, Hmax ) );
189  const auto colormapG = makeQuantifiedColorMap( makeColorMap( -Gmax, Gmax ) );
190  auto colorsH = SMW::Colors( smesh.nbFaces() );
191  auto colorsG = SMW::Colors( smesh.nbFaces() );
192  for ( auto i = 0; i < smesh.nbFaces(); i++ )
193  {
194  colorsH[ i ] = colormapH( H[ i ] );
195  colorsG[ i ] = colormapG( G[ i ] );
196  }
197  SMW::writeOBJ( "example-cnc-H", smesh, colorsH );
198  SMW::writeOBJ( "example-cnc-G", smesh, colorsG );
200  return 0;
201 }
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
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).
std::ostream & error()
std::ostream & info()
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)
Trace trace
Definition: Common.h:153
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 ...
Definition: SurfaceMesh.h:92

References DGtal::Trace::error(), DGtal::H, DGtal::PointVector< dim, TEuclideanRing, TContainer >::inf(), DGtal::Trace::info(), makeColorMap(), DGtal::makeQuantifiedColorMap(), DGtal::PointVector< dim, TEuclideanRing, TContainer >::sup(), DGtal::trace, and usage().

◆ makeColorMap()

DGtal::GradientColorMap< double > makeColorMap ( double  min_value,
double  max_value 
)

[curvature-measures-Includes]

[curvature-measures-Includes]

Definition at line 78 of file obj-curvature-measures-icnc-3d.cpp.

79 {
80  DGtal::GradientColorMap< double > gradcmap( min_value, max_value );
81  gradcmap.addColor( DGtal::Color( 0, 0, 255 ) );
82  gradcmap.addColor( DGtal::Color( 0, 255, 255 ) );
83  gradcmap.addColor( DGtal::Color( 255, 255, 255 ) );
84  gradcmap.addColor( DGtal::Color( 255, 255, 0 ) );
85  gradcmap.addColor( DGtal::Color( 255, 0, 0 ) );
86  return gradcmap;
87 }
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...

References DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::addColor().

Referenced by main().

◆ usage()

void usage ( int  argc,
char *  argv[] 
)

Definition at line 89 of file obj-curvature-measures-icnc-3d.cpp.

90 {
91  std::cout << "Usage: " << std::endl
92  << "\t" << argv[ 0 ] << " <filename.obj> <R> <Hmax> <Gmax>" << std::endl
93  << 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;
106 }

Referenced by main().