DGtal 1.3.0
Loading...
Searching...
No Matches
testFullConvexity.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include <vector>
33#include <algorithm>
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/geometry/volumes/CellGeometry.h"
40#include "DGtal/geometry/volumes/DigitalConvexity.h"
41#include "DGtal/shapes/Shapes.h"
42#include "DGtalCatch.h"
44
45using namespace std;
46using namespace DGtal;
47
48
50// Functions for testing class DigitalConvexity.
52
53SCENARIO( "DigitalConvexity< Z2 > full convexity tests", "[digital_convexity][2d][full_convexity]" )
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}
73
74SCENARIO( "FullConvexity< Z3 > full convexity tests", "[full_convexity][3d]" )
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}
98
99SCENARIO( "DigitalConvexity< Z2 > ball tests", "[digital_convexity][2d]" )
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}
125
126SCENARIO( "DigitalConvexity< Z3 > ball tests", "[digital_convexity][3d]" )
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}
152
153SCENARIO( "DigitalConvexity< Z4 > ball tests", "[digital_convexity][4d]" )
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}
181
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 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)
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
MyPointD Point
Definition: testClone2.cpp:383
GIVEN("A cubical complex with random 3-cells")
Domain domain
HyperRectDomain< Space > Domain
REQUIRE(domain.isInside(aPoint))
SCENARIO("UnorderedSetByBlock< PointVector< 2, int > unit tests with 32 bits blocks", "[unorderedsetbyblock][2d]")
Z2i::DigitalSet DigitalSet