DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
testFullConvexity.cpp File Reference
#include <iostream>
#include <vector>
#include <algorithm>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/kernel/sets/DigitalSetBySTLSet.h"
#include "DGtal/topology/KhalimskySpaceND.h"
#include "DGtal/geometry/volumes/CellGeometry.h"
#include "DGtal/geometry/volumes/DigitalConvexity.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtalCatch.h"

Go to the source code of this file.

Functions

 SCENARIO ("DigitalConvexity< Z2 > full convexity tests", "[digital_convexity][2d][full_convexity]")
 
 SCENARIO ("FullConvexity< Z3 > full convexity tests", "[full_convexity][3d]")
 
 SCENARIO ("DigitalConvexity< Z2 > ball tests", "[digital_convexity][2d]")
 
 SCENARIO ("DigitalConvexity< Z3 > ball tests", "[digital_convexity][3d]")
 
 SCENARIO ("DigitalConvexity< Z4 > ball tests", "[digital_convexity][4d]")
 

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
2020/02/01

Functions for testing full convexity.

This file is part of the DGtal library.

Definition in file testFullConvexity.cpp.

Function Documentation

◆ SCENARIO() [1/5]

SCENARIO ( "DigitalConvexity< Z2 > ball tests"  ,
""  [digital_convexity][2d] 
)

Definition at line 99 of file testFullConvexity.cpp.

100{
101 GIVEN( "Given a 2D digital ball of radius 5 " ) {
103 typedef KSpace::Point Point;
104 typedef KSpace::Space Space;
105 typedef DigitalConvexity< KSpace > DConvexity;
108
109 Point lo = Point::diagonal( -7 );
110 Point hi = Point::diagonal( 7 );
111 Point c = Point::zero;
112 Domain domain( lo, hi );
113 DConvexity dconv ( lo, hi );
114 DigitalSet ball ( domain );
115 Shapes< Domain >::addNorm2Ball( ball, c, 5 );
116 std::vector<Point> V( ball.begin(), ball.end() );
117 bool cvx0 = dconv.is0Convex( V );
118 bool fcvx = dconv.isFullyConvex( V );
119 THEN( "It is a 0-convex and fully convex set by morphological characterization" ) {
120 REQUIRE( cvx0 );
121 REQUIRE( fcvx );
122 }
123 }
124}
bool isFullyConvex(const PointRange &X, bool convex0=false) const
bool is0Convex(const PointRange &X) const
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: A container class for storing sets of digital points within some given domain.
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
static void addNorm2Ball(TDigitalSet &aSet, const Point &aCenter, UnsignedInteger aRadius)
MyPointD Point
Definition: testClone2.cpp:383
GIVEN("A cubical complex with random 3-cells")
Domain domain
HyperRectDomain< Space > Domain
REQUIRE(domain.isInside(aPoint))
Z2i::DigitalSet DigitalSet

References DGtal::Shapes< TDomain >::addNorm2Ball(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::begin(), domain, DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::end(), GIVEN(), DGtal::DigitalConvexity< TKSpace >::is0Convex(), DGtal::DigitalConvexity< TKSpace >::isFullyConvex(), and REQUIRE().

◆ SCENARIO() [2/5]

SCENARIO ( "DigitalConvexity< Z2 > full convexity tests"  ,
""  [digital_convexity][2d][full_convexity] 
)

Definition at line 53 of file testFullConvexity.cpp.

54{
56 typedef KSpace::Point Point;
57 typedef DigitalConvexity< KSpace > DConvexity;
58
59 DConvexity dconv( Point( -5, -5 ), Point( 10, 10 ) );
60
61 std::vector<Point> V1 = { Point(0,0), Point(-1,0), Point(1,0), Point(0,1) };
62 REQUIRE( dconv.isFullyConvex( V1 ) );
63 std::vector<Point> V2 = { Point(-1,0), Point(1,0), Point(0,1) };
64 REQUIRE( ! dconv.isFullyConvex( V2 ) );
65 std::vector<Point> V3 = { Point(0,0), Point(-1,0), Point(1,0) };
66 REQUIRE( dconv.isFullyConvex( V3 ) );
67 std::vector<Point> V4 = { Point(0,0), Point(-1,0), Point(1,0), Point(0,1),
68 Point(0,-1) };
69 REQUIRE( dconv.isFullyConvex( V4 ) );
70 std::vector<Point> V5 = { Point(-1,0), Point(1,0), Point(0,1), Point(0,-1) };
71 REQUIRE( ! dconv.isFullyConvex( V5 ) );
72}

References DGtal::DigitalConvexity< TKSpace >::isFullyConvex(), and REQUIRE().

◆ SCENARIO() [3/5]

SCENARIO ( "DigitalConvexity< Z3 > ball tests"  ,
""  [digital_convexity][3d] 
)

Definition at line 126 of file testFullConvexity.cpp.

127{
128 GIVEN( "Given a 3D digital ball of radius 5 " ) {
130 typedef KSpace::Point Point;
131 typedef KSpace::Space Space;
132 typedef DigitalConvexity< KSpace > DConvexity;
135
136 Point lo = Point::diagonal( -7 );
137 Point hi = Point::diagonal( 7 );
138 Point c = Point::zero;
139 Domain domain( lo, hi );
140 DConvexity dconv ( lo, hi );
141 DigitalSet ball ( domain );
142 Shapes< Domain >::addNorm2Ball( ball, c, 5 );
143 std::vector<Point> V( ball.begin(), ball.end() );
144 bool cvx0 = dconv.is0Convex( V );
145 bool fcvx = dconv.isFullyConvex( V );
146 THEN( "It is a 0-convex and fully convex set by morphological characterization" ) {
147 REQUIRE( cvx0 );
148 REQUIRE( fcvx );
149 }
150 }
151}

References DGtal::Shapes< TDomain >::addNorm2Ball(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::begin(), domain, DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::end(), GIVEN(), DGtal::DigitalConvexity< TKSpace >::is0Convex(), DGtal::DigitalConvexity< TKSpace >::isFullyConvex(), and REQUIRE().

◆ SCENARIO() [4/5]

SCENARIO ( "DigitalConvexity< Z4 > ball tests"  ,
""  [digital_convexity][4d] 
)

[nD-full-convexity]

[nD-full-convexity]

Definition at line 153 of file testFullConvexity.cpp.

154{
155 GIVEN( "Given a 4D digital ball of radius 5 " ) {
158 typedef KSpace::Point Point;
159 typedef KSpace::Space Space;
160 typedef DigitalConvexity< KSpace > DConvexity;
163
164 Point lo = Point::diagonal( -7 );
165 Point hi = Point::diagonal( 7 );
166 Point c = Point::zero;
167 Domain domain( lo, hi );
168 DConvexity dconv ( lo, hi );
169 DigitalSet ball ( domain );
170 Shapes< Domain >::addNorm2Ball( ball, c, 5 );
171 std::vector<Point> V( ball.begin(), ball.end() );
172 bool cvx0 = dconv.is0Convex( V ); // checks digital 0-convexity
173 bool fcvx = dconv.isFullyConvex( V ); // checks full convexity
175 THEN( "It is a 0-convex and fully convex set by morphological characterization" ) {
176 REQUIRE( cvx0 );
177 REQUIRE( fcvx );
178 }
179 }
180}

References DGtal::Shapes< TDomain >::addNorm2Ball(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::begin(), domain, DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::end(), GIVEN(), DGtal::DigitalConvexity< TKSpace >::is0Convex(), DGtal::DigitalConvexity< TKSpace >::isFullyConvex(), and REQUIRE().

◆ SCENARIO() [5/5]

SCENARIO ( "FullConvexity< Z3 > full convexity tests"  ,
""  [full_convexity][3d] 
)

Definition at line 74 of file testFullConvexity.cpp.

75{
77 typedef KSpace::Point Point;
78 typedef DigitalConvexity< KSpace > DConvexity;
79
80 DConvexity dconv( Point( -5, -5, -5 ), Point( 10, 10, 10 ) );
81 Point a( 0, 2, 3 );
82 Point b( 3, 1, 0 );
83 Point c( 2, 0, 1 );
84 Point d( 2, 1, 2 );
85 std::vector< Point > X;
86 REQUIRE( dconv.isSimplexFullDimensional( { a, b, c, d } ) );
87 auto tetra= dconv.makeSimplex( { a, b, c, d } );
88 tetra.getPoints( X );
89 bool cvx0 = dconv.isKConvex( tetra, 0 );
90 bool cvx1 = dconv.isKConvex( tetra, 1 );
91 bool cvx2 = dconv.isKConvex( tetra, 2 );
92 bool cvx3 = dconv.isKConvex( tetra, 3 );
93 bool cvxf = dconv.isFullyConvex( tetra );
94 bool cvxg = dconv.isFullyConvex( X, false );
95 REQUIRE( cvxf == cvxg );
96 REQUIRE( ( cvx0 && cvx1 && cvx2 && cvx3 ) == cvxf );
97}
void getPoints(std::vector< Point > &pts) const
bool isKConvex(const LatticePolytope &P, const Dimension k) const
static bool isSimplexFullDimensional(PointIterator itB, PointIterator itE)
static LatticePolytope makeSimplex(PointIterator itB, PointIterator itE)

References DGtal::BoundedLatticePolytope< TSpace >::getPoints(), DGtal::DigitalConvexity< TKSpace >::isFullyConvex(), DGtal::DigitalConvexity< TKSpace >::isKConvex(), DGtal::DigitalConvexity< TKSpace >::isSimplexFullDimensional(), DGtal::DigitalConvexity< TKSpace >::makeSimplex(), and REQUIRE().