DGtal 2.1.0
Loading...
Searching...
No Matches
exampleGenericLatticeConvexHull.cpp
Go to the documentation of this file.
1
46#include <iostream>
47#include <format>
48#include <vector>
50#include "DGtal/base/Common.h"
51#include "DGtal/kernel/SpaceND.h"
52#include "DGtal/geometry/tools/GenericLatticeConvexHull.h"
53int main()
54{
55 using namespace DGtal;
56 // point coordinates are int (32 bits), computation with int64_t
59 typedef Space::Point Point;
60
61 std::size_t nb_ok [ 4 ] = { 0, 0, 0, 0 };
62 std::size_t nb_per_dim [ 4 ] = { 0, 0, 0, 0 };
63 std::size_t nb_vertices[ 4 ] = { 0, 0, 0, 0 };
64 std::size_t nb_facets [ 4 ] = { 0, 0, 0, 0 };
65 const std::size_t nb = 100000;
66 for ( std::size_t n = 0; n < nb; ++n )
67 {
68 // Create a random set of points
69 std::vector< Point > X;
70 int m = 2 + rand() % 9; //< number of points
71 for ( int i = 0; i < m; i++ )
72 X.push_back( Point{ rand() % 8, rand() % 8, rand() % 8 } );
73 // Compute convex hull
74 QHull hull;
75 bool ok = hull.compute( X );
76 auto k = hull.affine_dimension; // affine dimension of X
77 // Compute statistics
78 nb_per_dim [ k ] += 1;
79 nb_vertices[ k ] += hull.positions.size(); // positions of vertices
80 nb_facets [ k ] += hull.facets.size(); // facets
81 nb_ok [ k ] += ok ? 1 : 0;
82 }
83 for ( auto k = 0; k < 4; k++ )
84 std::cout << std::setprecision(3) << ( 100.0 * nb_per_dim[ k ] ) / nb
85 << "% are " << k << "-dimensional"
86 << " #V=" << double( nb_vertices[ k ] ) / nb_per_dim[ k ]
87 << " #F=" << double( nb_facets[ k ] ) / nb_per_dim[ k ]
88 << " (" << nb_ok[ k ] << "/" << nb_per_dim[ k ] << ")\n";
89 return 0;
90}
int main()
[generic-qhull-example]
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...
MyPointD Point