49{
50 unsigned int nb = 0, nbok = 0;
51
54
55 trace.beginBlock (
"Load vol file -> build digital surface -> estimate mean curvature -> save OBJ." );
56 {
59 params( "colormap", "Tics" );
65
66
69 std::transform( curv.cbegin(), curv.cend(), colors.begin(), cmap );
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 {
80 params( "colormap", "Tics" );
88 std::transform( curv.cbegin(), curv.cend(), colors.begin(), cmap );
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 {
99 params( "polynomial", "3*x^2+2*y^2+z^2-90" )( "gridstep", 0.25 );
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 }
127
128 trace.beginBlock (
"Build polynomial shape -> digitize -> get pointels -> save projected quadrangulated surface." );
129 {
132 const double h = 0.25;
133 params( "polynomial", "goursat" )( "gridstep", h );
143 std::transform( pointels.cbegin(), pointels.cend(), pos.begin(),
144 [&] (
const SH3::Cell& c) { return h * embedder( c ); } );
147 [&] (
const SH3::Cell& c){
return ppos[ c2i[ c ] ];},
149 "goursat-quad-proj.obj" );
151 ++nb; nbok += ok ? 1 : 0;
152 }
154
155 trace.beginBlock (
"Build polynomial shape -> digitize -> extract mean curvature -> save as OBJ with colors." );
156 {
159 params( "polynomial", "goursat" )( "gridstep", 0.25 )( "colormap", "Tics" );
169 std::transform( mean_curv.cbegin(), mean_curv.cend(), colors.begin(), cmap );
171 "goursat-H.obj" );
173 ++nb; nbok += ok ? 1 : 0;
174 }
176
177 trace.beginBlock (
"Build polynomial shape -> digitize -> extract ground-truth and estimated mean curvature -> display errors in OBJ with colors." );
178 {
181 params( "polynomial", "goursat" )( "gridstep", 0.25 )( "colormap", "Tics" )
182 ( "R-radius", 5.0 );
193 std::transform( t_curv.cbegin(), t_curv.cend(), colors.begin(), cmap );
195 std::transform( ii_curv.cbegin(), ii_curv.cend(), colors.begin(), cmap );
200 std::transform( errors.cbegin(), errors.cend(), colors.begin(), cmap_errors );
205 << std::endl;
207 ++nb; nbok += ( ok_t && ok_ii && ok_err ) ? 1 : 0;
208 }
210
211 trace.beginBlock (
"Build polynomial shape -> digitize -> build digital surface -> save primal surface with VCM normals as obj." );
212 {
215 params( "polynomial", "goursat" )( "gridstep", 0.25 )
216 ( "surfaceTraversal", "Default" );
225 "goursat-primal-vcm.obj" );
227 ++nb; nbok += ok ? 1 : 0;
228 }
230
231 trace.beginBlock (
"Build polynomial shape -> digitize implicitly -> estimate II normals and curvature." );
232 {
235 params( "polynomial", "goursat" )( "gridstep", .25 );
243 trace.beginBlock(
"II with default traversal (slower)" );
246 trace.beginBlock(
"II with depth-first traversal (faster)" );
253 for (
SH3::Idx i = 0; i < colors.size(); i++ )
254 colors[ i ] = cmap( ii_mean_curv[ match[ i ] ] );
257 ++nb; nbok += ( ok_H && ii_mean_curv.size() == ii_mean_curv2.size() ) ? 1 : 0;
258 }
260
261 trace.beginBlock (
"Build polynomial shape -> save several projected quadrangulated surface and digitized boundaries." );
262 {
264 std::vector<double> gridsteps {0.5, 0.25, 0.125};
265 for ( auto h : gridsteps ) {
266 params( "polynomial", "goursat" )( "gridstep", h );
276 std::transform( pointels.cbegin(), pointels.cend(), pos.begin(),
277 [&] (
const SH3::Cell& c) { return h * embedder( c ); } );
279 auto fname = std::string( "goursat-quad-" ) + std::to_string( h ) + std::string( ".obj" );
281 [&] (
const SH3::Cell& c){
return pos[ c2i[ c ] ];},
283 fname );
284 auto proj_fname = std::string( "goursat-quad-proj-" ) + std::to_string( h ) + std::string( ".obj" );
286 [&] (
const SH3::Cell& c){
return ppos[ c2i[ c ] ];},
288 proj_fname );
289 ++nb; nbok += ok ? 1 : 0;
290 ++nb; nbok += proj_ok ? 1 : 0;
291 }
292 }
294
295 trace.beginBlock (
"Build polynomial shape -> digitize -> digital surface -> save primal surface and VCM normal field as obj." );
296 {
299 params( "polynomial", "goursat" )( "gridstep", 0.5 )
300 ( "surfaceTraversal", "Default" );
310 std::transform( surfels.cbegin(), surfels.cend(), positions.begin(),
311 [&] (
const SH3::SCell& c) { return embedder( c ); } );
313 "goursat-primal-vcm.obj" );
315 "goursat-primal-vcm-normals.obj",
318 ++nb, nbok += ok ? 1 : 0;
319 ++nb, nbok += ok2 ? 1 : 0;
320 }
322
323 trace.beginBlock (
"Build polynomial shape -> digitize -> extract ground-truth curvatures -> display in OBJ." );
324 {
327 params( "polynomial", "goursat" )( "gridstep", 0.25 )( "colormap", "Tics" );
340 std::transform( surfels.cbegin(), surfels.cend(), positions.begin(),
341 [&] (
const SH3::SCell& c) { return embedder( c ); } );
343 "goursat-primal.obj" );
344
347 std::transform( k1.cbegin(), k1.cend(), colors.begin(), cmap );
350 "goursat-primal-d1.obj", SH3::Color::Black );
351 std::transform( k2.cbegin(), k2.cend(), colors.begin(), cmap );
354 "goursat-primal-d2.obj", SH3::Color::Black );
355 ASSERT(ok_k1 && ok_d1 && ok_k2 && ok_d2);
357 }
359
360 trace.beginBlock(
"Load mesh file -> estimate mean/gaussian/principal curvatures -> display in obj" );
361 {
364 params("r-radius", 0.1);
365
367
372
374 std::transform( mcurv.cbegin(), mcurv.cend(), mcolors.begin(), cmap );
375
377 std::transform( gcurv.cbegin(), gcurv.cend(), gcolors.begin(), cmap );
378
380 std::transform( k1.begin(), k1.end(), k1colors.begin(), cmap);
381
383 std::transform( k2.begin(), k2.end(), k2colors.begin(), cmap);
384
390
391 ++nb; nbok += ok_m;
392 ++nb; nbok += ok_g;
393 ++nb; nbok += ok_k1;
394 ++nb; nbok += ok_k2;
395 }
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 {
413 ii_normals, params );
414
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 ] ) );
422
425 for ( size_t i = 0; i < linels.size(); i++ )
426 {
427 if ( features[ i ] < 0.5 )
428 {
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 }
438 "al-features.obj",
441 ++nb; nbok += ok1 ? 1 : 0;
442 ++nb; nbok += ok2 ? 1 : 0;
443 ++nb; nbok += ok3 ? 1 : 0;
444 }
446
447#endif
448
449#if DGTAL_WITH_POLYSCOPE
450 trace.beginBlock(
"Load vol file -> Compute VoronoiMap -> Display in Viewer" );
451 {
455 auto domain = bimage->domain();
456
457
458 std::vector<SH3::Point> sites;
459 std::copy_if(
domain.begin(),
461 std::back_inserter(sites),
462 *bimage);
463
464
467
471
472 for (
auto it =
domain.begin(); it !=
domain.end(); ++it)
473 {
476 "L1 distance", vmap1(*it)
477 ), "L2 distance", vmap2(*it)
478 );
479 }
480
483 nb ++;
484 nbok ++;
485 }
487#endif
488
489 trace.info() << nbok <<
"/" << nb <<
" passed tests." << std::endl;
490 return 0;
491}
std::string newCubeList(const std::string &name)
void show() override
Starts the event loop and display of elements.
static Scalars getIIGaussianCurvatures(CountedPtr< BinaryImage > bimage, const SurfelRange &surfels, const Parameters ¶ms=parametersGeometryEstimation()|parametersKSpace())
static Scalar getScalarsNormL1(const Scalars &v1, const Scalars &v2)
static Scalars getMeanCurvatures(CountedPtr< ImplicitShape3D > shape, const KSpace &K, const SurfelRange &surfels, const Parameters ¶ms=parametersShapeGeometry())
static RealPoints getPositions(CountedPtr< ImplicitShape3D > shape, const KSpace &K, const SurfelRange &surfels, const Parameters ¶ms=parametersShapeGeometry())
static Scalars getCNCGaussianCurvatures(CountedPtr< typename Base::SurfaceMesh > mesh, const typename Base::SurfaceMesh::Faces &faces, const Parameters ¶ms=parametersShapeGeometry())
static RealVectors getIINormalVectors(CountedPtr< BinaryImage > bimage, const SurfelRange &surfels, const Parameters ¶ms=parametersGeometryEstimation()|parametersKSpace())
static Scalars getScalarsAbsoluteDifference(const Scalars &v1, const Scalars &v2)
static RealVectors getNormalVectors(CountedPtr< ImplicitShape3D > shape, const KSpace &K, const SurfelRange &surfels, const Parameters ¶ms=parametersShapeGeometry())
static std::tuple< Scalars, Scalars, RealVectors, RealVectors > getCNCPrincipalCurvaturesAndDirections(CountedPtr< typename Base::SurfaceMesh > mesh, const typename Base::SurfaceMesh::Faces &faces, const Parameters ¶ms=parametersShapeGeometry())
static RealVectors getFirstPrincipalDirections(CountedPtr< ImplicitShape3D > shape, const KSpace &K, const SurfelRange &surfels, const Parameters ¶ms=parametersShapeGeometry())
static RealVectors getSecondPrincipalDirections(CountedPtr< ImplicitShape3D > shape, const KSpace &K, const SurfelRange &surfels, const Parameters ¶ms=parametersShapeGeometry())
static DistanceTransformation< Space, VoronoiPointPredicate, ExactPredicateLpSeparableMetric< Space, p > > getDistanceTransformation(Domain domain, const PointRange &sites, const Parameters ¶ms=parametersVoronoiMap())
static Scalars getCNCMeanCurvatures(CountedPtr< typename Base::SurfaceMesh > mesh, const typename Base::SurfaceMesh::Faces faces, const Parameters ¶ms=parametersShapeGeometry())
static Scalars getIIMeanCurvatures(CountedPtr< BinaryImage > bimage, const SurfelRange &surfels, const Parameters ¶ms=parametersGeometryEstimation()|parametersKSpace())
static Parameters defaultParameters()
static Scalars getGaussianCurvatures(CountedPtr< ImplicitShape3D > shape, const KSpace &K, const SurfelRange &surfels, const Parameters ¶ms=parametersShapeGeometry())
static Scalar getScalarsNormL2(const Scalars &v1, const Scalars &v2)
static Scalars getFirstPrincipalCurvatures(CountedPtr< ImplicitShape3D > shape, const KSpace &K, const SurfelRange &surfels, const Parameters ¶ms=parametersShapeGeometry())
static Scalar getScalarsNormLoo(const Scalars &v1, const Scalars &v2)
static ScalarStatistic getStatistic(const Scalars &v)
static VectorFieldInput getATVectorFieldApproximation(CountedPtr< TAnyDigitalSurface > surface, const SurfelRange &surfels, const VectorFieldInput &input, const Parameters ¶ms=parametersATApproximation()|parametersGeometryEstimation())
static Scalars getSecondPrincipalCurvatures(CountedPtr< ImplicitShape3D > shape, const KSpace &K, const SurfelRange &surfels, const Parameters ¶ms=parametersShapeGeometry())
static RealVectors getVCMNormalVectors(CountedPtr< TAnyDigitalSurface > surface, const SurfelRange &surfels, const Parameters ¶ms=parametersGeometryEstimation())
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
static CountedPtr< DigitizedImplicitShape3D > makeDigitizedImplicitShape3D(CountedPtr< ImplicitShape3D > shape, Parameters params=parametersDigitizedImplicitShape3D())
static CellRange getCellRange(Cell2Index &c2i, CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Dimension k)
static CountedPtr< SurfaceMesh > makeSurfaceMesh(const std::string &path)
std::map< Cell, IdxVertex > Cell2Index
static PointelRange getPointelRange(Cell2Index &c2i, CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface)
std::vector< Color > Colors
static SurfelRange getSurfelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters ¶ms=parametersDigitalSurface())
static CountedPtr< LightDigitalSurface > makeLightDigitalSurface(CountedPtr< BinaryImage > bimage, const KSpace &K, const Parameters ¶ms=parametersDigitalSurface())
static CanonicSCellEmbedder< KSpace > getSCellEmbedder(const KSpace &K)
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters ¶ms=parametersDigitalSurface())
static IdxRange getRangeMatch(const std::vector< TValue > &s1, const std::vector< TValue > &s2, bool perfect=false)
std::vector< RealPoint > RealPoints
std::vector< RealVector > RealVectors
std::vector< Scalar > Scalars
static bool saveVectorFieldOBJ(const RealPoints &positions, const RealVectors &vf, double thickness, const Colors &diffuse_colors, std::string objfile, const Color &ambient_color=Color(32, 32, 32), const Color &diffuse_color=Color(200, 200, 255), const Color &specular_color=Color::White)
static Parameters defaultParameters()
static ColorMap getColorMap(Scalar min, Scalar max, const Parameters ¶ms=parametersUtilities())
static std::vector< TValue > getMatchedRange(const std::vector< TValue > &range, const IdxRange &match)
LightDigitalSurface::SCell SCell
static bool saveOBJ(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > digsurf, const TCellEmbedder &embedder, const RealVectors &normals, const Colors &diffuse_colors, std::string objfile, const Color &ambient_color=Color(32, 32, 32), const Color &diffuse_color=Color(200, 200, 255), const Color &specular_color=Color::White)
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
static CanonicCellEmbedder< KSpace > getCellEmbedder(const KSpace &K)
static CountedPtr< ImplicitShape3D > makeImplicitShape3D(const Parameters ¶ms=parametersImplicitShape3D())
LightDigitalSurface::Cell Cell
CountedPtr< SH3::DigitalSurface > surface
CountedPtr< SH3::BinaryImage > binary_image
DGtal::uint32_t Dimension
Attach a property to an element.
ShortcutsGeometry< Z3i::KSpace > SHG3