DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testGenericLatticeConvexHull.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/geometry/tools/GenericLatticeConvexHull.h"
37
#include "DGtal/geometry/tools/AffineGeometry.h"
38
#include "DGtalCatch.h"
40
41
using namespace
std
;
42
using namespace
DGtal
;
43
44
std::random_device
rd
;
45
std::mt19937
g
(
rd
());
46
47
template
<
typename
Po
int
>
48
std::vector< Point >
49
randomPointsInBall
(
int
nb,
int
R )
50
{
51
std::vector< Point > V;
52
Point
c = Point::diagonal( R );
53
double
R2 = (double) R * (
double
) R;
54
for
(
int
i = 0; i < nb; ) {
55
Point
p;
56
for
(
DGtal::Dimension
k = 0; k < Point::dimension; ++k )
57
p[ k ] = rand() % (2*R);
58
if
( ( p - c ).squaredNorm() < R2 ) { V.push_back( p ); i++; }
59
}
60
return
V;
61
}
62
63
template
<
typename
Po
int
>
64
std::vector< Point >
65
makeRandomLatticePointsFromDirVectors
(
int
nb,
const
vector< Point>& V )
66
{
67
std::uniform_int_distribution<int> U(-10, 10);
68
vector< Point > P;
69
int
n = V[0].size();
70
int
m = V.size();
71
Point
A
;
72
for
(
auto
i = 0; i < n; i++ )
73
A
[ i ] = U(
g
);
74
P.push_back(
A
);
75
for
(
auto
k = 0; k < nb; k++ )
76
{
77
Point
B
=
A
;
78
for
(
auto
i = 0; i < m; i++ )
79
{
80
int
l = U(
g
);
81
B
+= l * V[ i ];
82
}
83
P.push_back(
B
);
84
}
85
std::shuffle( P.begin(), P.end(),
g
);
86
return
P;
87
}
88
89
// ///////////////////////////////////////////////////////////////////////////////
90
// // Functions for testing class GenericLatticeConvexHull in 2D.
91
// ///////////////////////////////////////////////////////////////////////////////
92
93
SCENARIO
(
"GenericLatticeConvexHull< ConvexHullIntegralKernel< 2 > > unit tests"
,
"[genquickhull][integral_kernel][2d]"
)
94
{
95
typedef
GenericLatticeConvexHull< 2, int >
CvxHull;
96
typedef
SpaceND< 2, int >
Space
;
97
typedef
Space::Point
Point
;
98
99
100
GIVEN
(
"Given a set { } "
) {
101
std::vector<Point> V = { };
102
CvxHull hull;
103
bool
ok = hull.compute( V );
104
std::cout << hull << std::endl;
105
THEN(
"Everything went fine and dim=-1."
) {
106
REQUIRE
( ok );
107
REQUIRE
( hull.affine_dimension == -1 );
108
REQUIRE
( hull.count() == 0 );
109
}
110
}
111
GIVEN
(
"Given a set { (2,1), (2,1) } "
) {
112
std::vector<Point> V
113
= {
Point
(2,1),
Point
(2,1) };
114
CvxHull hull;
115
bool
ok = hull.compute( V );
116
std::cout << hull << std::endl;
117
THEN(
"Everything went fine and dim=0."
) {
118
REQUIRE
( ok );
119
REQUIRE
( hull.affine_dimension == 0 );
120
REQUIRE
( hull.count() == 1 );
121
}
122
}
123
GIVEN
(
"Given a set { (0,0), (-4,-1), (8, 2), (16,4) } "
) {
124
std::vector<Point> V
125
= {
Point
(0,0),
Point
(-4,-1),
Point
(8,2),
Point
(16,4) };
126
CvxHull hull;
127
bool
ok = hull.compute( V );
128
std::cout << hull << std::endl;
129
THEN(
"Everything went fine and dim=1."
) {
130
REQUIRE
( ok );
131
REQUIRE
( hull.affine_dimension == 1 );
132
REQUIRE
( hull.count() == 6 );
133
}
134
}
135
GIVEN
(
"Given a set { (0,0), (-4,-1), (-3,5), (7,3), (5, -2), (2, 2) } "
) {
136
std::vector<Point> V
137
= {
Point
(0,0),
Point
(-4,-1),
Point
(-3,5),
Point
(7,3),
Point
(5, -2),
Point
(2,2) };
138
CvxHull hull;
139
bool
ok = hull.compute( V );
140
std::cout << hull << std::endl;
141
THEN(
"Everything went fine and dim=2."
) {
142
REQUIRE
( ok );
143
REQUIRE
( hull.affine_dimension == 2 );
144
REQUIRE
( hull.count() > V.size() );
145
}
146
}
147
148
}
149
150
SCENARIO
(
"GenericLatticeConvexHull< ConvexHullIntegralKernel< 3 > > unit tests"
,
"[genquickhull][integral_kernel][3d]"
)
151
{
152
typedef
GenericLatticeConvexHull< 3, int >
CvxHull;
153
typedef
SpaceND< 3, int >
Space
;
154
typedef
Space::Point
Point
;
155
156
std::vector< Point > V1 = {
Point
{ 5,-2, 1 } };
157
std::vector< Point > X1 =
makeRandomLatticePointsFromDirVectors
( 20, V1 );
158
std::vector< Point > V2 = {
Point
{ 5,-2, 1 },
Point
{ -3, 4, 2 } };
159
std::vector< Point > X2 =
makeRandomLatticePointsFromDirVectors
( 20, V2 );
160
std::vector< Point > V3 = {
Point
{ 5,-2, 1 },
Point
{ -3, 4, 2 },
Point
{ 1, -7, 11 } };
161
std::vector< Point > X3 =
makeRandomLatticePointsFromDirVectors
( 20, V3 );
162
163
GIVEN
(
"Given a 1-d lattice set in Z3 "
) {
164
CvxHull hull;
165
bool
ok = hull.compute( X1 );
166
std::cout << hull << std::endl;
167
THEN(
"Everything went fine and dim=1."
) {
168
CAPTURE
( hull.positions );
169
REQUIRE
( ok );
170
REQUIRE
( hull.affine_dimension == 1 );
171
REQUIRE
( hull.count() >= 2 );
172
}
173
}
174
GIVEN
(
"Given a 2-d lattice set in Z3 "
) {
175
CvxHull hull;
176
bool
ok = hull.compute( X2 );
177
std::cout << hull << std::endl;
178
THEN(
"Everything went fine and dim=2."
) {
179
REQUIRE
( ok );
180
REQUIRE
( hull.affine_dimension == 2 );
181
REQUIRE
( hull.count() >= 3 );
182
}
183
}
184
GIVEN
(
"Given a 3-d lattice set in Z3 "
) {
185
CvxHull hull;
186
bool
ok = hull.compute( X3 );
187
std::cout << hull << std::endl;
188
THEN(
"Everything went fine and dim=3."
) {
189
REQUIRE
( ok );
190
REQUIRE
( hull.affine_dimension == 3 );
191
REQUIRE
( hull.count() >= 4 );
192
}
193
}
194
}
B
Definition
testPartialTemplateSpecialization.cpp:63
DGtal::Point
DGtal::SpaceND< 3, Integer >::Point
PointVector< dim, Integer > Point
Definition
SpaceND.h:110
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::Dimension
DGtal::uint32_t Dimension
Definition
Common.h:119
std
STL namespace.
A
Definition
testCountedConstPtrOrConstPtr.cpp:43
DGtal::Space
DGtal::GenericLatticeConvexHull
Aim: Implements the quickhull algorithm by Barber et al. barber1996, a famous arbitrary dimensional c...
Definition
GenericLatticeConvexHull.h:522
g
std::mt19937 g(rd())
rd
std::random_device rd
Definition
testAffineBasis.cpp:45
makeRandomLatticePointsFromDirVectors
std::vector< Point > makeRandomLatticePointsFromDirVectors(int nb, const vector< Point > &V)
Definition
testAffineBasis.cpp:66
CAPTURE
CAPTURE(thicknessHV)
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
randomPointsInBall
std::vector< Point > randomPointsInBall(int nb, int R)
Definition
testGenericLatticeConvexHull.cpp:49
REQUIRE
REQUIRE(domain.isInside(aPoint))
tests
geometry
tools
testGenericLatticeConvexHull.cpp
Generated on
for DGtal by
1.18.0