34 #include "DGtal/base/Common.h"
35 #include "DGtal/helpers/StdDefs.h"
36 #include "DGtal/kernel/LatticeSetByIntervals.h"
37 #include "DGtalCatch.h"
41 using namespace DGtal;
48 SCENARIO(
"LatticeSetByIntervals< int > unit tests",
"[lattice_set]" )
54 WHEN(
"Inserting many points" ) {
57 unsigned int nb = 10000;
58 for (
unsigned int i = 0; i < nb; i++ )
60 Point p( rand() % 20, rand() % 20, rand() % 20 );
64 auto mem_L =
L.memory_usage();
65 auto mem_S = (
L.size() * (
sizeof(
Point ) +
sizeof(
void* ) ) );
66 auto vec_L =
L.toPointRange();
67 std::sort( vec_L.begin(), vec_L.end() );
68 std::vector< Point > vec_S( S.begin(), S.end() );
69 for (
size_t i = 0; i < vec_L.size(); i++ )
71 if ( vec_L[ i ] != vec_S[ i ] )
72 std::cout << i <<
" " << vec_L[ i ] <<
" != " << vec_S[ i ]
75 THEN(
"The lattice set contains the same points as std::set< Point >" ) {
78 REQUIRE( std::equal( vec_L.begin(), vec_L.end(), vec_S.begin() ) );
80 THEN(
"The lattice set is less costly to store than std::set< Point >" ) {
83 THEN(
"One can create directly a lattice set from a range" ) {
84 LatticeSet L2( S.begin(), S.end() );
85 REQUIRE( L2.size() == S.size() );
87 THEN(
"When erasing all elements from the lattice set, it becomes empty" ) {
88 LatticeSet L2( S.begin(), S.end() );
97 SCENARIO(
"LatticeSetByIntervals< int > set operations tests",
"[lattice_set]" )
103 std::set< Point > X,Y;
106 for (
auto i = 0; i < nb; i++ )
108 Point p( rand() % R, rand() % R, rand() % R );
110 Point q( rand() % R, rand() % R, rand() % R );
113 LatticeSet A( X.cbegin(), X.cend() );
114 LatticeSet B( Y.cbegin(), Y.cend() );
115 std::vector< Point > X_cup_Y, X_cap_Y, X_minus_Y, X_delta_Y;
118 std::set_union( X.cbegin(), X.cend(), Y.cbegin(), Y.cend(),
119 std::back_inserter( X_cup_Y ) );
120 std::set_intersection( X.cbegin(), X.cend(), Y.cbegin(), Y.cend(),
121 std::back_inserter( X_cap_Y ) );
122 std::set_difference( X.cbegin(), X.cend(), Y.cbegin(), Y.cend(),
123 std::back_inserter( X_minus_Y ) );
124 std::set_symmetric_difference( X.cbegin(), X.cend(), Y.cbegin(), Y.cend(),
125 std::back_inserter( X_delta_Y ) );
126 auto tv = c.stopClock();
129 LatticeSet A_cup_B = A.set_union( B );
130 LatticeSet A_cap_B = A.set_intersection( B );
131 LatticeSet A_minus_B = A.set_difference( B );
132 LatticeSet A_delta_B = A.set_symmetric_difference( B );
133 auto tl = c.stopClock();
134 THEN(
"Lattice sets can be constructed from sets" ) {
135 REQUIRE( X.size() == A.size() );
136 REQUIRE( Y.size() == B.size() );
138 THEN(
"Set operations on lattice sets are correct" ) {
139 REQUIRE( X_cup_Y.size() == A_cup_B.size() );
140 REQUIRE( X_cap_Y.size() == A_cap_B.size() );
141 REQUIRE( X_minus_Y.size() == A_minus_B.size() );
142 REQUIRE( X_delta_Y.size() == A_delta_B.size() );
144 THEN(
"Set operations on lattice sets are faster" ) {
147 THEN(
"Inclusions are correct" ) {
149 REQUIRE( A_cup_B.equals( A_cup_B ) );
150 REQUIRE( A_cup_B.includes( A_cup_B ) );
151 REQUIRE( A_cup_B.includes( A ) );
152 REQUIRE( ! A_cup_B.equals( A ) );
153 REQUIRE( ! A.includes( A_cup_B ) );
154 REQUIRE( A_cup_B.includes( B ) );
155 REQUIRE( ! B.includes( A_cup_B ) );
156 REQUIRE( ! A_cup_B.equals( B ) );
157 REQUIRE( A_cup_B.includes( A_cap_B ) );
158 REQUIRE( ! A_cap_B.includes( A_cup_B ) );
159 REQUIRE( A.includes( A_minus_B ) );
160 REQUIRE( ! A_minus_B.includes( A ) );
161 REQUIRE( A_cup_B.includes( A_delta_B ) );
162 REQUIRE( ! A_delta_B.includes( A_cup_B ) );
163 REQUIRE( ! A.includes( A_delta_B ) );
164 REQUIRE( ! B.includes( A_delta_B ) );
168 SCENARIO(
"LatticeSetByIntervals< int > 3d topology operations tests",
"[lattice_set][3d]" )
173 WHEN(
"Computing the star of n isolated points, the number of cells is 27*n, and taking its skel brings back the n points" ) {
174 std::vector< Point > X { {0,0,0}, {10,0,0}, {5,5,0}, {0,0,8} };
175 LatticeSet P( X.cbegin(), X.cend() );
176 auto StarP = P.starOfPoints();
177 auto SkelStarP = StarP.skeletonOfCells();
178 REQUIRE( P.size() == X.size() );
179 REQUIRE( StarP.size() == 27 * X.size() );
180 REQUIRE( SkelStarP.size() == X.size() );
182 WHEN(
"Computing the star of n points consecutive along space diagonal, the number of cells is 26*n+1, and taking its skel brings back the n points" ) {
183 std::vector< Point > X { {0,0,0}, {1,1,1}, {2,2,2}, {3,3,3} };
184 LatticeSet P( X.cbegin(), X.cend() );
185 auto StarP = P.starOfPoints();
186 auto SkelStarP = StarP.skeletonOfCells();
187 REQUIRE( P.size() == X.size() );
188 REQUIRE( StarP.size() == ( 26 * X.size() + 1 ) );
189 REQUIRE( SkelStarP.size() == X.size() );
191 WHEN(
"Computing the star of n points consecutive along any axis, the number of cells is 18*n+9, and taking its skel brings back the n points" ) {
192 std::vector< Point > X { {0,0,0}, {1,0,0}, {2,0,0}, {3,0,0} };
195 LatticeSet P( X.cbegin(), X.cend(), a );
196 auto StarP = P.starOfPoints();
197 auto SkelStarP = StarP.skeletonOfCells();
198 CAPTURE( StarP.toPointRange() );
199 CAPTURE( SkelStarP.toPointRange() );
201 REQUIRE( P.size() == X.size() );
202 REQUIRE( StarP.size() == ( 18 * X.size() + 9 ) );
203 REQUIRE( SkelStarP.size() == X.size() );
206 WHEN(
"Computing the skeleton of the star of a random set of points X, Skel(Star(X)) = X" ) {
207 std::vector< Point > X;
208 for (
int i = 0; i < 1000; i++ )
209 X.push_back(
Point( rand() % 10, rand() % 10, rand() % 10 ) );
212 LatticeSet P( X.cbegin(), X.cend(), a );
213 auto StarP = P.starOfPoints();
214 auto SkelStarP = StarP.skeletonOfCells();
215 REQUIRE( SkelStarP.size() == P.size() );
218 WHEN(
"Computing the skeleton of an open random set of cells O, O = Star(O), Skel(O) subset O and O = Star(Skel(O))" ) {
219 std::vector< Point > X;
220 for (
int i = 0; i < 50; i++ )
221 X.push_back(
Point( rand() % 5, rand() % 5, rand() % 5 ) );
224 LatticeSet C( X.cbegin(), X.cend(), a );
225 auto O = C.starOfCells();
226 auto StarO = O.starOfCells();
227 auto SkelO = O.skeletonOfCells();
228 auto StarSkelO = SkelO.starOfCells();
234 REQUIRE( O.includes( SkelO ) );
235 REQUIRE( StarSkelO.equals( O ) );
239 WHEN(
"Computing the skeleton of a random set of cells C, C subset Star(C), Skel(C) subset C, C subset Star(Skel(C)), Star(C) = Star(Skel(Star(C)))" ) {
240 std::vector< Point > X;
241 for (
int i = 0; i < 50; i++ )
242 X.push_back(
Point( rand() % 5, rand() % 5, rand() % 5 ) );
245 LatticeSet C( X.cbegin(), X.cend(), a );
246 auto StarC = C.starOfCells();
247 auto SkelC = C.skeletonOfCells();
248 auto StarSkelC = SkelC.starOfCells();
249 auto StarSkelStarC = StarC.skeletonOfCells().starOfCells();
255 CAPTURE( StarSkelStarC.size() );
256 REQUIRE( StarC.includes( C ) );
258 REQUIRE( StarSkelC.includes( C ) );
259 REQUIRE( StarSkelStarC.equals( StarC ) );
264 SCENARIO(
"LatticeSetByIntervals< int > 2d topology operations tests",
"[lattice_set][2d]" )
269 WHEN(
"Computing the skeleton of an open random set of cells O, O = Star(O), Skel(O) subset O and O = Star(Skel(O))" ) {
270 std::vector< Point > X;
271 for (
int i = 0; i < 30; i++ )
272 X.push_back(
Point( rand() % 10, rand() % 10 ) );
275 LatticeSet C( X.cbegin(), X.cend(), a );
276 auto O = C.starOfCells();
277 auto StarO = O.starOfCells();
278 auto SkelO = O.skeletonOfCells();
279 auto StarSkelO = SkelO.starOfCells();
280 auto debug = StarO.set_symmetric_difference( O );
287 CAPTURE( StarO.toPointRange() );
288 CAPTURE( SkelO.toPointRange() );
289 CAPTURE( StarSkelO.toPointRange() );
290 CAPTURE( debug.toPointRange() );
291 REQUIRE( O.includes( SkelO ) );
292 REQUIRE( StarSkelO.equals( O ) );
296 WHEN(
"Computing the skeleton of a random set of cells C, C subset Star(C), Skel(C) subset C, C subset Star(Skel(C)), Star(C) = Star(Skel(Star(C)))" ) {
297 std::vector< Point > X;
298 for (
int i = 0; i < 10; i++ )
299 X.push_back(
Point( rand() % 10, rand() % 10 ) );
302 LatticeSet C( X.cbegin(), X.cend(), a );
303 auto StarC = C.starOfCells();
304 auto SkelC = C.skeletonOfCells();
305 auto StarSkelC = SkelC.starOfCells();
306 auto StarSkelStarC = StarC.skeletonOfCells().starOfCells();
312 CAPTURE( StarSkelStarC.size() );
313 REQUIRE( StarC.includes( C ) );
315 REQUIRE( StarSkelC.includes( C ) );
316 REQUIRE( StarSkelStarC.equals( StarC ) );
318 WHEN(
"Computing the extrema of a set of cells C, extremas are correct" ) {
319 std::vector< Point > XX;
320 XX.push_back(
Point(10,-2) );
321 XX.push_back(
Point(5,5) );
322 XX.push_back(
Point(4,5) );
323 XX.push_back(
Point(3,5) );
324 XX.push_back(
Point(2,1) );
325 XX.push_back(
Point(2,3) );
326 XX.push_back(
Point(1,1) );
327 XX.push_back(
Point(-2,3) );
328 XX.push_back(
Point(-3,2) );
329 LatticeSet C( XX.cbegin(), XX.cend(), 0 );
330 auto ExtrC = C.extremaOfCells();
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension
SCENARIO("LatticeSetByIntervals< int > unit tests", "[lattice_set]")
REQUIRE(domain.isInside(aPoint))