DGtal 2.0.0
|
Aim: Implements the quickhull algorithm by Barber et al. [9], a famous arbitrary dimensional convex hull computation algorithm. It relies on dedicated geometric kernels for computing and comparing facet geometries. More...
#include <DGtal/geometry/tools/QuickHull.h>
Data Structures | |
struct | Facet |
Public Types | |
enum | { UNASSIGNED = (Index) -1 } |
Label for points that are not assigned to any facet. More... | |
enum class | Status { Uninitialized = 0 , InputInitialized = 1 , SimplexCompleted = 2 , FacetsCompleted = 3 , VerticesCompleted = 4 , AllCompleted = 5 , NotFullDimensional = 10 , InvalidRidge = 11 , InvalidConvexHull = 12 } |
Represents the status of a QuickHull object. More... | |
typedef TKernel | Kernel |
typedef Kernel::CoordinatePoint | Point |
typedef Kernel::CoordinateVector | Vector |
typedef Kernel::CoordinateScalar | Scalar |
typedef Kernel::InternalScalar | InternalScalar |
typedef std::size_t | Index |
typedef std::size_t | Size |
typedef std::vector< Index > | IndexRange |
typedef Kernel::HalfSpace | HalfSpace |
typedef Kernel::CombinatorialPlaneSimplex | CombinatorialPlaneSimplex |
typedef std::pair< Index, Index > | Ridge |
Public Member Functions | |
BOOST_STATIC_ASSERT ((Point::dimension==Vector::dimension)) | |
Standard services (construction, initialization, accessors) | |
QuickHull (const Kernel &K=Kernel(), int dbg=0) | |
Status | status () const |
void | clear () |
Clears the object. | |
Size | memory () const |
Size | nbPoints () const |
Size | nbFacets () const |
Size | nbVertices () const |
Size | nbFiniteFacets () const |
Size | nbInfiniteFacets () const |
Initialization services | |
template<typename InputPoint> | |
bool | setInput (const std::vector< InputPoint > &input_points, bool remove_duplicates=true) |
bool | setInitialSimplex (const IndexRange &full_splx) |
Convex hull services | |
bool | computeConvexHull (Status target=Status::VerticesCompleted) |
bool | computeInitialSimplex () |
bool | computeFacets () |
bool | computeVertices () |
Output services | |
template<typename OutputPoint> | |
bool | getVertexPositions (std::vector< OutputPoint > &vertex_positions) |
bool | getVertex2Point (IndexRange &vertex_to_point) |
bool | getPoint2Vertex (IndexRange &point_to_vertex) |
bool | getFacetVertices (std::vector< IndexRange > &facet_vertices) const |
bool | getFacetHalfSpaces (std::vector< HalfSpace > &facet_halfspaces) |
Check hull services | |
bool | check () |
bool | checkFacets () |
bool | checkHull () |
Interface | |
void | selfDisplay (std::ostream &out) const |
bool | isValid () const |
Data Fields | |
public datas | |
Kernel | kernel |
Kernel that is duplicated for computing facet geometries. | |
int | debug_level |
debug_level from 0:no to 2 | |
std::vector< Point > | points |
the set of points, indexed as in the array. | |
IndexRange | input2comp |
IndexRange | comp2input |
IndexRange | processed_points |
Points already processed (and within the convex hull). | |
std::vector< Index > | assignment |
assignment of points to facets | |
std::vector< Facet > | facets |
the current set of facets. | |
std::set< Index > | deleted_facets |
set of deleted facets | |
IndexRange | p2v |
point index -> vertex index (or UNASSIGNED) | |
IndexRange | v2p |
vertex index -> point index | |
Size | nb_finite_facets |
Number of finite facets. | |
Size | nb_infinite_facets |
Number of infinite facets (!= 0 only for specific kernels) | |
std::vector< double > | timings |
Timings of the different phases: 0: init, 1: facets, 2: vertices. | |
std::vector< Size > | facet_counter |
Counts the number of facets with a given number of vertices. |
Static Public Attributes | |
static const Size | dimension = Point::dimension |
Protected Attributes | |
protected datas | |
Status | myStatus |
protected services | |
InternalScalar | height (const Facet &F, const Point &p) const |
bool | above (const Facet &F, const Point &p) const |
bool | aboveOrOn (const Facet &F, const Point &p) const |
bool | on (const Facet &F, const Point &p) const |
void | cleanFacets () |
void | renumberInfiniteFacets () |
bool | processFacet (std::queue< Index > &Q) |
bool | checkFacet (Index f) const |
Index | newFacet () |
void | deleteFacet (Index f) |
void | makeNeighbors (const Index if1, const Index if2) |
void | unmakeNeighbors (const Index if1, const Index if2) |
Index | mergeParallelFacets (const Index if1, const Index if2) |
bool | areFacetsParallel (const Index if1, const Index if2) const |
bool | areFacetsNeighbor (const Index if1, const Index if2) const |
Facet | makeFacet (const IndexRange &base, Index below) const |
IndexRange | pointsOnRidge (const Ridge &R) const |
IndexRange | orientedFacetPoints (Index f) const |
void | filterVerticesOnFacet (const Index f) |
IndexRange | pickInitialSimplex () const |
bool | computeSimplexConfiguration (const IndexRange &full_simplex) |
static IndexRange | pickIntegers (const Size d, const Size n) |
Aim: Implements the quickhull algorithm by Barber et al. [9], a famous arbitrary dimensional convex hull computation algorithm. It relies on dedicated geometric kernels for computing and comparing facet geometries.
Description of template class 'QuickHull'
You can use it to build convex hulls of points with integral coordinate (using kernel ConvexHullIntegralKernel), convex hulls with rational coordinates (using kernel ConvexHullRationalKernel) or to build Delaunay triangulations (using kernels DelaunayIntegralKernel and DelaunayRationalKernel).
Below is a complete example that computes the convex hull of points randomly defined in a ball, builds a 3D mesh out of it and output it as an OBJ file.
TKernel | any type of QuickHull kernel, like ConvexHullIntegralKernel. |
Definition at line 139 of file QuickHull.h.
typedef Kernel::CombinatorialPlaneSimplex DGtal::QuickHull< TKernel >::CombinatorialPlaneSimplex |
Definition at line 151 of file QuickHull.h.
typedef Kernel::HalfSpace DGtal::QuickHull< TKernel >::HalfSpace |
Definition at line 150 of file QuickHull.h.
typedef std::size_t DGtal::QuickHull< TKernel >::Index |
Definition at line 146 of file QuickHull.h.
typedef std::vector< Index > DGtal::QuickHull< TKernel >::IndexRange |
Definition at line 149 of file QuickHull.h.
typedef Kernel::InternalScalar DGtal::QuickHull< TKernel >::InternalScalar |
Definition at line 145 of file QuickHull.h.
typedef TKernel DGtal::QuickHull< TKernel >::Kernel |
Definition at line 141 of file QuickHull.h.
typedef Kernel::CoordinatePoint DGtal::QuickHull< TKernel >::Point |
Definition at line 142 of file QuickHull.h.
typedef std::pair< Index, Index > DGtal::QuickHull< TKernel >::Ridge |
A ridge for point p is a pair of facets, such that p is visible from first facet, but not from second facet.
Definition at line 236 of file QuickHull.h.
typedef Kernel::CoordinateScalar DGtal::QuickHull< TKernel >::Scalar |
Definition at line 144 of file QuickHull.h.
typedef std::size_t DGtal::QuickHull< TKernel >::Size |
Definition at line 147 of file QuickHull.h.
typedef Kernel::CoordinateVector DGtal::QuickHull< TKernel >::Vector |
Definition at line 143 of file QuickHull.h.
anonymous enum |
Label for points that are not assigned to any facet.
Enumerator | |
---|---|
UNASSIGNED |
Definition at line 155 of file QuickHull.h.
|
strong |
Represents the status of a QuickHull object.
Enumerator | |
---|---|
Uninitialized | QuickHull is empty and has just been instantiated. |
InputInitialized | |
SimplexCompleted | An initial full-dimensional simplex has been found. QuickHull core algorithm can start. |
FacetsCompleted | All facets of the convex hull are identified. |
VerticesCompleted | All vertices of the convex hull are determined. |
AllCompleted | Same as VerticesCompleted. |
NotFullDimensional | Error: the initial simplex is not full dimensional. |
InvalidRidge | Error: some ridge is not consistent (probably integer overflow). |
InvalidConvexHull | Error: the convex hull does not contain all its points (probably integer overflow). |
Definition at line 239 of file QuickHull.h.
|
inline |
Default constructor
[in] | K | a kernel for computing facet geometries. |
[in] | dbg | the trace level, from 0 (no) to 3 (very verbose). |
Definition at line 259 of file QuickHull.h.
|
inlineprotected |
F | any valid facet |
p | any point |
Definition at line 856 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::checkFacet(), DGtal::QuickHull< Kernel3D >::checkHull(), DGtal::QuickHull< Kernel3D >::computeSimplexConfiguration(), and DGtal::QuickHull< Kernel3D >::processFacet().
|
inlineprotected |
F | any valid facet |
p | any point |
Definition at line 862 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::checkFacet(), and DGtal::QuickHull< Kernel3D >::processFacet().
|
inlineprotected |
Checks if two facets are neighbors by looking at the points on their boundary.
if1 | a valid facet index |
if2 | a valid facet index |
Definition at line 1267 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::checkFacet(), and DGtal::QuickHull< Kernel3D >::processFacet().
|
inlineprotected |
Checks if two distinct facets are parallel (i.e. should be merged).
if1 | a valid facet index |
if2 | a valid facet index |
Definition at line 1248 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::processFacet().
DGtal::QuickHull< TKernel >::BOOST_STATIC_ASSERT | ( | (Point::dimension==Vector::dimension) | ) |
|
inline |
Global validity check of the convex hull after processing.
Definition at line 715 of file QuickHull.h.
|
inlineprotected |
Definition at line 1136 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::checkFacets(), and DGtal::QuickHull< Kernel3D >::processFacet().
|
inline |
Definition at line 743 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::check(), DGtal::QuickHull< Kernel3D >::computeSimplexConfiguration(), and DGtal::QuickHull< Kernel3D >::processFacet().
|
inline |
Definition at line 762 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::check(), DGtal::QuickHull< Kernel3D >::computeSimplexConfiguration(), and DGtal::QuickHull< Kernel3D >::processFacet().
|
inlineprotected |
Cleans and renumber the facets so that no one belongs to deleted_facets.
Definition at line 873 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::computeFacets().
|
inline |
Clears the object.
Definition at line 270 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::setInput().
|
inline |
Computes the convex hull of the given range of points until a specified target:
[in] | target | the computation target in Status::SimplexCompleted, Status::FacetsCompleted, Status::VerticesCompleted. |
Definition at line 460 of file QuickHull.h.
Referenced by main().
|
inline |
Computes the facets of the convex hull using Quickhull algorithm. If everything went well, the status is Status::FacetsCompleted afterwards.
Definition at line 523 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::computeConvexHull().
|
inline |
Computes the initial full dimensional simplex from the input data.
Definition at line 504 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::computeConvexHull().
|
inlineprotected |
Computes the initial configuration induced by the given full dimensional simplex. Follows Status::InputInitialized and and terminate with Status::SimplexCompleted if everything went well.
Definition at line 1429 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::computeInitialSimplex(), and DGtal::QuickHull< Kernel3D >::setInitialSimplex().
|
inline |
Computes the vertices of the convex hull once the facets have been computed. It computes for each facet its vertices and reorder them so that, taken in order, their orientation matches the orientation of the facet. If everything went well, the status is Status::VerticesCompleted afterwards.
Definition at line 553 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::computeConvexHull().
|
inlineprotected |
Deletes the given facet f.
f | a valid facet index |
Definition at line 1193 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::processFacet().
|
inlineprotected |
Filters each vertex on the facet f to keep only the ones that are on or below the neighboring facets
[in] | f | any valid facet index. |
Definition at line 1352 of file QuickHull.h.
|
inline |
This methods return the halfspaces corresponding to each facet. It is useful to build a polytope.
[out] | facet_halfspaces | the range giving for each facet its halfspace as a pair (normal, intercept). |
Definition at line 690 of file QuickHull.h.
|
inline |
[out] | facet_vertices | the range giving for each facet the indices of its vertices. |
Definition at line 666 of file QuickHull.h.
Referenced by main().
|
inline |
Gets for each point its index in the output range of vertices (or UNASSIGNED if the point is not part of the convex hull)
[out] | point_to_vertex | the range giving for each point its index in the output range of vertices (or UNASSIGNED if the point is not part of the convex hull) |
Definition at line 651 of file QuickHull.h.
|
inline |
Gets for each vertex its index in the input range of points.
[out] | vertex_to_point | the range giving for each vertex its index in the input range of points. |
Definition at line 632 of file QuickHull.h.
|
inline |
Gets the positions of the convex hull vertices.
OutputPoint | a model of point such that the Point datatype is convertible to it. |
[out] | vertex_positions | the range of vertex positions. |
Definition at line 612 of file QuickHull.h.
Referenced by main().
|
inlineprotected |
F | any valid facet |
p | any point |
Definition at line 850 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::processFacet().
|
inline |
Checks the validity/consistency of the object.
Definition at line 1515 of file QuickHull.h.
|
inlineprotected |
Builds a facet from a base convex set of at least d different points and a point below.
[in] | base | a range containing at least d distinct points in general position. |
[in] | below | a point below the hyperplane containing simplex. |
Definition at line 1292 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::computeSimplexConfiguration(), and DGtal::QuickHull< Kernel3D >::processFacet().
|
inlineprotected |
Makes two distinct facets if1 and if2 as neighbors
if1 | a valid facet index |
if2 | a valid facet index |
Definition at line 1204 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::mergeParallelFacets(), and DGtal::QuickHull< Kernel3D >::processFacet().
|
inline |
Definition at line 287 of file QuickHull.h.
|
inlineprotected |
Merge the two facets and return the index of the second one, which is the one deleted.
if1 | a valid facet index |
if2 | a valid facet index |
Definition at line 1225 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::processFacet().
|
inline |
Definition at line 328 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::getFacetHalfSpaces(), DGtal::QuickHull< Kernel3D >::getFacetVertices(), main(), and DGtal::QuickHull< Kernel3D >::selfDisplay().
|
inline |
Definition at line 346 of file QuickHull.h.
|
inline |
Definition at line 355 of file QuickHull.h.
|
inline |
Definition at line 323 of file QuickHull.h.
Referenced by main(), and DGtal::QuickHull< Kernel3D >::selfDisplay().
|
inline |
Definition at line 337 of file QuickHull.h.
Referenced by main(), and DGtal::QuickHull< Kernel3D >::selfDisplay().
|
inlineprotected |
Definition at line 1183 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::processFacet().
|
inlineprotected |
F | any valid facet |
p | any point |
Definition at line 868 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::areFacetsParallel(), DGtal::QuickHull< Kernel3D >::checkFacet(), and DGtal::QuickHull< Kernel3D >::filterVerticesOnFacet().
|
inlineprotected |
Given a facet index f, return its points oriented consistently with respect to the normal.
f | any valid facet index |
Definition at line 1323 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::getFacetVertices().
|
inlineprotected |
Definition at line 1372 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::computeInitialSimplex().
|
inlinestaticprotected |
[in] | d | the number of returned integers |
[in] | n | the range of possible integers {0, 1, ..., n-1} |
Definition at line 1406 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::pickInitialSimplex().
|
inlineprotected |
[in] | R | a ridge between two facets (a pair of facets). |
Definition at line 1302 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::processFacet().
|
inlineprotected |
Process top facet in queue Q as in Quickhull algorithm, and updates the queue accordingly (top facet poped, new facets pushed).
[in,out] | Q | a queue of facet index to process. which is updated by the method. |
Definition at line 944 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::computeFacets().
|
inlineprotected |
Determine infinite facets and renumber them so that finite facets come first and infinite facets come after.
Definition at line 901 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::computeVertices().
|
inline |
Writes/Displays the object on an output stream.
out | the output stream where the object is written. |
Definition at line 1494 of file QuickHull.h.
|
inline |
Sets the initial full dimensional simplex
full_splx | a dimension+1-simplex specified as indices in the vector of input point. |
Definition at line 410 of file QuickHull.h.
|
inline |
Sets the input data for the QuickHull convex hull algorithm, which is a range of points.
InputPoint | a model of point that is convertible to Point datatype. |
[in] | input_points | the range of input points. |
[in] | remove_duplicates | should be set to 'true' if the input data has duplicates. |
Definition at line 382 of file QuickHull.h.
Referenced by main().
|
inline |
Definition at line 266 of file QuickHull.h.
Referenced by DGtal::QuickHull< Kernel3D >::check(), DGtal::QuickHull< Kernel3D >::computeConvexHull(), DGtal::QuickHull< Kernel3D >::computeFacets(), DGtal::QuickHull< Kernel3D >::computeSimplexConfiguration(), DGtal::QuickHull< Kernel3D >::computeVertices(), DGtal::QuickHull< Kernel3D >::getFacetHalfSpaces(), DGtal::QuickHull< Kernel3D >::getFacetVertices(), DGtal::QuickHull< Kernel3D >::getPoint2Vertex(), DGtal::QuickHull< Kernel3D >::getVertex2Point(), DGtal::QuickHull< Kernel3D >::getVertexPositions(), DGtal::QuickHull< Kernel3D >::isValid(), DGtal::QuickHull< Kernel3D >::nbFacets(), DGtal::QuickHull< Kernel3D >::nbFiniteFacets(), DGtal::QuickHull< Kernel3D >::nbInfiniteFacets(), DGtal::QuickHull< Kernel3D >::nbVertices(), DGtal::QuickHull< Kernel3D >::processFacet(), DGtal::QuickHull< Kernel3D >::selfDisplay(), and DGtal::QuickHull< Kernel3D >::setInitialSimplex().
|
inlineprotected |
std::vector< Index > DGtal::QuickHull< TKernel >::assignment |
assignment of points to facets
Definition at line 812 of file QuickHull.h.
IndexRange DGtal::QuickHull< TKernel >::comp2input |
the injective mapping between the convex hull point range and the input range.
Definition at line 808 of file QuickHull.h.
int DGtal::QuickHull< TKernel >::debug_level |
debug_level from 0:no to 2
Definition at line 800 of file QuickHull.h.
std::set< Index > DGtal::QuickHull< TKernel >::deleted_facets |
set of deleted facets
Definition at line 816 of file QuickHull.h.
|
static |
Definition at line 152 of file QuickHull.h.
std::vector< Size > DGtal::QuickHull< TKernel >::facet_counter |
Counts the number of facets with a given number of vertices.
Definition at line 828 of file QuickHull.h.
std::vector< Facet > DGtal::QuickHull< TKernel >::facets |
the current set of facets.
Definition at line 814 of file QuickHull.h.
IndexRange DGtal::QuickHull< TKernel >::input2comp |
the surjective mapping between the input range and the output range used for convex hull computation.
Definition at line 805 of file QuickHull.h.
|
mutable |
Kernel that is duplicated for computing facet geometries.
Definition at line 798 of file QuickHull.h.
|
protected |
The status of the object: Uninitialized, InputInitialized, SimplexCompleted, FacetsCompleted, VerticesCompleted, InvalidRidge, InvalidConvexHull, NotFullDimensional
Definition at line 839 of file QuickHull.h.
Size DGtal::QuickHull< TKernel >::nb_finite_facets |
Number of finite facets.
Definition at line 822 of file QuickHull.h.
Size DGtal::QuickHull< TKernel >::nb_infinite_facets |
Number of infinite facets (!= 0 only for specific kernels)
Definition at line 824 of file QuickHull.h.
IndexRange DGtal::QuickHull< TKernel >::p2v |
point index -> vertex index (or UNASSIGNED)
Definition at line 818 of file QuickHull.h.
std::vector< Point > DGtal::QuickHull< TKernel >::points |
the set of points, indexed as in the array.
Definition at line 802 of file QuickHull.h.
IndexRange DGtal::QuickHull< TKernel >::processed_points |
Points already processed (and within the convex hull).
Definition at line 810 of file QuickHull.h.
std::vector< double > DGtal::QuickHull< TKernel >::timings |
Timings of the different phases: 0: init, 1: facets, 2: vertices.
Definition at line 826 of file QuickHull.h.
Referenced by main().
IndexRange DGtal::QuickHull< TKernel >::v2p |
vertex index -> point index
Definition at line 820 of file QuickHull.h.