DGtal 2.1.0
Loading...
Searching...
No Matches
shortcuts-geometry.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "ConfigExamples.h"
33#include "DGtal/helpers/StdDefs.h"
34#include "DGtal/helpers/Shortcuts.h"
35#include "DGtal/helpers/ShortcutsGeometry.h"
36#include "DGtal/base/Common.h"
37
38#if DGTAL_WITH_POLYSCOPE
39#include "DGtal/io/viewers/PolyscopeViewer.h"
40#endif
42
43using namespace std;
44using namespace DGtal;
45
47
48int main( int /* argc */, char** /* argv */ )
49{
50 unsigned int nb = 0, nbok = 0;
51 // 3d tests
54
55 trace.beginBlock ( "Load vol file -> build digital surface -> estimate mean curvature -> save OBJ." );
56 {
58 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
59 params( "colormap", "Tics" );
60 auto bimage = SH3::makeBinaryImage( examplesPath + "samples/Al.100.vol", params );
61 auto K = SH3::getKSpace( bimage, params );
62 auto surface = SH3::makeDigitalSurface( bimage, K, params );
63 auto surfels = SH3::getSurfelRange( surface, params );
64 auto curv = SHG3::getIIMeanCurvatures( bimage, surfels, params );
65 // To get Gauss curvatures, write instead:
66 // auto curv = SHG3::getIIGaussianCurvatures( bimage, surfels, params );
67 auto cmap = SH3::getColorMap( -0.5, 0.5, params );
68 auto colors = SH3::Colors( surfels.size() );
69 std::transform( curv.cbegin(), curv.cend(), colors.begin(), cmap );
70 bool ok = SH3::saveOBJ( surface, SH3::RealVectors(), colors,
71 "al-H-II.obj" );
73 ++nb; nbok += ok ? 1 : 0;
74 }
76
77 trace.beginBlock ( "Load vol file -> build digital surface -> estimate Gauss curvature -> save OBJ." );
78 {
79 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
80 params( "colormap", "Tics" );
81 auto bimage = SH3::makeBinaryImage( examplesPath + "samples/Al.100.vol", params );
82 auto K = SH3::getKSpace( bimage, params );
83 auto surface = SH3::makeDigitalSurface( bimage, K, params );
84 auto surfels = SH3::getSurfelRange( surface, params );
85 auto curv = SHG3::getIIGaussianCurvatures( bimage, surfels, params );
86 auto cmap = SH3::getColorMap( -0.25, 0.25, params );
87 auto colors = SH3::Colors( surfels.size() );
88 std::transform( curv.cbegin(), curv.cend(), colors.begin(), cmap );
89 bool ok = SH3::saveOBJ( surface, SH3::RealVectors(), colors,
90 "al-G-II.obj" );
91 ++nb; nbok += ok ? 1 : 0;
92 }
94
95 trace.beginBlock ( "Build polynomial shape -> digitize -> extract ground-truth geometry." );
96 {
97 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
99 params( "polynomial", "3*x^2+2*y^2+z^2-90" )( "gridstep", 0.25 );
100 auto implicit_shape = SH3::makeImplicitShape3D ( params );
101 auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
102 auto binary_image = SH3::makeBinaryImage ( digitized_shape, params );
103 auto K = SH3::getKSpace( params );
104 auto surface = SH3::makeLightDigitalSurface( binary_image, K, params );
105 auto surfels = SH3::getSurfelRange( surface, params );
106 auto positions = SHG3::getPositions( implicit_shape, K, surfels, params );
107 auto normals = SHG3::getNormalVectors( implicit_shape, K, surfels, params );
108 auto mean_curvs = SHG3::getMeanCurvatures( implicit_shape, K, surfels, params );
109 auto gauss_curvs = SHG3::getGaussianCurvatures( implicit_shape, K, surfels, params );
111 auto stat_mean = SHG3::getStatistic( mean_curvs );
112 auto stat_gauss = SHG3::getStatistic( gauss_curvs );
113 trace.info() << " min(H)=" << stat_mean.min()
114 << " avg(H)=" << stat_mean.mean()
115 << " max(H)=" << stat_mean.max() << std::endl;
116 trace.info() << " min(G)=" << stat_gauss.min()
117 << " avg(G)=" << stat_gauss.mean()
118 << " max(G)=" << stat_gauss.max() << std::endl;
119 ++nb; nbok += positions.size() == surfels.size() ? 1 : 0;
120 ++nb; nbok += normals.size() == surfels.size() ? 1 : 0;
121 ++nb; nbok += mean_curvs.size() == surfels.size() ? 1 : 0;
122 ++nb; nbok += gauss_curvs.size() == surfels.size() ? 1 : 0;
123 ++nb; nbok += stat_mean.min() > 0.08 ? 1 : 0;
124 ++nb; nbok += stat_gauss.min() > 0.0064 ? 1 : 0;
125 }
126 trace.endBlock();
127
128 trace.beginBlock ( "Build polynomial shape -> digitize -> get pointels -> save projected quadrangulated surface." );
129 {
130 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
132 const double h = 0.25;
133 params( "polynomial", "goursat" )( "gridstep", h );
134 auto implicit_shape = SH3::makeImplicitShape3D ( params );
135 auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
136 auto binary_image = SH3::makeBinaryImage ( digitized_shape, params );
137 auto K = SH3::getKSpace( params );
138 auto embedder = SH3::getCellEmbedder( K );
139 auto surface = SH3::makeLightDigitalSurface( binary_image, K, params );
140 SH3::Cell2Index c2i;
141 auto pointels = SH3::getPointelRange( c2i, surface );
142 SH3::RealPoints pos( pointels.size() );
143 std::transform( pointels.cbegin(), pointels.cend(), pos.begin(),
144 [&] (const SH3::Cell& c) { return h * embedder( c ); } );
145 auto ppos = SHG3::getPositions( implicit_shape, pos, params );
146 bool ok = SH3::saveOBJ( surface,
147 [&] (const SH3::Cell& c){ return ppos[ c2i[ c ] ];},
148 SH3::RealVectors(), SH3::Colors(),
149 "goursat-quad-proj.obj" );
151 ++nb; nbok += ok ? 1 : 0;
152 }
153 trace.endBlock();
154
155 trace.beginBlock ( "Build polynomial shape -> digitize -> extract mean curvature -> save as OBJ with colors." );
156 {
157 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
159 params( "polynomial", "goursat" )( "gridstep", 0.25 )( "colormap", "Tics" );
160 auto implicit_shape = SH3::makeImplicitShape3D ( params );
161 auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
162 auto binary_image = SH3::makeBinaryImage ( digitized_shape, params );
163 auto K = SH3::getKSpace( params );
164 auto surface = SH3::makeLightDigitalSurface( binary_image, K, params );
165 auto surfels = SH3::getSurfelRange( surface, params );
166 auto mean_curv = SHG3::getMeanCurvatures( implicit_shape, K, surfels, params );
167 auto cmap = SH3::getColorMap( -0.3, 0.3, params );
168 auto colors = SH3::Colors( surfels.size() );
169 std::transform( mean_curv.cbegin(), mean_curv.cend(), colors.begin(), cmap );
170 bool ok = SH3::saveOBJ( surface, SH3::RealVectors(), colors,
171 "goursat-H.obj" );
173 ++nb; nbok += ok ? 1 : 0;
174 }
175 trace.endBlock();
176
177 trace.beginBlock ( "Build polynomial shape -> digitize -> extract ground-truth and estimated mean curvature -> display errors in OBJ with colors." );
178 {
179 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
181 params( "polynomial", "goursat" )( "gridstep", 0.25 )( "colormap", "Tics" )
182 ( "R-radius", 5.0 );
183 auto implicit_shape = SH3::makeImplicitShape3D ( params );
184 auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
185 auto bimage = SH3::makeBinaryImage ( digitized_shape, params );
186 auto K = SH3::getKSpace( params );
187 auto surface = SH3::makeLightDigitalSurface( bimage, K, params );
188 auto surfels = SH3::getSurfelRange( surface, params );
189 auto t_curv = SHG3::getMeanCurvatures( implicit_shape, K, surfels, params );
190 auto ii_curv = SHG3::getIIMeanCurvatures( bimage, surfels, params );
191 auto cmap = SH3::getColorMap( -0.5, 0.5, params );
192 auto colors = SH3::Colors( surfels.size() );
193 std::transform( t_curv.cbegin(), t_curv.cend(), colors.begin(), cmap );
194 bool ok_t = SH3::saveOBJ( surface, SH3::RealVectors(), colors, "goursat-H.obj" );
195 std::transform( ii_curv.cbegin(), ii_curv.cend(), colors.begin(), cmap );
196 bool ok_ii = SH3::saveOBJ( surface, SH3::RealVectors(), colors, "goursat-H-ii.obj" );
197 auto errors = SHG3::getScalarsAbsoluteDifference( t_curv, ii_curv );
198 auto stat_errors = SHG3::getStatistic( errors );
199 auto cmap_errors = SH3::getColorMap( 0.0, stat_errors.max(), params );
200 std::transform( errors.cbegin(), errors.cend(), colors.begin(), cmap_errors );
201 bool ok_err = SH3::saveOBJ( surface, SH3::RealVectors(), colors, "goursat-H-ii-err.obj" );
202 trace.info() << "Error Loo=" << SHG3::getScalarsNormLoo( t_curv, ii_curv )
203 << " L1=" << SHG3::getScalarsNormL1 ( t_curv, ii_curv )
204 << " L2=" << SHG3::getScalarsNormL2 ( t_curv, ii_curv )
205 << std::endl;
207 ++nb; nbok += ( ok_t && ok_ii && ok_err ) ? 1 : 0;
208 }
209 trace.endBlock();
210
211 trace.beginBlock ( "Build polynomial shape -> digitize -> build digital surface -> save primal surface with VCM normals as obj." );
212 {
213 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
215 params( "polynomial", "goursat" )( "gridstep", 0.25 )
216 ( "surfaceTraversal", "Default" );
217 auto implicit_shape = SH3::makeImplicitShape3D ( params );
218 auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
219 auto K = SH3::getKSpace( params );
220 auto binary_image = SH3::makeBinaryImage( digitized_shape, params );
221 auto surface = SH3::makeDigitalSurface( binary_image, K, params );
222 auto surfels = SH3::getSurfelRange( surface, params );
223 auto vcm_normals = SHG3::getVCMNormalVectors( surface, surfels, params );
224 bool ok = SH3::saveOBJ( surface, vcm_normals, SH3::Colors(),
225 "goursat-primal-vcm.obj" );
227 ++nb; nbok += ok ? 1 : 0;
228 }
229 trace.endBlock();
230
231 trace.beginBlock ( "Build polynomial shape -> digitize implicitly -> estimate II normals and curvature." );
232 {
233 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
235 params( "polynomial", "goursat" )( "gridstep", .25 );
236 auto implicit_shape = SH3::makeImplicitShape3D ( params );
237 auto dig_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
238 auto K = SH3::getKSpace ( params );
239 auto surface = SH3::makeDigitalSurface ( dig_shape, K, params );
240 auto surfels = SH3::getSurfelRange ( surface, params( "surfaceTraversal", "DepthFirst" ) );
241 auto def_surfels = SH3::getSurfelRange ( surface, params( "surfaceTraversal", "Default" ) );
242 auto ii_normals = SHG3::getIINormalVectors ( dig_shape, surfels, params );
243 trace.beginBlock( "II with default traversal (slower)" );
244 auto ii_mean_curv = SHG3::getIIMeanCurvatures ( dig_shape, def_surfels, params );
245 trace.endBlock();
246 trace.beginBlock( "II with depth-first traversal (faster)" );
247 auto ii_mean_curv2 = SHG3::getIIMeanCurvatures ( dig_shape, surfels, params );
248 trace.endBlock();
249 auto cmap = SH3::getColorMap ( -0.5, 0.5, params );
250 auto colors = SH3::Colors ( def_surfels.size() );
251 auto match = SH3::getRangeMatch ( def_surfels, surfels );
252 auto normals = SH3::getMatchedRange ( ii_normals, match );
253 for ( SH3::Idx i = 0; i < colors.size(); i++ )
254 colors[ i ] = cmap( ii_mean_curv[ match[ i ] ] );
255 bool ok_H = SH3::saveOBJ( surface, SH3::RealVectors(), colors, "goursat-imp-H-ii.obj" );
257 ++nb; nbok += ( ok_H && ii_mean_curv.size() == ii_mean_curv2.size() ) ? 1 : 0;
258 }
259 trace.endBlock();
260
261 trace.beginBlock ( "Build polynomial shape -> save several projected quadrangulated surface and digitized boundaries." );
262 {
263 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
264 std::vector<double> gridsteps {0.5, 0.25, 0.125};
265 for ( auto h : gridsteps ) {
266 params( "polynomial", "goursat" )( "gridstep", h );
267 auto implicit_shape = SH3::makeImplicitShape3D ( params );
268 auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
269 auto binary_image = SH3::makeBinaryImage ( digitized_shape, params );
270 auto K = SH3::getKSpace( params );
271 auto embedder = SH3::getCellEmbedder( K );
272 auto surface = SH3::makeLightDigitalSurface( binary_image, K, params );
273 SH3::Cell2Index c2i;
274 auto pointels = SH3::getPointelRange( c2i, surface );
275 SH3::RealPoints pos( pointels.size() );
276 std::transform( pointels.cbegin(), pointels.cend(), pos.begin(),
277 [&] (const SH3::Cell& c) { return h * embedder( c ); } );
278 auto ppos = SHG3::getPositions( implicit_shape, pos, params );
279 auto fname = std::string( "goursat-quad-" ) + std::to_string( h ) + std::string( ".obj" );
280 bool ok = SH3::saveOBJ( surface,
281 [&] (const SH3::Cell& c){ return pos[ c2i[ c ] ];},
282 SH3::RealVectors(), SH3::Colors(),
283 fname );
284 auto proj_fname = std::string( "goursat-quad-proj-" ) + std::to_string( h ) + std::string( ".obj" );
285 bool proj_ok = SH3::saveOBJ( surface,
286 [&] (const SH3::Cell& c){ return ppos[ c2i[ c ] ];},
287 SH3::RealVectors(), SH3::Colors(),
288 proj_fname );
289 ++nb; nbok += ok ? 1 : 0;
290 ++nb; nbok += proj_ok ? 1 : 0;
291 }
292 }
293 trace.endBlock();
294
295 trace.beginBlock ( "Build polynomial shape -> digitize -> digital surface -> save primal surface and VCM normal field as obj." );
296 {
297 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
299 params( "polynomial", "goursat" )( "gridstep", 0.5 )
300 ( "surfaceTraversal", "Default" );
301 auto implicit_shape = SH3::makeImplicitShape3D ( params );
302 auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
303 auto K = SH3::getKSpace( params );
304 auto binary_image = SH3::makeBinaryImage( digitized_shape, params );
305 auto surface = SH3::makeDigitalSurface( binary_image, K, params );
306 auto surfels = SH3::getSurfelRange( surface, params );
307 auto vcm_normals = SHG3::getVCMNormalVectors( surface, surfels, params );
308 auto embedder = SH3::getSCellEmbedder( K );
309 SH3::RealPoints positions( surfels.size() );
310 std::transform( surfels.cbegin(), surfels.cend(), positions.begin(),
311 [&] (const SH3::SCell& c) { return embedder( c ); } );
312 bool ok = SH3::saveOBJ( surface, vcm_normals, SH3::Colors(),
313 "goursat-primal-vcm.obj" );
314 bool ok2 = SH3::saveVectorFieldOBJ( positions, vcm_normals, 0.05, SH3::Colors(),
315 "goursat-primal-vcm-normals.obj",
316 SH3::Color( 0, 0, 0 ), SH3::Color::Red );
318 ++nb, nbok += ok ? 1 : 0;
319 ++nb, nbok += ok2 ? 1 : 0;
320 }
321 trace.endBlock();
322
323 trace.beginBlock ( "Build polynomial shape -> digitize -> extract ground-truth curvatures -> display in OBJ." );
324 {
325 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
327 params( "polynomial", "goursat" )( "gridstep", 0.25 )( "colormap", "Tics" );
328 auto implicit_shape = SH3::makeImplicitShape3D ( params );
329 auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
330 auto bimage = SH3::makeBinaryImage ( digitized_shape, params );
331 auto K = SH3::getKSpace( params );
332 auto surface = SH3::makeLightDigitalSurface( bimage, K, params );
333 auto surfels = SH3::getSurfelRange( surface, params );
334 auto k1 = SHG3::getFirstPrincipalCurvatures( implicit_shape, K, surfels, params );
335 auto k2 = SHG3::getSecondPrincipalCurvatures( implicit_shape, K, surfels, params );
336 auto d1 = SHG3::getFirstPrincipalDirections( implicit_shape, K, surfels, params );
337 auto d2 = SHG3::getSecondPrincipalDirections( implicit_shape, K, surfels, params );
338 auto embedder = SH3::getSCellEmbedder( K );
339 SH3::RealPoints positions( surfels.size() );
340 std::transform( surfels.cbegin(), surfels.cend(), positions.begin(),
341 [&] (const SH3::SCell& c) { return embedder( c ); } );
342 SH3::saveOBJ( surface, SH3::RealVectors(), SH3::Colors(),
343 "goursat-primal.obj" );
344 // output principal curvatures and directions
345 auto cmap = SH3::getColorMap( -0.5, 0.5, params );
346 auto colors= SH3::Colors( surfels.size() );
347 std::transform( k1.cbegin(), k1.cend(), colors.begin(), cmap );
348 bool ok_k1 = SH3::saveOBJ( surface, SH3::RealVectors(), colors, "goursat-primal-k1.obj" );
349 bool ok_d1 = SH3::saveVectorFieldOBJ( positions, d1, 0.05, colors,
350 "goursat-primal-d1.obj", SH3::Color::Black );
351 std::transform( k2.cbegin(), k2.cend(), colors.begin(), cmap );
352 bool ok_k2 = SH3::saveOBJ( surface, SH3::RealVectors(), colors, "goursat-primal-k2.obj" );
353 bool ok_d2 = SH3::saveVectorFieldOBJ( positions, d2, 0.05, colors,
354 "goursat-primal-d2.obj", SH3::Color::Black );
355 ASSERT(ok_k1 && ok_d1 && ok_k2 && ok_d2);
357 }
358 trace.endBlock();
359
360 trace.beginBlock( "Load mesh file -> estimate mean/gaussian/principal curvatures -> display in obj" );
361 {
363 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
364 params("r-radius", 0.1);
365
366 auto mesh = SH3::makeSurfaceMesh(examplesPath + "samples/bunnyhead2.obj");
367
368 auto mcurv = SHG3::getCNCMeanCurvatures(mesh, params);
369 auto gcurv = SHG3::getCNCGaussianCurvatures(mesh, params);
370 auto [k1, k2, d1, d2] = SHG3::getCNCPrincipalCurvaturesAndDirections(mesh);
371 auto cmap = SH3::getColorMap( -1, 1, params );
372
373 auto mcolors = SH3::Colors( mcurv.size() );
374 std::transform( mcurv.cbegin(), mcurv.cend(), mcolors.begin(), cmap );
375
376 auto gcolors = SH3::Colors( gcurv.size() );
377 std::transform( gcurv.cbegin(), gcurv.cend(), gcolors.begin(), cmap );
378
379 auto k1colors = SH3::Colors( k1.size() );
380 std::transform( k1.begin(), k1.end(), k1colors.begin(), cmap);
381
382 auto k2colors = SH3::Colors( k2.size() );
383 std::transform( k2.begin(), k2.end(), k2colors.begin(), cmap);
384
385 bool ok_m = SH3::saveOBJ( mesh, SH3::RealVectors(), mcolors, "bunnyhead2-meanCurvature.obj" );
386 bool ok_g = SH3::saveOBJ( mesh, SH3::RealVectors(), gcolors, "bunnyhead2-gaussianCurvature.obj" );
387 bool ok_k1 = SH3::saveOBJ( mesh, SH3::RealVectors(), k1colors, "bunnyhead2-firstPrincipalCurvature.obj" );
388 bool ok_k2 = SH3::saveOBJ( mesh, SH3::RealVectors(), k2colors, "bunnyhead2-secondPrincpalCurvature.obj" );
390
391 ++nb; nbok += ok_m;
392 ++nb; nbok += ok_g;
393 ++nb; nbok += ok_k1;
394 ++nb; nbok += ok_k2;
395 }
396 trace.endBlock();
397
398#if defined(DGTAL_WITH_EIGEN)
399 trace.beginBlock ( "Load vol file -> build main digital surface -> II normals -> AT regularization -> save OBJ with colored normals." );
400 {
401 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
403 auto al_capone = SH3::makeBinaryImage( examplesPath + "samples/Al.100.vol", params );
404 auto K = SH3::getKSpace( al_capone );
405 auto surface = SH3::makeLightDigitalSurface( al_capone, K, params );
406 auto surfels = SH3::getSurfelRange( surface, params );
407 auto ii_normals = SHG3::getIINormalVectors( al_capone, surfels, params );
408 auto linels = SH3::getCellRange( surface, 1 );
409 auto uembedder = SH3::getCellEmbedder( K );
410 SH3::Scalars features( linels.size() );
411 auto at_normals = SHG3::getATVectorFieldApproximation( features, linels.cbegin(), linels.cend(),
412 surface, surfels,
413 ii_normals, params );
414 // Output normals as colors depending on directions
415 SH3::Colors colors( surfels.size() );
416 for ( size_t i = 0; i < surfels.size(); i++ )
417 colors[ i ] = SH3::Color( (unsigned char) 255.0*fabs( at_normals[ i ][ 0 ] ),
418 (unsigned char) 255.0*fabs( at_normals[ i ][ 1 ] ),
419 (unsigned char) 255.0*fabs( at_normals[ i ][ 2 ] ) );
420 bool ok1 = SH3::saveOBJ( surface, SH3::RealVectors(), SH3::Colors(), "al-surface.obj" );
421 bool ok2 = SH3::saveOBJ( surface, at_normals, colors, "al-colored-at-normals.obj" );
422 // Output discontinuities as sticks on linels.
423 SH3::RealPoints f0;
424 SH3::RealVectors f1;
425 for ( size_t i = 0; i < linels.size(); i++ )
426 {
427 if ( features[ i ] < 0.5 )
428 {
429 const SH3::Cell linel = linels[ i ];
430 const Dimension d = * K.uDirs( linel );
431 const SH3::Cell p0 = K.uIncident( linel, d, false );
432 const SH3::Cell p1 = K.uIncident( linel, d, true );
433 f0.push_back( uembedder( p0 ) );
434 f1.push_back( uembedder( p1 ) - uembedder( p0 ) );
435 }
436 }
437 bool ok3 = SH3::saveVectorFieldOBJ( f0, f1, 0.1, SH3::Colors(),
438 "al-features.obj",
439 SH3::Color( 0, 0, 0 ), SH3::Color::Red );
441 ++nb; nbok += ok1 ? 1 : 0;
442 ++nb; nbok += ok2 ? 1 : 0;
443 ++nb; nbok += ok3 ? 1 : 0;
444 }
445 trace.endBlock();
446
447#endif // defined(WITH_EIGEN)
448
449#if DGTAL_WITH_POLYSCOPE
450 trace.beginBlock( "Load vol file -> Compute VoronoiMap -> Display in Viewer" );
451 {
452 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
454 auto bimage = SH3::makeBinaryImage( examplesPath + "samples/Al.100.vol", params );
455 auto domain = bimage->domain();
456
457 // Extract points location
458 std::vector<SH3::Point> sites;
459 std::copy_if(domain.begin(),
460 domain.end(),
461 std::back_inserter(sites),
462 *bimage);
463
464 // Compute VoronoiMap and get distances from sites
465 auto vmap1 = SHG3::getDistanceTransformation<1>(bimage->domain(), sites, params);
466 auto vmap2 = SHG3::getDistanceTransformation<2>(bimage->domain(), sites, params);
467
468 PolyscopeViewer<> viewer;
469 viewer.newCubeList("VoronoiMap distance");
470 viewer.allowReuseList = true;
471
472 for (auto it = domain.begin(); it != domain.end(); ++it)
473 {
474 viewer << WithQuantity(
475 WithQuantity(*it,
476 "L1 distance", vmap1(*it)
477 ), "L2 distance", vmap2(*it)
478 );
479 }
480
481 viewer.show();
483 nb ++;
484 nbok ++;
485 }
486 trace.endBlock();
487#endif // DGTAL_WITH_POLYSCOPE
488
489 trace.info() << nbok << "/" << nb << " passed tests." << std::endl;
490 return 0;
491}
492// //
std::string newCubeList(const std::string &name)
Definition Display3D.h:535
const ConstIterator & begin() const
const ConstIterator & end() const
Cell uIncident(const Cell &c, Dimension k, bool up) const
Return the forward or backward unsigned cell incident to [c] along axis [k], depending on [up].
DirIterator uDirs(const Cell &p) const
Given an unsigned cell [p], returns an iterator to iterate over each coordinate the cell spans.
void show() override
Starts the event loop and display of elements.
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:102
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
CountedPtr< SH3::DigitalSurface > surface
CountedPtr< SH3::BinaryImage > binary_image
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension
Definition Common.h:119
Trace trace
STL namespace.
Attach a property to an element.
Definition Display3D.h:331
Shortcuts< KSpace > SH3
int main()
Definition testBits.cpp:56
KSpace K
ShortcutsGeometry< Z3i::KSpace > SHG3
Domain domain