DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testFullConvexity.cpp
Go to the documentation of this file.
1
16
29
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
45
using namespace
std
;
46
using namespace
DGtal
;
47
48
50
// Functions for testing class DigitalConvexity.
52
53
SCENARIO
(
"DigitalConvexity< Z2 > full convexity tests"
,
"[digital_convexity][2d][full_convexity]"
)
54
{
55
typedef
KhalimskySpaceND<2,int>
KSpace
;
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
74
SCENARIO
(
"FullConvexity< Z3 > full convexity tests"
,
"[full_convexity][3d]"
)
75
{
76
typedef
KhalimskySpaceND<3,int>
KSpace
;
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
99
SCENARIO
(
"DigitalConvexity< Z2 > ball tests"
,
"[digital_convexity][2d]"
)
100
{
101
GIVEN
(
"Given a 2D digital ball of radius 5 "
) {
102
typedef
KhalimskySpaceND<2,int>
KSpace
;
103
typedef
KSpace::Point
Point
;
104
typedef
KSpace::Space
Space
;
105
typedef
DigitalConvexity< KSpace >
DConvexity;
106
typedef
HyperRectDomain< Space >
Domain
;
107
typedef
DigitalSetBySTLSet< Domain >
DigitalSet
;
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
126
SCENARIO
(
"DigitalConvexity< Z3 > ball tests"
,
"[digital_convexity][3d]"
)
127
{
128
GIVEN
(
"Given a 3D digital ball of radius 5 "
) {
129
typedef
KhalimskySpaceND<3,int>
KSpace
;
130
typedef
KSpace::Point
Point
;
131
typedef
KSpace::Space
Space
;
132
typedef
DigitalConvexity< KSpace >
DConvexity;
133
typedef
HyperRectDomain< Space >
Domain
;
134
typedef
DigitalSetBySTLSet< Domain >
DigitalSet
;
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
153
SCENARIO
(
"DigitalConvexity< Z4 > ball tests"
,
"[digital_convexity][4d]"
)
154
{
155
GIVEN
(
"Given a 4D digital ball of radius 5 "
) {
157
typedef
KhalimskySpaceND<4,int>
KSpace
;
158
typedef
KSpace::Point
Point
;
159
typedef
KSpace::Space
Space
;
160
typedef
DigitalConvexity< KSpace >
DConvexity;
161
typedef
HyperRectDomain< Space >
Domain
;
162
typedef
DigitalSetBySTLSet< Domain >
DigitalSet
;
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
}
DGtal::DigitalConvexity< KSpace >
DGtal::DigitalSetByAssociativeContainer::end
ConstIterator end() const
DGtal::DigitalSetByAssociativeContainer::begin
ConstIterator begin() const
DGtal::DigitalSetBySTLSet
Aim: A container class for storing sets of digital points within some given domain.
Definition
DigitalSetBySTLSet.h:85
DGtal::HyperRectDomain< Space >
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition
KhalimskySpaceND.h:394
DGtal::KhalimskySpaceND< 3, Integer >::Point
PointVector< dim, Integer > Point
Definition
KhalimskySpaceND.h:425
DGtal::KhalimskySpaceND< 3, Integer >::Space
SpaceND< dim, Integer > Space
Definition
KhalimskySpaceND.h:410
DGtal::Shapes::addNorm2Ball
static void addNorm2Ball(TDigitalSet &aSet, const Point &aCenter, UnsignedInteger aRadius)
DGtal::Point
DGtal::Domain
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
std
STL namespace.
DGtal::Space
KSpace
Z3i::KSpace KSpace
Definition
testArithmeticalDSSComputerOnSurfels.cpp:48
SCENARIO
SCENARIO("CorrectedNormalCurrentComputer interpolated curvature measures on sphere tests", "[icnc][sphere]")
Definition
testCorrectedNormalCurrentComputer.cpp:50
GIVEN
GIVEN("A cubical complex with random 3-cells")
Definition
testCubicalComplex.cpp:70
domain
Domain domain
Definition
testProjection.cpp:88
REQUIRE
REQUIRE(domain.isInside(aPoint))
DigitalSet
Z2i::DigitalSet DigitalSet
Definition
testVoronoiMapComplete.cpp:40
tests
geometry
volumes
testFullConvexity.cpp
Generated on
for DGtal by
1.18.0