34#include "DGtal/base/Common.h"
35#include "DGtal/kernel/SpaceND.h"
36#include "DGtal/kernel/domains/HyperRectDomain.h"
37#include "DGtal/kernel/sets/DigitalSetBySTLSet.h"
38#include "DGtal/topology/KhalimskySpaceND.h"
39#include "DGtal/shapes/Shapes.h"
40#include "DGtal/geometry/volumes/PConvexity.h"
41#include "DGtal/geometry/volumes/DigitalConvexity.h"
42#include "DGtalCatch.h"
53SCENARIO(
"PConvexity< Z2 > P-convexity tests",
"[p_convexity][2d]" )
62 REQUIRE( pconv.is0Convex( V1 ) );
63 REQUIRE( pconv.isPConvex( V1 ) );
64 REQUIRE( pconv.convexityMeasure( V1 ) == 1.0 );
65 REQUIRE( pconv.fullConvexityMeasure( V1 ) == 1.0 );
67 REQUIRE( ! pconv.is0Convex( V2 ) );
68 REQUIRE( ! pconv.isPConvex( V2 ) );
69 REQUIRE( pconv.convexityMeasure( V2 ) < 1.0 );
70 REQUIRE( pconv.fullConvexityMeasure( V2 ) < 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 );
78 REQUIRE( pconv.is0Convex( V4 ) );
79 REQUIRE( pconv.isPConvex( V4 ) );
81 REQUIRE( pconv.is0Convex( V5 ) );
82 REQUIRE( ! pconv.isPConvex( V5 ) );
83 REQUIRE( pconv.convexityMeasure( V5 ) == 1.0 );
84 REQUIRE( pconv.fullConvexityMeasure( V5 ) < 1.0 );
87SCENARIO(
"PConvexity< Z3 > ball tests",
"[p_convexity][3d]" )
89 GIVEN(
"Given a 3D digital ball of radius 5 " ) {
97 Point lo = Point::diagonal( -7 );
98 Point hi = Point::diagonal( 7 );
99 Point c = Point::zero;
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" ) {
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 );
117SCENARIO(
"PConvexity< Z4 > ball tests",
"[p_convexity][4d]" )
119 GIVEN(
"Given a 4D digital ball of radius 5 " ) {
127 Point lo = Point::diagonal( -7 );
128 Point hi = Point::diagonal( 7 );
129 Point c = Point::zero;
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" ) {
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 );
148SCENARIO(
"DigitalConvexity< Z3 > fully convex and p-convex tetrahedra",
"[p_convexity][full_convexity][convex_simplices][3d]" )
158 DConvexity dconv(
Point( -1, -1, -1 ),
Point( 4, 4, 4 ) );
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 )
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 );
182 std::vector< Point > 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;
205 nbfg += cvxfg ? 1 : 0;
206 nbffast += cvxffast ? 1 : 0;
208 nb0123 += ( cvx0 && cvx1 && cvx2 && cvx3 ) ? 1 : 0;
209 nb012_not3+= ( cvx0 && cvx1 && cvx2 && ! cvx3 ) ? 1 : 0;
211 THEN(
"All valid tetrahedra are 0-convex." ) {
214 THEN(
"There are less 1-convex, 2-convex and 3-convex than 0-convex." ) {
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." ) {
226 THEN(
"All methods for computing full convexity and P-convexity agree." ) {
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: A wrapper class around a STL associative container for storing sets of digital points within som...
ConstIterator end() const
ConstIterator begin() const
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,...
Aim: A class to check if digital sets are P-convex. The P-convexity is defined as follows: A digital ...
bool isPConvex(const std::vector< Point > &X) const
static void addNorm2Ball(TDigitalSet &aSet, const Point &aCenter, UnsignedInteger aRadius)
DGtal is the top-level namespace which contains all DGtal functions and types.
GIVEN("A cubical complex with random 3-cells")
HyperRectDomain< Space > Domain
REQUIRE(domain.isInside(aPoint))
SCENARIO("UnorderedSetByBlock< PointVector< 2, int > unit tests with 32 bits blocks", "[unorderedsetbyblock][2d]")
Z2i::DigitalSet DigitalSet