DGtal  1.5.beta
testPConvexity.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/shapes/Shapes.h"
#include "DGtal/geometry/volumes/PConvexity.h"
#include "DGtal/geometry/volumes/DigitalConvexity.h"
#include "DGtalCatch.h"
Include dependency graph for testPConvexity.cpp:

Go to the source code of this file.

Functions

 SCENARIO ("PConvexity< Z2 > P-convexity tests", "[p_convexity][2d]")
 
 SCENARIO ("PConvexity< Z3 > ball tests", "[p_convexity][3d]")
 
 SCENARIO ("PConvexity< Z4 > ball tests", "[p_convexity][4d]")
 
 SCENARIO ("DigitalConvexity< Z3 > fully convex and p-convex tetrahedra", "[p_convexity][full_convexity][convex_simplices][3d]")
 

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 Savoie Mont Blanc, France
Date
2024/06/21

Functions for testing P-convexity.

This file is part of the DGtal library.

Definition in file testPConvexity.cpp.

Function Documentation

◆ SCENARIO() [1/4]

SCENARIO ( "DigitalConvexity< Z3 > fully convex and p-convex tetrahedra"  ,
""  [p_convexity][full_convexity][convex_simplices][3d] 
)

Definition at line 148 of file testPConvexity.cpp.

149 {
151  typedef KSpace::Point Point;
152  typedef KSpace::Space Space;
154  typedef DigitalConvexity< KSpace > DConvexity;
156 
157  Domain domain( Point( 0, 0, 0 ), Point( 3, 3, 3 ) );
158  DConvexity dconv( Point( -1, -1, -1 ), Point( 4, 4, 4 ) );
159  PConvexity pconv;
160 
161  WHEN( "Computing many tetrahedra in domain (0,0,0)-(4,4,4)." ) {
162  const unsigned int nb = 100;
163  unsigned int nbsimplex= 0;
164  unsigned int nb0 = 0;
165  unsigned int nb1 = 0;
166  unsigned int nb2 = 0;
167  unsigned int nb3 = 0;
168  unsigned int nb012_not3 = 0;
169  unsigned int nbf = 0;
170  unsigned int nbfg = 0;
171  unsigned int nbffast = 0;
172  unsigned int nbp = 0;
173  unsigned int nb0123 = 0;
174  for ( unsigned int i = 0; i < nb; ++i )
175  {
176  Point a( rand() % 5, rand() % 5, rand() % 5 );
177  Point b( rand() % 5, rand() % 5, rand() % 5 );
178  Point c( rand() % 5, rand() % 5, rand() % 5 );
179  Point d( rand() % 5, rand() % 5, rand() % 5 );
180  if ( ! dconv.isSimplexFullDimensional( { a, b, c, d } ) ) continue;
181  auto tetra = dconv.makeSimplex( { a, b, c, d } );
182  std::vector< Point > X;
183  tetra.getPoints( X );
184  bool cvx0 = dconv.isKConvex( tetra, 0 );
185  bool cvx1 = dconv.isKConvex( tetra, 1 );
186  bool cvx2 = dconv.isKConvex( tetra, 2 );
187  bool cvx3 = dconv.isKConvex( tetra, 3 );
188  bool cvxf = dconv.isFullyConvex( tetra );
189  bool cvxfg = dconv.isFullyConvex( X, false );
190  bool cvxffast = dconv.isFullyConvexFast( X );
191  bool cvxp = pconv.isPConvex( X );
192  if ( cvxf != cvxfg || cvxf != cvxffast || cvxf != cvxp ) {
193  std::cout << "[" << cvx0 << cvx1 << cvx2 << cvx3 << "] "
194  << "[" << cvxf << "] [" << cvxfg
195  << "] [" << cvxffast << "]"
196  << "] [" << cvxp << "]"
197  << a << b << c << d << std::endl;
198  }
199  nbsimplex += 1;
200  nb0 += cvx0 ? 1 : 0;
201  nb1 += cvx1 ? 1 : 0;
202  nb2 += cvx2 ? 1 : 0;
203  nb3 += cvx3 ? 1 : 0;
204  nbf += cvxf ? 1 : 0;
205  nbfg += cvxfg ? 1 : 0;
206  nbffast += cvxffast ? 1 : 0;
207  nbp += cvxp ? 1 : 0;
208  nb0123 += ( cvx0 && cvx1 && cvx2 && cvx3 ) ? 1 : 0;
209  nb012_not3+= ( cvx0 && cvx1 && cvx2 && ! cvx3 ) ? 1 : 0;
210  }
211  THEN( "All valid tetrahedra are 0-convex." ) {
212  REQUIRE( nb0 == nbsimplex );
213  }
214  THEN( "There are less 1-convex, 2-convex and 3-convex than 0-convex." ) {
215  REQUIRE( nb1 < nb0 );
216  REQUIRE( nb2 < nb0 );
217  REQUIRE( nb3 < nb0 );
218  }
219  THEN( "When the tetrahedron is 0-convex, 1-convex and 2-convex, then it is 3-convex, so fully convex and also P-convex." ) {
220  REQUIRE( nb1 <= nb3 );
221  REQUIRE( nb2 <= nb3 );
222  REQUIRE( nb012_not3 == 0 );
223  REQUIRE( nbf == nb0123 );
224  REQUIRE( nbf == nbp );
225  }
226  THEN( "All methods for computing full convexity and P-convexity agree." ) {
227  REQUIRE( nbf == nbfg );
228  REQUIRE( nbf == nbffast );
229  REQUIRE( nbf == nbp );
230  }
231  }
232 }
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)
bool isFullyConvexFast(const PointRange &X) const
bool isFullyConvex(const PointRange &X, bool convex0=false) const
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Aim: A class to check if digital sets are P-convex. The P-convexity is defined as follows: A digital ...
Definition: PConvexity.h:355
bool isPConvex(const std::vector< Point > &X) const
Definition: PConvexity.h:407
MyPointD Point
Definition: testClone2.cpp:383
Domain domain
HyperRectDomain< Space > Domain
REQUIRE(domain.isInside(aPoint))

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

◆ SCENARIO() [2/4]

SCENARIO ( "PConvexity< Z2 > P-convexity tests"  ,
""  [p_convexity][2d] 
)

Definition at line 53 of file testPConvexity.cpp.

54 {
55  typedef SpaceND< 2, int > Space;
56  typedef Space::Point Point;
57  typedef PConvexity< Space > Convexity;
58 
59  Convexity pconv;
60 
61  std::vector<Point> V1 = { Point(0,0), Point(-1,0), Point(1,0), Point(0,1) };
62  REQUIRE( pconv.is0Convex( V1 ) );
63  REQUIRE( pconv.isPConvex( V1 ) );
64  REQUIRE( pconv.convexityMeasure( V1 ) == 1.0 );
65  REQUIRE( pconv.fullConvexityMeasure( V1 ) == 1.0 );
66  std::vector<Point> V2 = { Point(-1,0), Point(1,0), Point(0,1) };
67  REQUIRE( ! pconv.is0Convex( V2 ) );
68  REQUIRE( ! pconv.isPConvex( V2 ) );
69  REQUIRE( pconv.convexityMeasure( V2 ) < 1.0 );
70  REQUIRE( pconv.fullConvexityMeasure( V2 ) < 1.0 );
71  std::vector<Point> V3 = { Point(0,0), Point(-1,0), Point(1,0) };
72  REQUIRE( pconv.is0Convex( V3 ) );
73  REQUIRE( pconv.isPConvex( V3 ) );
74  REQUIRE( pconv.convexityMeasure( V3 ) == 1.0 );
75  REQUIRE( pconv.fullConvexityMeasure( V3 ) == 1.0 );
76  std::vector<Point> V4 = { Point(0,0), Point(-1,0), Point(1,0), Point(0,1),
77  Point(0,-1) };
78  REQUIRE( pconv.is0Convex( V4 ) );
79  REQUIRE( pconv.isPConvex( V4 ) );
80  std::vector<Point> V5 = { Point(-1,0), Point(0,0), Point(3,1) };
81  REQUIRE( pconv.is0Convex( V5 ) );
82  REQUIRE( ! pconv.isPConvex( V5 ) );
83  REQUIRE( pconv.convexityMeasure( V5 ) == 1.0 );
84  REQUIRE( pconv.fullConvexityMeasure( V5 ) < 1.0 );
85 }

References REQUIRE().

◆ SCENARIO() [3/4]

SCENARIO ( "PConvexity< Z3 > ball tests"  ,
""  [p_convexity][3d] 
)

Definition at line 87 of file testPConvexity.cpp.

88 {
89  GIVEN( "Given a 3D digital ball of radius 5 " ) {
90  typedef SpaceND<3,int> Space;
91  typedef Space::Point Point;
92  typedef PConvexity< Space > Convexity;
95 
96  Convexity pconv;
97  Point lo = Point::diagonal( -7 );
98  Point hi = Point::diagonal( 7 );
99  Point c = Point::zero;
100  Domain domain( lo, hi );
101  DigitalSet ball ( domain );
102  Shapes< Domain >::addNorm2Ball( ball, c, 5 );
103  std::vector<Point> V( ball.begin(), ball.end() );
104  bool cvx0 = pconv.is0Convex( V );
105  bool fcvx = pconv.isPConvex( V );
106  THEN( "It is a 0-convex and P-convex by morphological characterization" ) {
107  REQUIRE( cvx0 );
108  REQUIRE( fcvx );
109  }
110  THEN( "Then both its convexity measure and its full convexity measure is 1.0" ) {
111  REQUIRE( pconv.convexityMeasure( V ) == 1.0 );
112  REQUIRE( pconv.fullConvexityMeasure( V ) == 1.0 );
113  }
114  }
115 }
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: A utility class for constructing different shapes (balls, diamonds, and others).
GIVEN("A cubical complex with random 3-cells")
Z2i::DigitalSet DigitalSet

References DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::begin(), domain, DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::end(), GIVEN(), and REQUIRE().

◆ SCENARIO() [4/4]

SCENARIO ( "PConvexity< Z4 > ball tests"  ,
""  [p_convexity][4d] 
)

Definition at line 117 of file testPConvexity.cpp.

118 {
119  GIVEN( "Given a 4D digital ball of radius 5 " ) {
120  typedef SpaceND<4,int> Space;
121  typedef Space::Point Point;
122  typedef PConvexity< Space > Convexity;
125 
126  Convexity conv;
127  Point lo = Point::diagonal( -7 );
128  Point hi = Point::diagonal( 7 );
129  Point c = Point::zero;
130  Domain domain( lo, hi );
131  DigitalSet ball ( domain );
132  Shapes< Domain >::addNorm2Ball( ball, c, 5 );
133  std::vector<Point> V( ball.begin(), ball.end() );
134  bool cvx0 = conv.is0Convex( V );
135  bool fcvx = conv.isPConvex( V );
136  THEN( "It is a 0-convex and P-convex by morphological characterization" ) {
137  REQUIRE( cvx0 );
138  REQUIRE( fcvx );
139  }
140  THEN( "Then both its convexity measure and its full convexity measure is 1.0" ) {
141  REQUIRE( conv.convexityMeasure( V ) == 1.0 );
142  REQUIRE( conv.fullConvexityMeasure( V ) == 1.0 );
143  }
144  }
145 }

References DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::begin(), domain, DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::end(), GIVEN(), and REQUIRE().