DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
curvature-measures-icnc-XY-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 "DGtal/helpers/Shortcuts.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-icnc-XY-3d.

This file is part of the DGtal library.

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

140{
141 if ( argc <= 1 )
142 {
143 usage( argc, argv );
144 return 0;
145 }
147 using namespace DGtal;
148 using namespace DGtal::Z3i;
153 // a shape in "torus|lantern|sphere"
154 std::string input = argv[ 1 ];
155 int m = argc > 2 ? atoi( argv[ 2 ] ) : 20; // nb latitude points
156 int n = argc > 3 ? atoi( argv[ 3 ] ) : 20; // nb longitude points
157 double R = argc > 4 ? atof( argv[ 4 ] ) : 0.5; // radius of measuring ball
158
160 SM smesh;
161 double exp_K1_min = 0.0;
162 double exp_K1_max = 0.0;
163 double exp_K2_min = 0.0;
164 double exp_K2_max = 0.0;
165 if ( input == "torus" )
166 {
167 const double big_radius = 3.0;
168 const double small_radius = 1.00001; // avoid codacy warnings
169 smesh = SMH::makeTorus( big_radius, small_radius,
170 RealPoint { 0.0, 0.0, 0.0 }, m, n, 0,
171 SMH::NormalsType::VERTEX_NORMALS );
172 exp_K1_min = ( 1.0 / ( small_radius - big_radius ) );
173 exp_K1_max = ( 1.0 / ( big_radius + small_radius ) );
174 exp_K2_min = 1.0 / small_radius;
175 exp_K2_max = 1.0 / small_radius;
176 }
177 else if ( input == "sphere" )
178 {
179 const double radius = 2.0;
180 smesh = SMH::makeSphere( radius, RealPoint { 0.0, 0.0, 0.0 }, m, n,
181 SMH::NormalsType::VERTEX_NORMALS );
182 exp_K1_min = 1.0 / radius;
183 exp_K1_max = 1.0 / radius;
184 exp_K2_min = 1.0 / radius;
185 exp_K2_max = 1.0 / radius;
186 }
187 else if ( input == "lantern" )
188 {
189 const double radius = 2.0;
190 smesh = SMH::makeLantern( radius, 1.0, RealPoint { 0.0, 0.0, 0.0 }, m, n,
191 SMH::NormalsType::VERTEX_NORMALS );
192 exp_K1_min = 0.0;
193 exp_K1_max = 0.0;
194 exp_K2_min = 1.0 / radius;
195 exp_K2_max = 1.0 / radius;
196 }
198
200 // builds a CorrectedNormalCurrentComputer object onto the mesh
201 CNC cnc( smesh );
202 // computes area, anisotropic XY curvature measures
203 auto mu0 = cnc.computeMu0();
204 auto muXY = cnc.computeMuXY();
206
208 // Estimates principal curvatures (K1,K2) and directions (D1,D2) by
209 // measure normalization and eigen decomposition.
210 std::vector< double > K1( smesh.nbFaces() );
211 std::vector< double > K2( smesh.nbFaces() );
212 std::vector< RealVector > D1( smesh.nbFaces() );
213 std::vector< RealVector > D2( smesh.nbFaces() );
214 // Principal directions computation requires a local face normal
215 smesh.computeFaceNormalsFromPositions();
216 for ( auto f = 0; f < smesh.nbFaces(); ++f )
217 {
218 const auto b = smesh.faceCentroid( f );
219 const auto N = smesh.faceNormals()[ f ];
220 const auto area = mu0 .measure( b, R, f );
221 const auto M = muXY.measure( b, R, f );
222 std::tie( K1[ f ], K2[ f ], D1[ f ], D2[ f ] )
223 = cnc.principalCurvatures( area, M, N );
224 }
226
228 auto K1_min_max = std::minmax_element( K1.cbegin(), K1.cend() );
229 auto K2_min_max = std::minmax_element( K2.cbegin(), K2.cend() );
230 std::cout << "Expected k1 curvatures:"
231 << " min=" << exp_K1_min << " max=" << exp_K1_max
232 << std::endl;
233 std::cout << "Computed k1 curvatures:"
234 << " min=" << *K1_min_max.first << " max=" << *K1_min_max.second
235 << std::endl;
236 std::cout << "Expected k2 curvatures:"
237 << " min=" << exp_K2_min << " max=" << exp_K2_max
238 << std::endl;
239 std::cout << "Computed k2 curvatures:"
240 << " min=" << *K2_min_max.first << " max=" << *K2_min_max.second
241 << std::endl;
243
246 typedef Shortcuts< KSpace > SH;
247 const auto colormapK1 = makeQuantifiedColorMap( makeColorMap( -0.625, 0.625 ) );
248 const auto colormapK2 = makeQuantifiedColorMap( makeColorMap( -0.625, 0.625 ) );
249 auto colorsK1 = SMW::Colors( smesh.nbFaces() );
250 auto colorsK2 = SMW::Colors( smesh.nbFaces() );
251 for ( auto i = 0; i < smesh.nbFaces(); i++ )
252 {
253 colorsK1[ i ] = colormapK1( K1[ i ] );
254 colorsK2[ i ] = colormapK2( K2[ i ] );
255 }
256 SMW::writeOBJ( "example-cnc-K1", smesh, colorsK1 );
257 SMW::writeOBJ( "example-cnc-K2", smesh, colorsK2 );
258 const auto avg_e = smesh.averageEdgeLength();
259 SH::RealPoints positions( smesh.nbFaces() );
260 for ( auto f = 0; f < positions.size(); ++f )
261 {
262 D1[ f ] *= smesh.localWindow( f );
263 positions[ f ] = smesh.faceCentroid( f ) - 0.5 * D1[ f ];
264 }
265 SH::saveVectorFieldOBJ( positions, D1, 0.05 * avg_e, SH::Colors(),
266 "example-cnc-D1",
267 SH::Color::Black, SH::Color( 0, 128, 0 ) );
268 for ( auto f = 0; f < positions.size(); ++f )
269 {
270 D2[ f ] *= smesh.localWindow( f );
271 positions[ f ] = smesh.faceCentroid( f ) - 0.5 * D2[ f ];
272 }
273 SH::saveVectorFieldOBJ( positions, D2, 0.05 * avg_e, SH::Colors(),
274 "example-cnc-D2",
275 SH::Color::Black, SH::Color(128, 0,128 ) );
276
278 return 0;
279}
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition: Shortcuts.h:105
DGtal::GradientColorMap< double > makeColorMap(double min_value, double max_value)
[curvature-measures-Includes]
KSpace K2
Definition: StdDefs.h:78
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
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 111 of file curvature-measures-icnc-XY-3d.cpp.

112{
113 DGtal::GradientColorMap< double > gradcmap( min_value, max_value );
114 gradcmap.addColor( DGtal::Color( 0, 0, 255 ) );
115 gradcmap.addColor( DGtal::Color( 0, 255, 255 ) );
116 gradcmap.addColor( DGtal::Color( 255, 255, 255 ) );
117 gradcmap.addColor( DGtal::Color( 255, 255, 0 ) );
118 gradcmap.addColor( DGtal::Color( 255, 0, 0 ) );
119 return gradcmap;
120}
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 122 of file curvature-measures-icnc-XY-3d.cpp.

123{
124 std::cout << "Usage: " << std::endl
125 << "\t" << argv[ 0 ] << " <shape> <m> <n> <R>" << std::endl
126 << std::endl
127 << "Computation of principal curvatures and directions on a shape, " << std::endl
128 << "using interpolated corrected curvature measures (based " << std::endl
129 << "on the theory of corrected normal currents)." << std::endl
130 << "- builds a <shape> in {torus,lantern,sphere}, with " << std::endl
131 << " <m> latitude points and <n> longitude points." << std::endl
132 << "- <R> is the radius of the measuring balls." << std::endl
133 << "It produces several OBJ files to display principal " << std::endl
134 << "curvatures and directions estimations: `example-cnc-K1.obj`" << std::endl
135 << "`example-cnc-K2.obj`, `example-cnc-D1.obj`, and" << std::endl
136 << "`example-cnc-D2.obj` as well as associated MTL files." << std::endl;
137}