DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
exampleGenericLatticeConvexHull3D.cpp
Go to the documentation of this file.
1
26
57
58
#include <iostream>
59
#include <vector>
60
#include <random>
61
#include <algorithm>
62
#include <polyscope/polyscope.h>
63
#include <polyscope/surface_mesh.h>
64
#include <polyscope/point_cloud.h>
65
#include <polyscope/curve_network.h>
66
67
#include "DGtal/base/Common.h"
68
#include "DGtal/helpers/StdDefs.h"
69
#include "DGtal/geometry/tools/GenericLatticeConvexHull.h"
70
71
72
using namespace
DGtal
;
73
74
75
//Polyscope global
76
polyscope::PointCloud *
psPoints
;
77
polyscope::PointCloud *
psVertices
;
78
polyscope::PointCloud *
psBoundary0
;
79
polyscope::CurveNetwork *
psBoundary1
;
80
polyscope::SurfaceMesh *
psBoundary2
;
81
82
std::random_device
rd
;
83
std::mt19937
g
(
rd
());
84
85
template
<
typename
Po
int
>
86
static
87
std::vector< Point >
88
makeRandomLatticePointsFromDirVectors
(
Point
A
,
const
std::vector< Point>& V,
89
int
nb,
double
radius,
int
amplitude,
int
aff_dim )
90
{
91
std::uniform_int_distribution<int> U(-amplitude, amplitude);
92
std::vector< Point > P;
93
int
m = std::min( aff_dim, (
int
) V.size() );
94
for
(
auto
k = 0; P.size() < nb && k < 100000; k++ )
95
{
96
Point
B
=
A
;
97
for
(
auto
i = 0; i < m; i++ )
98
{
99
int
l = U(
g
);
100
B
+= l * V[ i ];
101
}
102
if
( (
B
-
A
).norm() <= radius )
103
P.push_back(
B
);
104
}
105
std::shuffle( P.begin(), P.end(),
g
);
106
return
P;
107
}
108
109
int
main
(
int
argc,
char
* argv[] )
110
{
111
typedef
GenericLatticeConvexHull< 3, int >
QHull;
112
typedef
SpaceND< 3, int >
Space
;
113
typedef
Space::Point
Point
;
114
115
std::cout <<
"Usage: "
<< argv[ 0 ] <<
" [R=30] [N=30] [D=2]\n"
;
116
std::cout <<
"Computes the convex hull of N points within a ball of radius R, these points belonging to a lattice of chosen dimension D.\n"
;
117
double
radius = argc > 1 ? atof( argv[ 1 ] ) : 30.0;
118
int
nb = argc > 2 ? atoi( argv[ 2 ] ) : 30;
119
int
adim = argc > 3 ? atoi( argv[ 3 ] ) : 2;
120
if
( nb < 0 )
return
1;
121
if
( adim < 0 || adim > 3 )
return
1;
122
123
// Create points
124
std::vector< Point >
L
= {
Point
{ 4, 1, -3 },
Point
{ 0, 2, 5 },
Point
{ -1, -3, 5 } };
125
std::vector< Point > X
126
=
makeRandomLatticePointsFromDirVectors
(
Point
(1,2,-1),
127
L
, nb,
128
radius,
129
int
( round( radius+0.5 ) ),
130
adim );
131
132
// Compute convex hull
133
QHull hull;
134
bool
ok = hull.compute( X );
135
std:: cout << ( ok ?
"[PASSED]"
:
"[FAILED]"
) <<
" hull="
<< hull <<
"\n"
;
136
// Initialize polyscope
137
polyscope::init();
138
psPoints
= polyscope::registerPointCloud(
"Points"
, X );
139
psVertices
= polyscope::registerPointCloud(
"Vertices"
, hull.positions );
140
if
( hull.affine_dimension <= 1 )
// 1 or 2 points
141
{
142
// no facets
143
psBoundary0
= polyscope::registerPointCloud(
"Convex hull bdy dim=0"
,
144
hull.positions );
145
}
146
else
if
( hull.affine_dimension == 2 )
// 2D
147
{
148
// facets are edges (and implicitly converted by polyscope)
149
psBoundary1
= polyscope::registerCurveNetwork(
"Convex hull bdy dim=1"
,
150
hull.positions, hull.facets );
151
psBoundary0
= polyscope::registerPointCloud(
"Projected points"
,
152
hull.projected_points );
153
std::set<Point> S( hull.projected_points.cbegin(),
154
hull.projected_points.cend() );
155
std::cout <<
"Projection basis=[ "
<< hull.affine_basis.basis()[0]
156
<<
","
<< hull.affine_basis.basis()[1] <<
" ]"
157
<<
" d="
<< hull.projected_dilation <<
"\n"
;
158
}
159
else
if
( hull.affine_dimension == 3 )
// 3D
160
{
161
// facets are polygons
162
psBoundary2
= polyscope::registerSurfaceMesh(
"Convex hull bdy dim=2"
,
163
hull.positions, hull.facets );
164
}
165
std::cout <<
" dilation="
<< hull.projected_dilation
166
<<
" => counting of lattice points is "
167
<< (hull.projected_dilation == 1 ?
"correct"
:
"INCORRECT"
) <<
".\n"
;
168
std::cout <<
" #(P ∩ Z3)="
<< hull.count() <<
"\n"
;
169
std::cout <<
"#(Int(P) ∩ Z3)="
<< hull.countInterior() <<
"\n"
;
170
std::cout <<
" #(Bd(P) ∩ Z3)="
<< hull.countBoundary() <<
"\n"
;
171
polyscope::show();
172
return
EXIT_SUCCESS;
173
174
}
B
Definition
testPartialTemplateSpecialization.cpp:63
DGtal::Point
DGtal::SpaceND< 3, Integer >::Point
PointVector< dim, Integer > Point
Definition
SpaceND.h:110
psVertices
polyscope::PointCloud * psVertices
Definition
dgtalCalculus-single.cpp:59
psBoundary0
polyscope::PointCloud * psBoundary0
Definition
exampleGenericLatticeConvexHull3D.cpp:78
psBoundary2
polyscope::SurfaceMesh * psBoundary2
Definition
exampleGenericLatticeConvexHull3D.cpp:80
psPoints
polyscope::PointCloud * psPoints
Definition
exampleGenericLatticeConvexHull3D.cpp:76
psBoundary1
polyscope::CurveNetwork * psBoundary1
Definition
exampleGenericLatticeConvexHull3D.cpp:79
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::ProbingMode::L
@ L
Definition
PlaneProbingTetrahedronEstimator.h:63
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
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
examples
io
external-viewers
polyscope
exampleGenericLatticeConvexHull3D.cpp
Generated on
for DGtal by
1.18.0