DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
curvature-comparator-ii-cnc-3d.cpp File Reference
#include <iostream>
#include <fstream>
#include <algorithm>
#include "DGtal/base/Common.h"
#include "DGtal/shapes/SurfaceMesh.h"
#include "DGtal/geometry/meshes/CorrectedNormalCurrentComputer.h"
#include "DGtal/helpers/Shortcuts.h"
#include "DGtal/helpers/ShortcutsGeometry.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-comparator-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
2022/02/27

An example file named curvature-comparator-ii-cnc-3d.

This file is part of the DGtal library.

Definition in file curvature-comparator-ii-cnc-3d.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

[curvature-comparator-Typedefs]

[curvature-comparator-Typedefs]

[curvature-comparator-DigitalSurface]

[curvature-comparator-DigitalSurface]

[curvature-comparator-ii]

[curvature-comparator-ii]

[curvature-comparator-SurfaceMesh]

[curvature-comparator-SurfaceMesh]

[curvature-comparator-TrueCurvatures]

[curvature-comparator-TrueCurvatures]

[curvature-comparator-CNC]

[curvature-comparator-CNC]

[curvature-comparator-estimations]

[curvature-comparator-estimations]

[curvature-comparator-check]

[curvature-comparator-check]

[curvature-comparator-results]

[curvature-comparator-results]

Definition at line 126 of file curvature-comparator-ii-cnc-3d.cpp.

127{
128 if ( argc <= 1 )
129 {
130 usage( argc, argv );
131 return 0;
132 }
134 using namespace DGtal;
135 using namespace DGtal::Z3i;
138 typedef Shortcuts< KSpace > SH;
139 typedef SH::DigitalSurface DigSurf;
140 typedef ShortcutsGeometry< KSpace > SHG;
142 std::string poly = argv[ 1 ]; // polynomial
143 const double B = argc > 2 ? atof( argv[ 2 ] ) : 1.0; // max ||_oo bbox
144 const double h = argc > 3 ? atof( argv[ 3 ] ) : 1.0; // gridstep
145 std::string mode = argc > 4 ? argv[ 4 ] : "Const"; // either Const or Interp
146 bool interpolated = mode == "Interp";
147 if ( interpolated )
148 trace.info() << "Using vertex-*Interpolated* Corrected Normal Current" << std::endl;
149 else
150 trace.info() << "Using face-*Constant* Corrected Normal Current" << std::endl;
152 // Read polynomial and build digital surface
153 auto params = SH::defaultParameters() | SHG::defaultParameters();
154 // Choose depth-first traversal to speed-up II computations.
155 params( "surfaceTraversal", "DepthFirst" );
156 params( "t-ring", 3 );
157 params( "polynomial", poly )( "gridstep", h );
158 params( "minAABB", -B )( "maxAABB", B );
159 params( "offset", 3.0 );
160 auto shape = SH::makeImplicitShape3D( params );
161 auto K = SH::getKSpace( params );
162 auto dshape = SH::makeDigitizedImplicitShape3D( shape, params );
163 auto bimage = SH::makeBinaryImage( dshape, params );
164 if ( bimage == nullptr )
165 {
166 trace.error() << "Unable to read polynomial <"
167 << poly.c_str() << ">" << std::endl;
168 return 1;
169 }
170 auto sembedder = SH::getSCellEmbedder( K );
171 auto embedder = SH::getCellEmbedder( K );
172 auto surface = SH::makeDigitalSurface( bimage, K, params );
173 auto surfels = SH::getSurfelRange( surface, params );
174 trace.info() << "- surface has " << surfels.size()<< " surfels." << std::endl;
176
178 params( "r-radius", 3.0 );
179 params( "alpha", 0.33 );
180 double ii_r = 3.0 * pow( h, 0.33 );
181 Clock c;
182 trace.beginBlock( "Computing II curvatures" );
183 std::vector< double > HII = SHG::getIIMeanCurvatures ( bimage, surfels, params );
184 std::vector< double > GII = SHG::getIIGaussianCurvatures( bimage, surfels, params );
185 auto ii_t = trace.endBlock();
187
189 SM smesh;
190 std::vector< SM::Vertices > faces;
191 SH::Cell2Index c2i;
192 auto pointels = SH::getPointelRange( c2i, surface );
193 auto vertices = SH::RealPoints( pointels.size() );
194 std::transform( pointels.cbegin(), pointels.cend(), vertices.begin(),
195 [&] (const SH::Cell& c) { return h * embedder( c ); } );
196 for ( auto&& surfel : surfels )
197 {
198 const auto primal_surfel_vtcs = SH::getPointelRange( K, surfel );
199 SM::Vertices face;
200 for ( auto&& primal_vtx : primal_surfel_vtcs )
201 face.push_back( c2i[ primal_vtx ] );
202 faces.push_back( face );
203 }
204 smesh.init( vertices.cbegin(), vertices.cend(),
205 faces.cbegin(), faces.cend() );
206 trace.info() << smesh << std::endl;
208
210 trace.beginBlock( "Computing True curvatures" );
211 auto exp_H = SHG::getMeanCurvatures( shape, K, surfels, params );
212 auto exp_G = SHG::getGaussianCurvatures( shape, K, surfels, params );
213 trace.endBlock();
215
216 trace.beginBlock( "Computing CNC curvatures" );
218 // Builds a CorrectedNormalCurrentComputer object onto the SurfaceMesh object
219 CNC cnc( smesh );
220 // Estimates normal vectors using Integral Invariant Normal estimator
221 trace.beginBlock( "Computing II normal vectors" );
222 auto face_normals = SHG::getIINormalVectors( bimage, surfels, params );
223 double cnc_tn = trace.endBlock();
224 // Set corrected face normals => Corrected Normal Current with
225 // constant per face corrected vector field.
226 smesh.setFaceNormals( face_normals.cbegin(), face_normals.cend() ); // CCNC
227 // Set corrected vertex normals => Corrected Normal Current with
228 // smooth linearly interpolated per face corrected vector field.
229 if ( interpolated ) smesh.computeVertexNormalsFromFaceNormals(); // ICNC
230 // computes area, mean and Gaussian curvature measures
231 auto mu0 = cnc.computeMu0();
232 auto mu1 = cnc.computeMu1();
233 auto mu2 = cnc.computeMu2();
235
237 // estimates mean (H) and Gaussian (G) curvatures by measure normalization.
238 double cnc_mr = 1.0 * sqrt( h );
239 trace.info() << "CNC measuring radius = " << cnc_mr << std::endl;
240 std::vector< double > H( smesh.nbFaces() );
241 std::vector< double > G( smesh.nbFaces() );
242 for ( auto f = 0; f < smesh.nbFaces(); ++f )
243 {
244 const auto b = smesh.faceCentroid( f );
245 const auto area = mu0.measure( b, cnc_mr, f );
246 H[ f ] = cnc.meanCurvature ( area, mu1.measure( b, cnc_mr, f ) );
247 G[ f ] = cnc.GaussianCurvature( area, mu2.measure( b, cnc_mr, f ) );
248 }
250 double cnc_t = trace.endBlock();
251
253 auto HII_min_max = std::minmax_element( HII.cbegin(), HII.cend() );
254 auto GII_min_max = std::minmax_element( GII.cbegin(), GII.cend() );
255 auto H_min_max = std::minmax_element( H.cbegin(), H.cend() );
256 auto G_min_max = std::minmax_element( G.cbegin(), G.cend() );
257 auto exp_H_min_max = std::minmax_element( exp_H.cbegin(), exp_H.cend() );
258 auto exp_G_min_max = std::minmax_element( exp_G.cbegin(), exp_G.cend() );
259 trace.info() << "Expected mean curvatures:"
260 << " min=" << *exp_H_min_max.first << " max=" << *exp_H_min_max.second
261 << std::endl;
262 trace.info() << "Computed II mean curvatures:"
263 << " min=" << *HII_min_max.first << " max=" << *HII_min_max.second
264 << std::endl;
265 trace.info() << "Computed CNC mean curvatures:"
266 << " min=" << *H_min_max.first << " max=" << *H_min_max.second
267 << std::endl;
268 trace.info() << "Expected Gaussian curvatures:"
269 << " min=" << *exp_G_min_max.first << " max=" << *exp_G_min_max.second
270 << std::endl;
271 trace.info() << "Computed II Gaussian curvatures:"
272 << " min=" << *GII_min_max.first << " max=" << *GII_min_max.second
273 << std::endl;
274 trace.info() << "Computed CNC Gaussian curvatures:"
275 << " min=" << *G_min_max.first << " max=" << *G_min_max.second
276 << std::endl;
277 const auto error_HII = SHG::getScalarsAbsoluteDifference( HII, exp_H );
278 const auto stat_error_HII = SHG::getStatistic( error_HII );
279 const auto error_HII_l2 = SHG::getScalarsNormL2( HII, exp_H );
280 trace.info() << "|H-H_II|_oo = " << stat_error_HII.max() << std::endl;
281 trace.info() << "|H-H_II|_2 = " << error_HII_l2 << std::endl;
282 const auto error_H = SHG::getScalarsAbsoluteDifference( H, exp_H );
283 const auto stat_error_H = SHG::getStatistic( error_H );
284 const auto error_H_l2 = SHG::getScalarsNormL2( H, exp_H );
285 trace.info() << "|H-H_CNC|_oo = " << stat_error_H.max() << std::endl;
286 trace.info() << "|H-H_CNC|_2 = " << error_H_l2 << std::endl;
287 const auto error_GII = SHG::getScalarsAbsoluteDifference( GII, exp_G );
288 const auto stat_error_GII = SHG::getStatistic( error_GII );
289 const auto error_GII_l2 = SHG::getScalarsNormL2( GII, exp_G );
290 trace.info() << "|G-G_II|_oo = " << stat_error_GII.max() << std::endl;
291 trace.info() << "|G-G_II|_2 = " << error_GII_l2 << std::endl;
292 const auto error_G = SHG::getScalarsAbsoluteDifference( G, exp_G );
293 const auto stat_error_G = SHG::getStatistic( error_G );
294 const auto error_G_l2 = SHG::getScalarsNormL2( G, exp_G );
295 trace.info() << "|G-G_CNC|_oo = " << stat_error_G.max() << std::endl;
296 trace.info() << "|G-G_CNC|_2 = " << error_G_l2 << std::endl;
298
300 std::cout << "# " << argv[ 0 ] << std::endl
301 << "# polynomial: " << poly << std::endl
302 << "# CNC mode: " << mode << std::endl;
303 // 1 2 3 4 5 6 7 8
304 std::cout << "# h nb_surfels ii_t ii_r ii_Hoo ii_H2 ii_Goo ii_G2 ";
305 // 9 10 11 12 13 14 15
306 std::cout << "cnc_tn cnc_t cnc_mr cnc_Hoo cnc_H2 cnc_Goo cnc_G2" << std::endl;
307 std::cout << h << " " << surfels.size() << " " << ii_t << " " << ii_r
308 << " " << stat_error_HII.max() << " " << error_HII_l2
309 << " " << stat_error_GII.max() << " " << error_GII_l2
310 << " " << cnc_tn << " " << cnc_t << " " << cnc_mr
311 << " " << stat_error_H.max() << " " << error_H_l2
312 << " " << stat_error_G.max() << " " << error_G_l2 << std::endl;
314 return 0;
315}
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition: Shortcuts.h:105
void beginBlock(const std::string &keyword="")
std::ostream & error()
std::ostream & info()
double endBlock()
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator > vertices(const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
Aim: Utility class to compute curvature measures induced by (1) a corrected normal current defined by...
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...
Definition: SurfaceMesh.h:92
KSpace K

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::error(), DGtal::Trace::info(), and K.

◆ makeColorMap()

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

[curvature-comparator-Includes]

[curvature-comparator-Includes]

Examples
geometry/meshes/curvature-comparator-ii-cnc-3d.cpp, geometry/meshes/curvature-measures-icnc-3d.cpp, geometry/meshes/curvature-measures-icnc-XY-3d.cpp, geometry/meshes/curvature-measures-nc-3d.cpp, geometry/meshes/curvature-measures-nc-XY-3d.cpp, geometry/meshes/digpoly-curvature-measures-cnc-3d.cpp, geometry/meshes/digpoly-curvature-measures-cnc-XY-3d.cpp, geometry/meshes/obj-curvature-measures-icnc-3d.cpp, geometry/meshes/obj-curvature-measures-icnc-XY-3d.cpp, geometry/meshes/vol-curvature-measures-icnc-3d.cpp, and geometry/meshes/vol-curvature-measures-icnc-XY-3d.cpp.

Definition at line 89 of file curvature-comparator-ii-cnc-3d.cpp.

90{
91 DGtal::GradientColorMap< double > gradcmap( min_value, max_value );
92 gradcmap.addColor( DGtal::Color( 0, 0, 255 ) );
93 gradcmap.addColor( DGtal::Color( 0, 255, 255 ) );
94 gradcmap.addColor( DGtal::Color( 255, 255, 255 ) );
95 gradcmap.addColor( DGtal::Color( 255, 255, 0 ) );
96 gradcmap.addColor( DGtal::Color( 255, 0, 0 ) );
97 return gradcmap;
98}
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().

◆ usage()

void usage ( int  argc,
char *  argv[] 
)

Definition at line 100 of file curvature-comparator-ii-cnc-3d.cpp.

101{
102 using namespace DGtal;
103 using namespace DGtal::Z3i;
104 typedef Shortcuts< KSpace > SH;
105 std::cout << "Usage: " << std::endl
106 << "\t" << argv[ 0 ] << " <P> <B> <h> <mode>" << std::endl
107 << std::endl
108 << "Compare Integral Invariant (II) curvature estimations " << std::endl
109 << "with Corrected Normal Current (CNC) estimations, either "<< std::endl
110 << "interpolated (Interp) or constant per face (Const)." << std::endl
111 << "- builds the surface mesh from polynomial <P>" << std::endl
112 << "- <B> defines the digitization space size [-B,B]^3" << std::endl
113 << "- <h> is the gridstep digitization" << std::endl
114 << "- <mode> is either Const for constant corrected normal" << std::endl
115 << " vector field or Interp for interpolated corrected" << std::endl
116 << " normal vector field." << std::endl
117 << "It outputs timings and accuracy statistics for both " << std::endl
118 << "methods." << std::endl;
119 std::cout << "You may either write your own polynomial as 3*x^2-z^2*x*y+1" << std::endl
120 <<"or use a predefined polynomial in the following list:" << std::endl;
121 auto L = SH::getPolynomialList();
122 for ( const auto& p : L )
123 std::cout << p.first << " : " << p.second << std::endl;
124}