DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
vol-curvature-measures-icnc-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-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 vol-curvature-measures-icnc-3d.

This file is part of the DGtal library.

Definition in file vol-curvature-measures-icnc-3d.cpp.

Function Documentation

◆ main()

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

[curvature-measures-Typedefs]

[curvature-measures-Typedefs]

[curvature-measures-DigitalSurface]

[curvature-measures-DigitalSurface]

[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 120 of file vol-curvature-measures-icnc-3d.cpp.

121{
122 if ( argc <= 1 )
123 {
124 usage( argc, argv );
125 return 0;
126 }
128 using namespace DGtal;
129 using namespace DGtal::Z3i;
132 typedef Shortcuts< KSpace > SH;
133 typedef ShortcutsGeometry< KSpace > SHG;
135 // VOL file
136 std::string input = argv[ 1 ];
137 const double R = argc > 2 ? atof( argv[ 2 ] ) : 2.0; // radius of measuring ball
138 const int m = argc > 3 ? atoi( argv[ 3 ] ) : 0; // min threshold
139 const int M = argc > 4 ? atoi( argv[ 4 ] ) : 1; // max threshold
140 const double Hmax = argc > 5 ? atof( argv[ 5 ] ) : 0.33; // range mean curvature colormap
141 const double Gmax = argc > 6 ? atof( argv[ 6 ] ) : 0.1; // range Gaussian curvature colormap
142
144 // Read VOL file and build digital surface
145 auto params = SH::defaultParameters() | SHG::defaultParameters();
146 params( "thresholdMin", m )( "thresholdMax", M )( "closed", 1);
147 params( "t-ring", 3 )( "surfaceTraversal", "Default" );
148 auto bimage = SH::makeBinaryImage( input.c_str(), params );
149 if ( bimage == nullptr )
150 {
151 trace.error() << "Unable to read file <" << input.c_str() << ">" << std::endl;
152 return 1;
153 }
154 auto K = SH::getKSpace( bimage, params );
155 auto sembedder = SH::getSCellEmbedder( K );
156 auto embedder = SH::getCellEmbedder( K );
157 auto surface = SH::makeDigitalSurface( bimage, K, params );
158 auto surfels = SH::getSurfelRange( surface, params );
159 trace.info() << "- surface has " << surfels.size()<< " surfels." << std::endl;
161
163 SM smesh;
164 std::vector< SM::Vertices > faces;
165 SH::Cell2Index c2i;
166 auto pointels = SH::getPointelRange( c2i, surface );
167 auto vertices = SH::RealPoints( pointels.size() );
168 std::transform( pointels.cbegin(), pointels.cend(), vertices.begin(),
169 [&] (const SH::Cell& c) { return embedder( c ); } );
170 for ( auto&& surfel : *surface )
171 {
172 const auto primal_surfel_vtcs = SH::getPointelRange( K, surfel );
173 SM::Vertices face;
174 for ( auto&& primal_vtx : primal_surfel_vtcs )
175 face.push_back( c2i[ primal_vtx ] );
176 faces.push_back( face );
177 }
178 smesh.init( vertices.cbegin(), vertices.cend(),
179 faces.cbegin(), faces.cend() );
180 trace.info() << smesh << std::endl;
182
184 // Builds a CorrectedNormalCurrentComputer object onto the SurfaceMesh object
185 CNC cnc( smesh );
186 // Estimates normal vectors using Convolved Trivial Normal estimator
187 auto face_normals = SHG::getCTrivialNormalVectors( surface, surfels, params );
188 smesh.setFaceNormals( face_normals.cbegin(), face_normals.cend() );
189 // if ( smesh.vertexNormals().empty() )
190 // smesh.computeVertexNormalsFromFaceNormals();
191 // computes area, mean and Gaussian curvature measures
192 std::cout << "Compute mu0" << std::endl;
193 auto mu0 = cnc.computeMu0();
194 std::cout << "Compute mu1" << std::endl;
195 auto mu1 = cnc.computeMu1();
196 std::cout << "Compute mu2" << std::endl;
197 auto mu2 = cnc.computeMu2();
199
201 // estimates mean (H) and Gaussian (G) curvatures by measure normalization.
202 std::vector< double > H( smesh.nbFaces() );
203 std::vector< double > G( smesh.nbFaces() );
204 for ( auto f = 0; f < smesh.nbFaces(); ++f )
205 {
206 const auto b = smesh.faceCentroid( f );
207 const auto area = mu0.measure( b, R, f );
208 H[ f ] = cnc.meanCurvature ( area, mu1.measure( b, R, f ) );
209 G[ f ] = cnc.GaussianCurvature( area, mu2.measure( b, R, f ) );
210 }
212
214 auto H_min_max = std::minmax_element( H.cbegin(), H.cend() );
215 auto G_min_max = std::minmax_element( G.cbegin(), G.cend() );
216 std::cout << "Computed mean curvatures:"
217 << " min=" << *H_min_max.first << " max=" << *H_min_max.second
218 << std::endl;
219 std::cout << "Computed Gaussian curvatures:"
220 << " min=" << *G_min_max.first << " max=" << *G_min_max.second
221 << std::endl;
223
225 // Remove normals for better blocky display.
226 smesh.vertexNormals() = SH::RealVectors();
227 smesh.faceNormals() = SH::RealVectors();
229 const auto colormapH = makeQuantifiedColorMap( makeColorMap( -Hmax, Hmax ) );
230 const auto colormapG = makeQuantifiedColorMap( makeColorMap( -Gmax, Gmax ) );
231 auto colorsH = SMW::Colors( smesh.nbFaces() );
232 auto colorsG = SMW::Colors( smesh.nbFaces() );
233 for ( auto i = 0; i < smesh.nbFaces(); i++ )
234 {
235 colorsH[ i ] = colormapH( H[ i ] );
236 colorsG[ i ] = colormapG( G[ i ] );
237 }
238 SMW::writeOBJ( "example-cnc-H", smesh, colorsH );
239 SMW::writeOBJ( "example-cnc-G", smesh, colorsG );
241 return 0;
242}
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
std::ostream & error()
std::ostream & info()
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
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: 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
KSpace K
DGtal::GradientColorMap< double > makeColorMap(double min_value, double max_value)
[curvature-measures-Includes]

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

◆ makeColorMap()

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

[curvature-measures-Includes]

[curvature-measures-Includes]

Definition at line 88 of file vol-curvature-measures-icnc-3d.cpp.

89{
90 DGtal::GradientColorMap< double > gradcmap( min_value, max_value );
91 gradcmap.addColor( DGtal::Color( 0, 0, 255 ) );
92 gradcmap.addColor( DGtal::Color( 0, 255, 255 ) );
93 gradcmap.addColor( DGtal::Color( 255, 255, 255 ) );
94 gradcmap.addColor( DGtal::Color( 255, 255, 0 ) );
95 gradcmap.addColor( DGtal::Color( 255, 0, 0 ) );
96 return gradcmap;
97}
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 99 of file vol-curvature-measures-icnc-3d.cpp.

100{
101 std::cout << "Usage: " << std::endl
102 << "\t" << argv[ 0 ] << " <filename.vol> <R> <m> <M> <Hmax> <Gmax>" << std::endl
103 << std::endl
104 << "Computation of mean and Gaussian curvatures on a vol file, " << std::endl
105 << "using interpolated corrected curvature measures (based " << std::endl
106 << "on the theory of corrected normal currents)." << std::endl
107 << "- builds the surface mesh from file <filename.vol>" << std::endl
108 << "- <R> is the radius of the measuring balls" << std::endl
109 << "- <m> is the min threshold value for the vol file" << std::endl
110 << "- <M> is the max threshold value for the vol file" << std::endl
111 << "- <Hmax> gives the colormap range [-Hmax,Hmax] for" << std::endl
112 << " the output of mean curvature estimates" << std::endl
113 << "- <Gmax> gives the colormap range [-Gmax,Gmax] for" << std::endl
114 << " the output of mean curvature estimates" << 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}