DGtal 1.4.0
Loading...
Searching...
No Matches
curvature-measures-nc-3d.cpp
Go to the documentation of this file.
1
80#include <iostream>
81#include <algorithm>
82#include "DGtal/base/Common.h"
83#include "DGtal/shapes/SurfaceMesh.h"
84#include "DGtal/shapes/SurfaceMeshHelper.h"
86#include "DGtal/geometry/meshes/NormalCycleComputer.h"
88#include "DGtal/io/writers/SurfaceMeshWriter.h"
89#include "DGtal/io/colormaps/GradientColorMap.h"
90#include "DGtal/io/colormaps/QuantifiedColorMap.h"
91
93makeColorMap( double min_value, double max_value )
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}
103
104void usage( int argc, char* argv[] )
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}
119
120int main( int argc, char* argv[] )
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}
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 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
int main()
Definition testBits.cpp:56
PointVector< 3, double > RealPoint