DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
curvature-measures-nc-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/NormalCycleComputer.h"
#include "DGtal/io/writers/SurfaceMeshWriter.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/io/colormaps/QuantifiedColorMap.h"

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-nc-3d.

This file is part of the DGtal library.

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

121{
122 if ( argc <= 1 )
123 {
124 usage( argc, argv );
125 return 0;
126 }
128 using namespace DGtal;
129 using namespace DGtal::Z3i;
134 std::string input = argv[ 1 ];
135 int m = argc > 2 ? atoi( argv[ 2 ] ) : 20; // nb latitude points
136 int n = argc > 3 ? atoi( argv[ 3 ] ) : 20; // nb longitude points
137 double R = argc > 4 ? atof( argv[ 4 ] ) : 0.5; // radius of measuring ball
138
140 SM smesh;
141 double exp_H_min = 0.0;
142 double exp_H_max = 0.0;
143 double exp_G_min = 0.0;
144 double exp_G_max = 0.0;
145 if ( input == "torus" )
146 {
147 const double big_radius = 3.0;
148 const double small_radius = 1.0;
149 smesh = SMH::makeTorus( big_radius, small_radius,
150 RealPoint { 0.0, 0.0, 0.0 }, m, n, 0,
151 SMH::NormalsType::VERTEX_NORMALS );
152 exp_H_min = ( 0.5 / ( small_radius - big_radius ) + 0.5 / small_radius );
153 exp_H_max = ( 0.5 / ( big_radius + small_radius ) + 0.5 / small_radius );
154 exp_G_min = ( 1.0 / ( small_radius - big_radius ) * 1.0 / small_radius );
155 exp_G_max = ( 1.0 / ( big_radius + small_radius ) * 1.0 / small_radius );
156 }
157 else if ( input == "sphere" )
158 {
159 const double radius = 2.0;
160 smesh = SMH::makeSphere( radius, RealPoint { 0.0, 0.0, 0.0 }, m, n,
161 SMH::NormalsType::VERTEX_NORMALS );
162 exp_H_min = 1.0 / radius;
163 exp_H_max = 1.0 / radius;
164 exp_G_min = 1.0 / ( radius * radius );
165 exp_G_max = 1.0 / ( radius * radius );
166 }
167 else if ( input == "lantern" )
168 {
169 const double radius = 2.0;
170 smesh = SMH::makeLantern( radius, 1.0, RealPoint { 0.0, 0.0, 0.0 }, m, n,
171 SMH::NormalsType::VERTEX_NORMALS );
172 exp_H_min = 0.5 / radius;
173 exp_H_max = 0.5 / radius;
174 exp_G_min = 0.0;
175 exp_G_max = 0.0;
176 }
178
180 // builds a NormalCycleComputer object onto the mesh
181 NC nc( smesh );
182 // computes area, mean and Gaussian curvature measures
183 auto mu0 = nc.computeMu0();
184 auto mu1 = nc.computeMu1();
185 auto mu2 = nc.computeMu2();
187
189 // estimates mean (H) and Gaussian (G) curvatures by measure normalization.
190 std::vector< double > H( smesh.nbFaces() );
191 std::vector< double > G( smesh.nbFaces() );
192 for ( auto f = 0; f < smesh.nbFaces(); ++f )
193 {
194 const auto b = smesh.faceCentroid( f );
195 const auto area = mu0.measure( b, R, f );
196 H[ f ] = nc.meanCurvature ( area, mu1.measure( b, R, f ) );
197 G[ f ] = nc.GaussianCurvature( area, mu2.measure( b, R, f ) );
198 }
200
202 auto H_min_max = std::minmax_element( H.cbegin(), H.cend() );
203 auto G_min_max = std::minmax_element( G.cbegin(), G.cend() );
204 std::cout << "Expected mean curvatures:"
205 << " min=" << exp_H_min << " max=" << exp_H_max
206 << std::endl;
207 std::cout << "Computed mean curvatures:"
208 << " min=" << *H_min_max.first << " max=" << *H_min_max.second
209 << std::endl;
210 std::cout << "Expected Gaussian curvatures:"
211 << " min=" << exp_G_min << " max=" << exp_G_max
212 << std::endl;
213 std::cout << "Computed Gaussian curvatures:"
214 << " min=" << *G_min_max.first << " max=" << *G_min_max.second
215 << std::endl;
217
220 const auto colormapH = makeQuantifiedColorMap( makeColorMap( -0.625, 0.625 ) );
221 const auto colormapG = makeQuantifiedColorMap( makeColorMap( -0.625, 0.625 ) );
222 auto colorsH = SMW::Colors( smesh.nbFaces() );
223 auto colorsG = SMW::Colors( smesh.nbFaces() );
224 for ( auto i = 0; i < smesh.nbFaces(); i++ )
225 {
226 colorsH[ i ] = colormapH( H[ i ] );
227 colorsG[ i ] = colormapG( G[ i ] );
228 }
229 SMW::writeOBJ( "example-nc-H", smesh, colorsH );
230 SMW::writeOBJ( "example-nc-G", smesh, colorsG );
232 return 0;
233}
DGtal::GradientColorMap< double > makeColorMap(double min_value, double max_value)
[curvature-measures-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

References makeColorMap().

◆ makeColorMap()

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

[curvature-measures-Includes]

[curvature-measures-Includes]

Definition at line 93 of file curvature-measures-nc-3d.cpp.

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

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