DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
vol-curvature-measures-icnc-XY-3d.cpp File Reference
#include <iostream>
#include <algorithm>
#include "DGtal/base/Common.h"
#include "DGtal/math/linalg/EigenDecomposition.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/helpers/ShortcutsGeometry.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 vol-curvature-measures-icnc-XY-3d.

This file is part of the DGtal library.

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

125{
126 if ( argc <= 1 )
127 {
128 usage( argc, argv );
129 return 0;
130 }
132 using namespace DGtal;
133 using namespace DGtal::Z3i;
137 typedef Shortcuts< KSpace > SH;
138 typedef ShortcutsGeometry< KSpace > SHG;
140 // VOL file
141 std::string input = argv[ 1 ];
142 const double R = argc > 2 ? atof( argv[ 2 ] ) : 2.0; // radius of measuring ball
143 const int m = argc > 3 ? atoi( argv[ 3 ] ) : 0; // min threshold
144 const int M = argc > 4 ? atoi( argv[ 4 ] ) : 1; // max threshold
145 const double Kmax = argc > 5 ? atof( argv[ 5 ] ) : 0.33; // range mean curvature colormap
146
148 // Read VOL file and build digital surface
149 auto params = SH::defaultParameters() | SHG::defaultParameters();
150 params( "thresholdMin", m )( "thresholdMax", M )( "closed", 1);
151 params( "t-ring", 3 )( "surfaceTraversal", "Default" );
152 auto bimage = SH::makeBinaryImage( input.c_str(), params );
153 if ( bimage == nullptr )
154 {
155 trace.error() << "Unable to read file <" << input.c_str() << ">" << std::endl;
156 return 1;
157 }
158 auto K = SH::getKSpace( bimage, params );
159 auto sembedder = SH::getSCellEmbedder( K );
160 auto embedder = SH::getCellEmbedder( K );
161 auto surface = SH::makeDigitalSurface( bimage, K, params );
162 auto surfels = SH::getSurfelRange( surface, params );
163 trace.info() << "- surface has " << surfels.size()<< " surfels." << std::endl;
165
167 SM smesh;
168 std::vector< SM::Vertices > faces;
169 SH::Cell2Index c2i;
170 auto pointels = SH::getPointelRange( c2i, surface );
171 auto vertices = SH::RealPoints( pointels.size() );
172 std::transform( pointels.cbegin(), pointels.cend(), vertices.begin(),
173 [&] (const SH::Cell& c) { return embedder( c ); } );
174 for ( auto&& surfel : *surface )
175 {
176 const auto primal_surfel_vtcs = SH::getPointelRange( K, surfel );
177 SM::Vertices face;
178 for ( auto&& primal_vtx : primal_surfel_vtcs )
179 face.push_back( c2i[ primal_vtx ] );
180 faces.push_back( face );
181 }
182 smesh.init( vertices.cbegin(), vertices.cend(),
183 faces.cbegin(), faces.cend() );
184 trace.info() << smesh << std::endl;
186
188 // Builds a CorrectedNormalCurrentComputer object onto the SurfaceMesh object
189 CNC cnc( smesh );
190 // Estimates normal vectors using Convolved Trivial Normal estimator
191 auto face_normals = SHG::getCTrivialNormalVectors( surface, surfels, params );
192 smesh.setFaceNormals( face_normals.cbegin(), face_normals.cend() );
193 if ( smesh.vertexNormals().empty() )
194 smesh.computeVertexNormalsFromFaceNormals();
195 // computes area, anisotropic XY curvature measures
196 auto mu0 = cnc.computeMu0();
197 auto muXY = cnc.computeMuXY();
199
201 // estimates principal curvatures (K1,K2) and directions (D1,D2) by
202 // measure normalization.
203 std::vector< double > K1( smesh.nbFaces() );
204 std::vector< double > K2( smesh.nbFaces() );
205 std::vector< RealVector > D1( smesh.nbFaces() );
206 std::vector< RealVector > D2( smesh.nbFaces() );
207 for ( auto f = 0; f < smesh.nbFaces(); ++f )
208 {
209 const auto b = smesh.faceCentroid( f );
210 const auto N = smesh.faceNormals()[ f ];
211 const auto area = mu0 .measure( b, R, f );
212 const auto M = muXY.measure( b, R, f );
213 std::tie( K1[ f ], K2[ f ], D1[ f ], D2[ f ] )
214 = cnc.principalCurvatures( area, M, N );
215 }
217
219 auto K1_min_max = std::minmax_element( K1.cbegin(), K1.cend() );
220 auto K2_min_max = std::minmax_element( K2.cbegin(), K2.cend() );
221 std::cout << "Computed k1 curvatures:"
222 << " min=" << *K1_min_max.first << " max=" << *K1_min_max.second
223 << std::endl;
224 std::cout << "Computed k2 curvatures:"
225 << " min=" << *K2_min_max.first << " max=" << *K2_min_max.second
226 << std::endl;
228
230 // Remove normals for better blocky display.
231 smesh.vertexNormals() = SH::RealVectors();
232 smesh.faceNormals() = SH::RealVectors();
234 const auto colormapK1 = makeQuantifiedColorMap( makeColorMap( -Kmax, Kmax ) );
235 const auto colormapK2 = makeQuantifiedColorMap( makeColorMap( -Kmax, Kmax ) );
236 auto colorsK1 = SMW::Colors( smesh.nbFaces() );
237 auto colorsK2 = SMW::Colors( smesh.nbFaces() );
238 for ( auto i = 0; i < smesh.nbFaces(); i++ )
239 {
240 colorsK1[ i ] = colormapK1( K1[ i ] );
241 colorsK2[ i ] = colormapK2( K2[ i ] );
242 }
243 SMW::writeOBJ( "example-cnc-K1", smesh, colorsK1 );
244 SMW::writeOBJ( "example-cnc-K2", smesh, colorsK2 );
245 const auto avg_e = smesh.averageEdgeLength();
246 SH::RealPoints positions( smesh.nbFaces() );
247 for ( auto f = 0; f < positions.size(); ++f )
248 {
249 D1[ f ] *= smesh.localWindow( f );
250 positions[ f ] = smesh.faceCentroid( f ) - 0.5 * D1[ f ];
251 }
252 SH::saveVectorFieldOBJ( positions, D1, 0.05 * avg_e, SH::Colors(),
253 "example-cnc-D1",
254 SH::Color::Black, SH::Color( 0, 128, 0 ) );
255 for ( auto f = 0; f < positions.size(); ++f )
256 {
257 D2[ f ] *= smesh.localWindow( f );
258 positions[ f ] = smesh.faceCentroid( f ) - 0.5 * D2[ f ];
259 }
260 SH::saveVectorFieldOBJ( positions, D2, 0.05 * avg_e, SH::Colors(),
261 "example-cnc-D2",
262 SH::Color::Black, SH::Color(128, 0,128 ) );
264 return 0;
265}
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()
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
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 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
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 93 of file vol-curvature-measures-icnc-XY-3d.cpp.

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}
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 104 of file vol-curvature-measures-icnc-XY-3d.cpp.

105{
106 std::cout << "Usage: " << std::endl
107 << "\t" << argv[ 0 ] << " <filename.vol> <R> <m> <M> <Kmax>" << std::endl
108 << std::endl
109 << "Computation of principal curvatures and directions on a vol file, " << std::endl
110 << "using interpolated corrected curvature measures (based " << std::endl
111 << "on the theory of corrected normal currents)." << std::endl
112 << "- builds the surface mesh from file <filename.obj>" << std::endl
113 << "- <R> is the radius of the measuring balls." << std::endl
114 << "- <m> is the min threshold value for the vol file" << std::endl
115 << "- <M> is the max threshold value for the vol file" << std::endl
116 << "- <Kmax> gives the colormap range [-Kmax,Kmax] for" << std::endl
117 << " the output of principal curvatures estimates" << std::endl
118 << "It produces several OBJ files to display principal " << std::endl
119 << "curvatures and directions estimations: `example-cnc-K1.obj`" << std::endl
120 << "`example-cnc-K2.obj`, `example-cnc-D1.obj`, and" << std::endl
121 << "`example-cnc-D2.obj` as well as associated MTL files." << std::endl;
122}