DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
testShortestPaths.cpp File Reference
#include <iostream>
#include <vector>
#include <algorithm>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/helpers/Shortcuts.h"
#include "DGtal/geometry/volumes/TangencyComputer.h"
#include "DGtalCatch.h"

Go to the source code of this file.

Functions

 SCENARIO ("TangencyComputer::ShortestPaths 3D tests", "[shortest_paths][3d][tangency]")
 

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
2022/05/09

Functions for testing shortest paths.

This file is part of the DGtal library.

Definition in file testShortestPaths.cpp.

Function Documentation

◆ SCENARIO()

SCENARIO ( "TangencyComputer::ShortestPaths 3D tests"  ,
""  [shortest_paths][3d][tangency] 
)

Definition at line 49 of file testShortestPaths.cpp.

50{
51 typedef Z3i::Space Space;
52 typedef Z3i::KSpace KSpace;
53 typedef Z3i::Domain Domain;
54 typedef Z3i::SCell SCell;
56 typedef Space::Point Point;
59 typedef Space::Vector Vector;
60 typedef std::size_t Index;
61
62 SECTION( "Computing shortest paths on a 3D unit sphere digitized at gridstep 0.25" )
63 {
64 // Make digital sphere
65 const double h = 0.25;
66 auto params = SH3::defaultParameters();
67 params( "polynomial", "sphere1" )( "gridstep", h );
68 params( "minAABB", -2)( "maxAABB", 2)( "offset", 1.0 )( "closed", 1 );
69 auto implicit_shape = SH3::makeImplicitShape3D ( params );
70 auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
71 auto K = SH3::getKSpace( params );
72 auto binary_image = SH3::makeBinaryImage(digitized_shape,
74 params );
75 auto surface = SH3::makeDigitalSurface( binary_image, K, params );
76 std::vector< Point > lattice_points;
77 auto pointels = SH3::getPointelRange( surface );
78 for ( auto p : pointels ) lattice_points.push_back( K.uCoords( p ) );
79 REQUIRE( pointels.size() == 296 );
80 // Find lowest and uppest point.
81 const Index nb = lattice_points.size();
82 Index lowest = 0;
83 Index uppest = 0;
84 for ( Index i = 1; i < nb; i++ )
85 {
86 if ( lattice_points[ i ] < lattice_points[ lowest ] ) lowest = i;
87 if ( lattice_points[ uppest ] < lattice_points[ i ] ) uppest = i;
88 }
89 // Compute shortest paths
92 TC.init( lattice_points.cbegin(), lattice_points.cend() );
93 auto SP = TC.makeShortestPaths( sqrt(3.0) );
94 SP.init( lowest ); //< set source
95 double last_distance = 0.0;
96 Index last = 0;
97 double prev_distance = 0.0;
98 std::set< Index > V;
99 unsigned int nb_multiple_pops = 0;
100 unsigned int nb_decreasing_distance = 0;
101 while ( ! SP.finished() )
102 {
103 last = std::get<0>( SP.current() );
104 last_distance = std::get<2>( SP.current() );
105 if ( V.count( last ) ) nb_multiple_pops += 1;
106 V.insert( last );
107 SP.expand();
108 if ( last_distance < prev_distance ) nb_decreasing_distance += 1;
109 prev_distance = last_distance;
110 }
111 // THEN( "No point is popped several times" )
112 REQUIRE( nb_multiple_pops == 0 );
113 // AND_THEN( "The sequence of popped points has non decreasing distances" )
114 REQUIRE( nb_decreasing_distance == 0 );
115 // AND_THEN( "The furthest point is also the antipodal point" )
116 REQUIRE( last == uppest );
117 // AND_THEN( "The furthest point is at distance close but lower than pi" )
118 REQUIRE( last_distance*h >= 2.8 );
119 REQUIRE( last_distance*h <= 3.14159265358979323844 );
120 // Compute approximate shortest paths
121 SP = TC.makeShortestPaths( 0 );
122 SP.init( uppest ); //< set source
123 double last_distance_opt = 0.0;
124 while ( ! SP.finished() )
125 {
126 last = std::get<0>( SP.current() );
127 last_distance_opt = std::get<2>( SP.current() );
128 SP.expand();
129 }
130 // THEN( "The furthest point is also the antipodal point" )
131 REQUIRE( last == lowest );
132 // AND_THEN( "The furthest point is at distance close but lower than pi" )
133 REQUIRE( last_distance_opt*h >= 2.8 );
134 REQUIRE( last_distance_opt*h <= 3.14159265358979323844 );
135 // AND_THEN( "This distance is greater or equal to the exacts shortest path" )
136 REQUIRE( last_distance_opt*h >= last_distance*h );
137 }
138}
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
const Point & lowerBound() const
Return the lower bound for digital points in this space.
const Point & upperBound() const
Return the upper bound for digital points in this space.
Point uCoords(const Cell &c) const
Return its digital coordinates.
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition: Shortcuts.h:105
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
Definition: Shortcuts.h:332
static CountedPtr< DigitizedImplicitShape3D > makeDigitizedImplicitShape3D(CountedPtr< ImplicitShape3D > shape, Parameters params=parametersDigitizedImplicitShape3D())
Definition: Shortcuts.h:523
static PointelRange getPointelRange(Cell2Index &c2i, CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface)
Definition: Shortcuts.h:1469
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1209
static Parameters defaultParameters()
Definition: Shortcuts.h:203
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
Definition: Shortcuts.h:561
static CountedPtr< ImplicitShape3D > makeImplicitShape3D(const Parameters &params=parametersImplicitShape3D())
Definition: Shortcuts.h:282
Aim: A class that computes tangency to a given digital set. It provides services to compute all the c...
Z3i::SCell SCell
SMesh::Index Index
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Shortcuts< KSpace > SH3
Z2i::RealPoint RealPoint
MyPointD Point
Definition: testClone2.cpp:383
FreemanChain< int >::Vector Vector
KSpace K
SECTION("Testing constant forward iterators")
HyperRectDomain< Space > Domain
REQUIRE(domain.isInside(aPoint))

References DGtal::Shortcuts< TKSpace >::defaultParameters(), DGtal::Shortcuts< TKSpace >::getKSpace(), DGtal::Shortcuts< TKSpace >::getPointelRange(), K, DGtal::KhalimskySpaceND< dim, TInteger >::lowerBound(), DGtal::Shortcuts< TKSpace >::makeBinaryImage(), DGtal::Shortcuts< TKSpace >::makeDigitalSurface(), DGtal::Shortcuts< TKSpace >::makeDigitizedImplicitShape3D(), DGtal::Shortcuts< TKSpace >::makeImplicitShape3D(), REQUIRE(), SECTION(), DGtal::KhalimskySpaceND< dim, TInteger >::uCoords(), and DGtal::KhalimskySpaceND< dim, TInteger >::upperBound().