DGtal 1.3.0
Loading...
Searching...
No Matches
curvature-measures-icnc-3d.cpp
Go to the documentation of this file.
1
84#include <iostream>
85#include <algorithm>
86#include "DGtal/base/Common.h"
87#include "DGtal/shapes/SurfaceMesh.h"
88#include "DGtal/shapes/SurfaceMeshHelper.h"
90#include "DGtal/geometry/meshes/CorrectedNormalCurrentComputer.h"
92#include "DGtal/io/writers/SurfaceMeshWriter.h"
93#include "DGtal/io/colormaps/GradientColorMap.h"
94#include "DGtal/io/colormaps/QuantifiedColorMap.h"
95
97makeColorMap( double min_value, double max_value )
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}
107
108void usage( int argc, char* argv[] )
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}
123
124int main( int argc, char* argv[] )
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}
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...
void addColor(const Color &color)
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.
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
int main()
Definition: testBits.cpp:56