Computes the convex hull of N 3D points within a ball of radius R, these points belonging to a lattice of chosen dimension D.
#include <iostream>
#include <vector>
#include <random>
#include <algorithm>
#include <polyscope/polyscope.h>
#include <polyscope/surface_mesh.h>
#include <polyscope/point_cloud.h>
#include <polyscope/curve_network.h>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/tools/GenericLatticeConvexHull.h"
template < typename Point >
static
std::vector< Point >
int nb, double radius, int amplitude, int aff_dim )
{
std::uniform_int_distribution<int> U(-amplitude, amplitude);
std::vector< Point > P;
int m = std::min( aff_dim, (int) V.size() );
for ( auto k = 0; P.size() < nb && k < 100000; k++ )
{
for ( auto i = 0; i < m; i++ )
{
}
if ( (
B-
A).norm() <= radius )
}
std::shuffle( P.begin(), P.end(),
g );
return P;
}
int main(
int argc,
char* argv[] )
{
typedef Space::Point
Point;
std::cout << "Usage: " << argv[ 0 ] << " [R=30] [N=30] [D=2]\n";
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";
double radius = argc > 1 ? atof( argv[ 1 ] ) : 30.0;
int nb = argc > 2 ? atoi( argv[ 2 ] ) : 30;
int adim = argc > 3 ? atoi( argv[ 3 ] ) : 2;
if ( nb < 0 ) return 1;
if ( adim < 0 || adim > 3 ) return 1;
std::vector< Point >
L = {
Point{ 4, 1, -3 },
Point{ 0, 2, 5 },
Point{ -1, -3, 5 } };
std::vector< Point > X
L, nb,
radius,
int( round( radius+0.5 ) ),
adim );
QHull hull;
bool ok = hull.compute( X );
std:: cout << ( ok ? "[PASSED]" : "[FAILED]" ) << " hull=" << hull << "\n";
polyscope::init();
psPoints = polyscope::registerPointCloud(
"Points", X );
psVertices = polyscope::registerPointCloud(
"Vertices", hull.positions );
if ( hull.affine_dimension <= 1 )
{
psBoundary0 = polyscope::registerPointCloud(
"Convex hull bdy dim=0",
hull.positions );
}
else if ( hull.affine_dimension == 2 )
{
psBoundary1 = polyscope::registerCurveNetwork(
"Convex hull bdy dim=1",
hull.positions, hull.facets );
psBoundary0 = polyscope::registerPointCloud(
"Projected points",
hull.projected_points );
std::set<Point> S( hull.projected_points.cbegin(),
hull.projected_points.cend() );
std::cout << "Projection basis=[ " << hull.affine_basis.basis()[0]
<< "," << hull.affine_basis.basis()[1] << " ]"
<< " d=" << hull.projected_dilation << "\n";
}
else if ( hull.affine_dimension == 3 )
{
psBoundary2 = polyscope::registerSurfaceMesh(
"Convex hull bdy dim=2",
hull.positions, hull.facets );
}
std::cout << " dilation=" << hull.projected_dilation
<< " => counting of lattice points is "
<< (hull.projected_dilation == 1 ? "correct" : "INCORRECT") << ".\n";
std::cout << " #(P ∩ Z3)=" << hull.count() << "\n";
std::cout << "#(Int(P) ∩ Z3)=" << hull.countInterior() << "\n";
std::cout << " #(Bd(P) ∩ Z3)=" << hull.countBoundary() << "\n";
polyscope::show();
return EXIT_SUCCESS;
}
polyscope::PointCloud * psVertices
polyscope::PointCloud * psBoundary0
polyscope::SurfaceMesh * psBoundary2
polyscope::PointCloud * psPoints
polyscope::CurveNetwork * psBoundary1
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: Implements the quickhull algorithm by Barber et al. , a famous arbitrary dimensional convex hull...
std::vector< Point > makeRandomLatticePointsFromDirVectors(int nb, const vector< Point > &V)