DGtal  1.4.beta
curvature-measures-icnc-3d.cpp File Reference
#include <iostream>
#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/writers/SurfaceMeshWriter.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/io/colormaps/QuantifiedColorMap.h"
Include dependency graph for 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 curvature-measures-icnc-3d.

This file is part of the DGtal library.

Definition in file 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 124 of file curvature-measures-icnc-3d.cpp.

125 {
126  if ( argc <= 1 )
127  {
128  usage( argc, argv );
129  return 0;
130  }
132  using namespace DGtal;
133  using namespace DGtal::Z3i;
138  // a shape in "torus|lantern|sphere"
139  std::string input = argv[ 1 ];
140  int m = argc > 2 ? atoi( argv[ 2 ] ) : 20; // nb latitude points
141  int n = argc > 3 ? atoi( argv[ 3 ] ) : 20; // nb longitude points
142  double R = argc > 4 ? atof( argv[ 4 ] ) : 0.5; // radius of measuring ball
143 
145  SM smesh;
146  double exp_H_min = 0.0;
147  double exp_H_max = 0.0;
148  double exp_G_min = 0.0;
149  double exp_G_max = 0.0;
150  if ( input == "torus" )
151  {
152  const double big_radius = 3.0;
153  const double small_radius = 1.0;
154  smesh = SMH::makeTorus( big_radius, small_radius,
155  RealPoint { 0.0, 0.0, 0.0 }, m, n, 0,
156  SMH::NormalsType::VERTEX_NORMALS );
157  exp_H_min = ( 0.5 / ( small_radius - big_radius ) + 0.5 / small_radius );
158  exp_H_max = ( 0.5 / ( big_radius + small_radius ) + 0.5 / small_radius );
159  exp_G_min = ( 1.0 / ( small_radius - big_radius ) * 1.0 / small_radius );
160  exp_G_max = ( 1.0 / ( big_radius + small_radius ) * 1.0 / small_radius );
161  }
162  else if ( input == "sphere" )
163  {
164  const double radius = 2.0;
165  smesh = SMH::makeSphere( radius, RealPoint { 0.0, 0.0, 0.0 }, m, n,
166  SMH::NormalsType::VERTEX_NORMALS );
167  exp_H_min = 1.0 / radius;
168  exp_H_max = 1.0 / radius;
169  exp_G_min = 1.0 / ( radius * radius );
170  exp_G_max = 1.0 / ( radius * radius );
171  }
172  else if ( input == "lantern" )
173  {
174  const double radius = 2.0;
175  smesh = SMH::makeLantern( radius, 1.0, RealPoint { 0.0, 0.0, 0.0 }, m, n,
176  SMH::NormalsType::VERTEX_NORMALS );
177  exp_H_min = 0.5 / radius;
178  exp_H_max = 0.5 / radius;
179  exp_G_min = 0.0;
180  exp_G_max = 0.0;
181  }
183 
185  // builds a CorrectedNormalCurrentComputer object onto the torus/lantern/sphere mesh
186  CNC cnc( smesh );
187  // computes area, mean and Gaussian curvature measures
188  auto mu0 = cnc.computeMu0();
189  auto mu1 = cnc.computeMu1();
190  auto mu2 = cnc.computeMu2();
192 
194  // estimates mean (H) and Gaussian (G) curvatures by measure normalization.
195  std::vector< double > H( smesh.nbFaces() );
196  std::vector< double > G( smesh.nbFaces() );
197  for ( auto f = 0; f < smesh.nbFaces(); ++f )
198  {
199  const auto b = smesh.faceCentroid( f );
200  const auto area = mu0.measure( b, R, f );
201  H[ f ] = cnc.meanCurvature ( area, mu1.measure( b, R, f ) );
202  G[ f ] = cnc.GaussianCurvature( area, mu2.measure( b, R, f ) );
203  }
205 
207  auto H_min_max = std::minmax_element( H.cbegin(), H.cend() );
208  auto G_min_max = std::minmax_element( G.cbegin(), G.cend() );
209  std::cout << "Expected mean curvatures:"
210  << " min=" << exp_H_min << " max=" << exp_H_max
211  << std::endl;
212  std::cout << "Computed mean curvatures:"
213  << " min=" << *H_min_max.first << " max=" << *H_min_max.second
214  << std::endl;
215  std::cout << "Expected Gaussian curvatures:"
216  << " min=" << exp_G_min << " max=" << exp_G_max
217  << std::endl;
218  std::cout << "Computed Gaussian curvatures:"
219  << " min=" << *G_min_max.first << " max=" << *G_min_max.second
220  << std::endl;
222 
225  const auto colormapH = makeQuantifiedColorMap( makeColorMap( -0.625, 0.625 ) );
226  const auto colormapG = makeQuantifiedColorMap( makeColorMap( -0.625, 0.625 ) );
227  auto colorsH = SMW::Colors( smesh.nbFaces() );
228  auto colorsG = SMW::Colors( smesh.nbFaces() );
229  for ( auto i = 0; i < smesh.nbFaces(); i++ )
230  {
231  colorsH[ i ] = colormapH( H[ i ] );
232  colorsG[ i ] = colormapG( G[ i ] );
233  }
234  SMW::writeOBJ( "example-cnc-H", smesh, colorsH );
235  SMW::writeOBJ( "example-cnc-G", smesh, colorsG );
237  return 0;
238 }
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
DGtal::GradientColorMap< double > makeColorMap(double min_value, double max_value)
[curvature-measures-Includes]
void usage(int argc, char *argv[])
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 curvature measures induced by (1) a corrected normal current defined by...
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

References DGtal::H, makeColorMap(), DGtal::makeQuantifiedColorMap(), and usage().

◆ makeColorMap()

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

[curvature-measures-Includes]

[curvature-measures-Includes]

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

98 {
99  DGtal::GradientColorMap< double > gradcmap( min_value, max_value );
100  gradcmap.addColor( DGtal::Color( 0, 0, 255 ) );
101  gradcmap.addColor( DGtal::Color( 0, 255, 255 ) );
102  gradcmap.addColor( DGtal::Color( 255, 255, 255 ) );
103  gradcmap.addColor( DGtal::Color( 255, 255, 0 ) );
104  gradcmap.addColor( DGtal::Color( 255, 0, 0 ) );
105  return gradcmap;
106 }
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 108 of file curvature-measures-icnc-3d.cpp.

109 {
110  std::cout << "Usage: " << std::endl
111  << "\t" << argv[ 0 ] << " <shape> <m> <n> <R>" << std::endl
112  << std::endl
113  << "Computation of mean and Gaussian curvatures on a shape, " << std::endl
114  << "using interpolated corrected curvature measures (based " << std::endl
115  << "on the theory of corrected normal currents)." << std::endl
116  << "- builds a <shape> in {torus,lantern,sphere}, with " << std::endl
117  << " <m> latitude points and <n> longitude points." << std::endl
118  << "- <R> is the radius of the measuring balls." << std::endl
119  << "It produces several OBJ files to display mean and" << std::endl
120  << "Gaussian curvature estimation results: `example-cnc-H.obj`" << std::endl
121  << "and `example-cnc-G.obj` as well as the associated MTL file." << std::endl;
122 }

Referenced by main().