DGtal 2.1.1
Loading...
Searching...
No Matches
testIntegralInvariantShortcuts.cpp File Reference
#include <iostream>
#include <vector>
#include "DGtal/base/Common.h"
#include "ConfigTest.h"
#include "DGtalCatch.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/helpers/Shortcuts.h"
#include "DGtal/helpers/ShortcutsGeometry.h"
Include dependency graph for testIntegralInvariantShortcuts.cpp:

Go to the source code of this file.

Typedefs

typedef Shortcuts< Z3i::KSpaceSH3
 
typedef ShortcutsGeometry< Z3i::KSpaceSHG3
 

Functions

 TEST_CASE ("Testing IntegralInvariant Shortcuts API")
 

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
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systemes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2020/03/14

Functions for testing class IntegralInvariantShortcuts.

This file is part of the DGtal library.

Definition in file testIntegralInvariantShortcuts.cpp.

Typedef Documentation

◆ SH3

typedef Shortcuts<Z3i::KSpace> SH3

Definition at line 46 of file testIntegralInvariantShortcuts.cpp.

◆ SHG3

Function Documentation

◆ TEST_CASE()

TEST_CASE ( "Testing IntegralInvariant Shortcuts API"  )

Definition at line 53 of file testIntegralInvariantShortcuts.cpp.

54{
55 auto params = SH3::defaultParameters() | SHG3::defaultParameters() | SHG3::parametersGeometryEstimation();
56 params( "polynomial", "goursat" )( "gridstep", 1. );
57 auto implicit_shape = SH3::makeImplicitShape3D ( params );
58 auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
59 auto binary_image = SH3::makeBinaryImage( digitized_shape, params );
60 auto K = SH3::getKSpace( params );
61 auto embedder = SH3::getCellEmbedder( K );
62 auto surface = SH3::makeLightDigitalSurface( binary_image, K, params );
63 auto surfels = SH3::getSurfelRange( surface, params );
64
65 trace.info() << "Nb surfels= " << surfels.size() << std::endl;
66
67 //Computing some differential quantities
68 params("r-radius", 3.0);
69
70 //We compute the curvature tensor, the mean and the Gaussian curvature
71 auto Hcurv = SHG3::getIIMeanCurvatures( binary_image, surfels, params );
72 auto Tcurv = SHG3::getIIPrincipalCurvaturesAndDirections(binary_image, surfels, params);
73 auto Kcurv = SHG3::getIIGaussianCurvatures( binary_image, surfels, params);
74 auto Ncurv = SHG3::getIINormalVectors( binary_image, surfels, params );
75
76 auto params_parallel = params;
77 params_parallel( "ii-thread-number", 4 )( "ii-split-axis", 2 );
78 auto HcurvParallel = SHG3::getIIMeanCurvatures( binary_image, surfels, params_parallel );
79 auto TcurvParallel = SHG3::getIIPrincipalCurvaturesAndDirections( binary_image, surfels, params_parallel );
80 auto KcurvParallel = SHG3::getIIGaussianCurvatures( binary_image, surfels, params_parallel );
81 auto NcurvParallel = SHG3::getIINormalVectors( binary_image, surfels, params_parallel );
82
83 std::vector<double> k1,k2,G;
84 for(auto &result: Tcurv)
85 {
86 k1.push_back( std::get<0>(result) );
87 k2.push_back( std::get<1>(result) );
88 G.push_back( ( std::get<0>(result) * std::get<1>(result)) );
89 }
90
91 SECTION("Testing that mean/Gaussian/tensor curvature shortucut values match")
92 {
93 for(std::size_t i = 0; i < G.size(); ++i)
94 REQUIRE( Kcurv[i] == Approx( G[i] ) );
95 }
96
97 SECTION("Testing that requesting the parallel II shortcut preserves curvature values")
98 {
99 REQUIRE( HcurvParallel.size() == Hcurv.size() );
100 REQUIRE( KcurvParallel.size() == Kcurv.size() );
101 REQUIRE( TcurvParallel.size() == Tcurv.size() );
102
103 for ( std::size_t i = 0; i < Hcurv.size(); ++i )
104 REQUIRE( HcurvParallel[ i ] == Approx( Hcurv[ i ] ) );
105
106 for ( std::size_t i = 0; i < Kcurv.size(); ++i )
107 REQUIRE( KcurvParallel[ i ] == Approx( Kcurv[ i ] ) );
108
109 for ( std::size_t i = 0; i < Tcurv.size(); ++i )
110 {
111 REQUIRE( std::get<0>( TcurvParallel[ i ] ) == Approx( std::get<0>( Tcurv[ i ] ) ) );
112 REQUIRE( std::get<1>( TcurvParallel[ i ] ) == Approx( std::get<1>( Tcurv[ i ] ) ) );
113 }
114 }
115
116 SECTION("Testing that requesting the parallel II shortcut preserves normal vectors")
117 {
118 REQUIRE( NcurvParallel.size() == Ncurv.size() );
119
120 for ( std::size_t i = 0; i < Ncurv.size(); ++i )
121 for ( std::size_t d = 0; d < 3; ++d )
122 REQUIRE( NcurvParallel[ i ][ d ] == Approx( Ncurv[ i ][ d ] ) );
123 }
124
125 SECTION("Testing that ii-split-axis accepts out-of-range values by clamping to a valid axis")
126 {
127 auto params_parallel_clamped = params;
128 params_parallel_clamped( "ii-thread-number", 4 )( "ii-split-axis", 9 );
129 auto HcurvParallelClamped = SHG3::getIIMeanCurvatures( binary_image, surfels, params_parallel_clamped );
130
131 REQUIRE( HcurvParallelClamped.size() == Hcurv.size() );
132 for ( std::size_t i = 0; i < Hcurv.size(); ++i )
133 REQUIRE( HcurvParallelClamped[ i ] == Approx( Hcurv[ i ] ) );
134 }
135
136 SECTION("Testing on shifted domains")
137 {
138 auto SHIFT=512;
139 auto domain = binary_image->domain();
141
142 SH3::KSpace Ks;
143 Ks.init( shifted.lowerBound(), shifted.upperBound(), true );
144
145 CountedPtr<SH3::BinaryImage> binary_image_shifted(new SH3::BinaryImage(shifted));
146 for(auto p : binary_image->domain())
147 binary_image_shifted->setValue(p+Z3i::Point::diagonal(SHIFT), binary_image->operator()(p));
148
149 auto surfaceShifted = SH3::makeLightDigitalSurface( binary_image_shifted, Ks, params );
150 auto surfelsShifted = SH3::getSurfelRange( surfaceShifted, params );
151 trace.info() << "Nb surfels= " << surfels.size() << " "<<shifted<<" "<<Ks<<std::endl;
152
153 //Computing some differential quantities
154 auto KcurvShifted = SHG3::getIIGaussianCurvatures( binary_image_shifted, surfelsShifted, params);
155
156
157 }
158}
Aim: Smart pointer based on reference counts.
Definition CountedPtr.h:80
const Point & lowerBound() const
const Point & upperBound() const
static Self diagonal(Component val=1)
std::ostream & info()
CountedPtr< SH3::DigitalSurface > surface
CountedPtr< SH3::BinaryImage > binary_image
DGtal::LinearOperator< Calculus, dim, duality, dim, duality > diagonal(const DGtal::KForm< Calculus, dim, duality > &kform)
Trace trace
KSpace K
Domain domain
SECTION("Testing constant forward iterators")
REQUIRE(domain.isInside(aPoint))

References binary_image, DGtal::PointVector< dim, Integer >::diagonal(), domain, DGtal::Trace::info(), K, DGtal::HyperRectDomain< TSpace >::lowerBound(), REQUIRE(), SECTION(), surface, DGtal::trace, and DGtal::HyperRectDomain< TSpace >::upperBound().