DGtal 2.1.0
Loading...
Searching...
No Matches
testGenericLatticeConvexHull.cpp File Reference
#include <iostream>
#include <vector>
#include <algorithm>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/geometry/tools/GenericLatticeConvexHull.h"
#include "DGtal/geometry/tools/AffineGeometry.h"
#include "DGtalCatch.h"
Include dependency graph for testGenericLatticeConvexHull.cpp:

Go to the source code of this file.

Functions

std::mt19937 g (rd())
 
template<typename Point >
std::vector< PointrandomPointsInBall (int nb, int R)
 
template<typename Point >
std::vector< PointmakeRandomLatticePointsFromDirVectors (int nb, const vector< Point > &V)
 
 SCENARIO ("GenericLatticeConvexHull< ConvexHullIntegralKernel< 2 > > unit tests", "[genquickhull][integral_kernel][2d]")
 
 SCENARIO ("GenericLatticeConvexHull< ConvexHullIntegralKernel< 3 > > unit tests", "[genquickhull][integral_kernel][3d]")
 

Variables

std::random_device rd
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2025/09/04

Functions for testing class GenericLatticeConvexHull.

This file is part of the DGtal library.

Definition in file testGenericLatticeConvexHull.cpp.

Function Documentation

◆ g()

std::mt19937 g ( rd()  )

◆ makeRandomLatticePointsFromDirVectors()

template<typename Point >
std::vector< Point > makeRandomLatticePointsFromDirVectors ( int  nb,
const vector< Point > &  V 
)

Definition at line 65 of file testGenericLatticeConvexHull.cpp.

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}
std::mt19937 g(rd())

References g().

Referenced by SCENARIO().

◆ randomPointsInBall()

template<typename Point >
std::vector< Point > randomPointsInBall ( int  nb,
int  R 
)
Examples
geometry/tools/checkLatticeBallQuickHull.cpp.

Definition at line 49 of file testGenericLatticeConvexHull.cpp.

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}
DGtal::uint32_t Dimension
Definition Common.h:119

References DGtal::R.

◆ SCENARIO() [1/2]

SCENARIO ( "GenericLatticeConvexHull< ConvexHullIntegralKernel< 2 > > unit tests"  ,
""  [genquickhull][integral_kernel][2d] 
)

Definition at line 93 of file testGenericLatticeConvexHull.cpp.

94{
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}
Aim: Implements the quickhull algorithm by Barber et al. , a famous arbitrary dimensional convex hull...
MyPointD Point
GIVEN("A cubical complex with random 3-cells")
REQUIRE(domain.isInside(aPoint))

References GIVEN(), and REQUIRE().

◆ SCENARIO() [2/2]

SCENARIO ( "GenericLatticeConvexHull< ConvexHullIntegralKernel< 3 > > unit tests"  ,
""  [genquickhull][integral_kernel][3d] 
)

Definition at line 150 of file testGenericLatticeConvexHull.cpp.

151{
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}
CAPTURE(thicknessHV)
std::vector< Point > makeRandomLatticePointsFromDirVectors(int nb, const vector< Point > &V)

References CAPTURE(), GIVEN(), makeRandomLatticePointsFromDirVectors(), and REQUIRE().

Variable Documentation

◆ rd

std::random_device rd

Definition at line 44 of file testGenericLatticeConvexHull.cpp.