DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
obj-curvature-measures-icnc-XY-3d.cpp File Reference
#include <iostream>
#include <algorithm>
#include "DGtal/base/Common.h"
#include "DGtal/shapes/SurfaceMesh.h"
#include "DGtal/geometry/meshes/CorrectedNormalCurrentComputer.h"
#include "DGtal/io/writers/SurfaceMeshWriter.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/helpers/Shortcuts.h"
#include "DGtal/io/readers/SurfaceMeshReader.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 obj-curvature-measures-icnc-XY-3d.

This file is part of the DGtal library.

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

111{
112 if ( argc <= 1 )
113 {
114 usage( argc, argv );
115 return 0;
116 }
118 using namespace DGtal;
119 using namespace DGtal::Z3i;
124 // OBJ file
125 std::string input = argv[ 1 ];
126 const double R = argc > 2 ? atof( argv[ 2 ] ) : 0.0; // radius of measuring ball
127 const double Kmax = argc > 3 ? atof( argv[ 3 ] ) : 5.0; // range curvature colormap
128
130 SM smesh;
131 std::ifstream obj_stream( input.c_str() );
132 bool ok = SMR::readOBJ( obj_stream, smesh );
133 if ( !ok )
134 {
135 trace.error() << "Unable to read file <" << input.c_str() << ">" << std::endl;
136 return 1;
137 }
138 RealPoint lo = smesh.position( 0 );
139 RealPoint up = smesh.position( 0 );
140 for ( const auto& p : smesh.positions() )
141 lo = lo.inf( p ), up = up.sup( p );
142 const auto diameter = (up - lo).norm();
143 trace.info() << "Mesh=" << smesh
144 << " diameter=" << diameter
145 << " radius=" << R << std::endl;
147
149 // builds a CorrectedNormalCurrentComputer object onto the mesh
150 CNC cnc( smesh );
151 // computes normals if necessary
152 if ( smesh.vertexNormals().empty() )
153 {
154 if ( smesh.faceNormals().empty() )
155 smesh.computeFaceNormalsFromPositions();
156 smesh.computeVertexNormalsFromFaceNormals();
157 }
158 // computes area, anisotropic XY curvature measures
159 auto mu0 = cnc.computeMu0();
160 auto muXY = cnc.computeMuXY();
162
164 // estimates mean (H) and Gaussian (G) curvatures by measure normalization.
165 std::vector< double > K1( smesh.nbFaces() );
166 std::vector< double > K2( smesh.nbFaces() );
167 std::vector< RealVector > D1( smesh.nbFaces() );
168 std::vector< RealVector > D2( smesh.nbFaces() );
169 smesh.computeFaceNormalsFromPositions();
170 for ( auto f = 0; f < smesh.nbFaces(); ++f )
171 {
172 const auto b = smesh.faceCentroid( f );
173 const auto N = smesh.faceNormals()[ f ];
174 const auto area = mu0 .measure( b, R, f );
175 const auto M = muXY.measure( b, R, f );
176 std::tie( K1[ f ], K2[ f ], D1[ f ], D2[ f ] )
177 = cnc.principalCurvatures( area, M, N );
178 }
180
182 auto K1_min_max = std::minmax_element( K1.cbegin(), K1.cend() );
183 auto K2_min_max = std::minmax_element( K2.cbegin(), K2.cend() );
184 std::cout << "Computed k1 curvatures:"
185 << " min=" << *K1_min_max.first << " max=" << *K1_min_max.second
186 << std::endl;
187 std::cout << "Computed k2 curvatures:"
188 << " min=" << *K2_min_max.first << " max=" << *K2_min_max.second
189 << std::endl;
191
194 typedef Shortcuts< KSpace > SH;
195 const auto colormapK1 = makeQuantifiedColorMap( makeColorMap( -Kmax, Kmax ) );
196 const auto colormapK2 = makeQuantifiedColorMap( makeColorMap( -Kmax, Kmax ) );
197 auto colorsK1 = SMW::Colors( smesh.nbFaces() );
198 auto colorsK2 = SMW::Colors( smesh.nbFaces() );
199 for ( auto i = 0; i < smesh.nbFaces(); i++ )
200 {
201 colorsK1[ i ] = colormapK1( K1[ i ] );
202 colorsK2[ i ] = colormapK2( K2[ i ] );
203 }
204 SMW::writeOBJ( "example-cnc-K1", smesh, colorsK1 );
205 SMW::writeOBJ( "example-cnc-K2", smesh, colorsK2 );
206 const auto avg_e = smesh.averageEdgeLength();
207 SH::RealPoints positions( smesh.nbFaces() );
208 for ( auto f = 0; f < positions.size(); ++f )
209 {
210 D1[ f ] *= smesh.localWindow( f );
211 positions[ f ] = smesh.faceCentroid( f ) - 0.5 * D1[ f ];
212 }
213 SH::saveVectorFieldOBJ( positions, D1, 0.05 * avg_e, SH::Colors(),
214 "example-cnc-D1",
215 SH::Color::Black, SH::Color( 0, 128, 0 ) );
216 for ( auto f = 0; f < positions.size(); ++f )
217 {
218 D2[ f ] *= smesh.localWindow( f );
219 positions[ f ] = smesh.faceCentroid( f ) - 0.5 * D2[ f ];
220 }
221 SH::saveVectorFieldOBJ( positions, D2, 0.05 * avg_e, SH::Colors(),
222 "example-cnc-D2",
223 SH::Color::Black, SH::Color(128, 0,128 ) );
224
226 return 0;
227}
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).
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition: Shortcuts.h:105
std::ostream & error()
std::ostream & info()
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)
Trace trace
Definition: Common.h:154
DGtal::GradientColorMap< double > makeColorMap(double min_value, double max_value)
[curvature-measures-Includes]
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
Z2i::RealPoint RealPoint

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

◆ makeColorMap()

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

[curvature-measures-Includes]

[curvature-measures-Includes]

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

82{
83 DGtal::GradientColorMap< double > gradcmap( min_value, max_value );
84 gradcmap.addColor( DGtal::Color( 0, 0, 255 ) );
85 gradcmap.addColor( DGtal::Color( 0, 255, 255 ) );
86 gradcmap.addColor( DGtal::Color( 255, 255, 255 ) );
87 gradcmap.addColor( DGtal::Color( 255, 255, 0 ) );
88 gradcmap.addColor( DGtal::Color( 255, 0, 0 ) );
89 return gradcmap;
90}
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 92 of file obj-curvature-measures-icnc-XY-3d.cpp.

93{
94 std::cout << "Usage: " << std::endl
95 << "\t" << argv[ 0 ] << " <filename.obj> <R> <Kmax>" << std::endl
96 << std::endl
97 << "Computation of principal curvatures and directions on a mesh, " << std::endl
98 << "using interpolated corrected curvature measures (based " << std::endl
99 << "on the theory of corrected normal currents)." << std::endl
100 << "- builds the surface mesh from file <filename.obj>" << std::endl
101 << "- <R> is the radius of the measuring balls." << std::endl
102 << "- <Kmax> gives the colormap range [-Kmax,Kmax] for" << std::endl
103 << " the output of principal curvatures estimates" << std::endl
104 << "It produces several OBJ files to display principal " << std::endl
105 << "curvatures and directions estimations: `example-cnc-K1.obj`" << std::endl
106 << "`example-cnc-K2.obj`, `example-cnc-D1.obj`, and" << std::endl
107 << "`example-cnc-D2.obj` as well as associated MTL files." << std::endl;
108}