SynAPSE  0.6.0
Synergistic Analysis of Phase Space Evolution
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Voronoi.hh
1 #ifndef VORONOI_HH
2 #define VORONOI_HH
3 
4 // C++ includes
5 #include <iostream>
6 #include <ctime>
7 #include <cmath>
8 #include <vector>
9 #include <map>
10 
11 // ROOT includes
12 #include "TStyle.h"
13 #include "TCanvas.h"
14 #include "TPolyLine.h"
15 #include "TH2Poly.h"
16 #include "TGraph.h"
17 #include "TCanvas.h"
18 
19 // QHULL includes
20 #include "PointCoordinates.h"
21 #include "RboxPoints.h"
22 #include "QhullError.h"
23 #include "Qhull.h"
24 #include "QhullQh.h"
25 #include "QhullFacet.h"
26 #include "QhullFacetList.h"
27 #include "QhullFacetSet.h"
28 #include "QhullLinkedList.h"
29 #include "QhullVertex.h"
30 #include "QhullSet.h"
31 #include "QhullVertexSet.h"
32 
33 // NanoFLANN includes
34 #include <nanoflann.hpp>
35 #include "KDTreeVectorOfVectorsAdaptor.h"
36 
37 // Additional includes
38 #include "Vector.hh"
39 #include "Matrix.hh"
40 #include "Hull.hh"
41 
42 typedef KDTreeVectorOfVectorsAdaptor<std::vector<std::vector<double>>> KDTree;
43 
53 class Voronoi {
54  public:
56  Voronoi();
57 
65  Voronoi(const std::vector<std::vector<double>>& points,
66  const bool bounded=true,
67  const double alpha=0.,
68  const double eps=1e-6);
69 
71  Voronoi(const Voronoi& vor);
72 
74  Voronoi& operator=(const Voronoi& vor);
75 
77  ~Voronoi();
78 
80  void Initialize(const double alpha, const double eps);
81 
83  void Initialize1D(const double alpha, const double eps);
84 
86  const size_t GetNpoints() const { return _points.size(); }
87 
89  const std::vector<std::vector<double>>& GetPointArray() const { return _points; }
90 
92  const std::vector<double>& GetPoint(const size_t i) const { return _points[i]; }
93 
95  const std::vector<Hull>& GetCellArray() const { return _cells; }
96 
98  const Hull& GetCell(const size_t i) const { return _cells[i]; }
99 
101  const size_t& GetDimension() const { return _dim; }
102 
104  const bool& IsBounded() const { return _bounded; }
105 
107  size_t GetBestCellID(const std::vector<double>& v) const;
108 
110  const Hull& GetBestCell(const std::vector<double>& v) const;
111 
113  double SimplexVolume(const std::vector<double>& point) const;
114 
116  TPolyLine* BoundingBox() const;
117 
119  std::vector<TPolyLine*> Polygons() const;
120 
122  TH2Poly* DensityProfile() const;
123 
131  void Draw(std::string name="",
132  bool color=true,
133  bool points=false,
134  bool axes=false) const;
135 
136  private:
137 
138  size_t _dim;
139  std::vector<std::vector<double>> _points;
140  std::vector<Hull> _cells;
141  bool _bounded;
142  std::vector<double> _lower;
143  std::vector<double> _upper;
144  KDTree* _kdtree;
145 };
146 
147 #endif
Data stucture of a convex hull.
Definition: Hull.hh:25
const std::vector< double > & GetPoint(const size_t i) const
Returns a specific vertex.
Definition: Voronoi.hh:92
std::vector< double > _upper
Upper bounds in each dimension.
Definition: Voronoi.hh:143
const std::vector< Hull > & GetCellArray() const
Returns the array of cells corresponding to the array of vertice.
Definition: Voronoi.hh:95
void Initialize(const double alpha, const double eps)
Find the Voronoi tessellation of the N points.
Definition: Voronoi.cc:53
const bool & IsBounded() const
Returns true if box points have been added.
Definition: Voronoi.hh:104
std::vector< double > _lower
Lower bounds in each dimension.
Definition: Voronoi.hh:142
double SimplexVolume(const std::vector< double > &point) const
Returns the volume of a simplex in the current space.
Definition: Voronoi.cc:379
void Initialize1D(const double alpha, const double eps)
Find the Voronoi tessellation of the N points in 1D (special case)
Definition: Voronoi.cc:257
std::vector< Hull > _cells
Voronoi cells (subhulls)
Definition: Voronoi.hh:140
const Hull & GetCell(const size_t i) const
Returns a specific cell.
Definition: Voronoi.hh:98
KDTree * _kdtree
k-d Tree of the points to find NNs
Definition: Voronoi.hh:144
std::vector< TPolyLine * > Polygons() const
Returns an array of polygons to be drawn in ROOT (only 2D)
Definition: Voronoi.cc:425
Voronoi()
Default constructor, initilizes everything to 0.
Definition: Voronoi.cc:3
const std::vector< std::vector< double > > & GetPointArray() const
Returns the array of points on which the triangulation is constructed.
Definition: Voronoi.hh:89
std::vector< std::vector< double > > _points
Vector of N points.
Definition: Voronoi.hh:139
Computes the Voronoi tessellation of a set of points.
Definition: Voronoi.hh:53
const size_t GetNpoints() const
Returns the array of points on which the triangulation is constructed.
Definition: Voronoi.hh:86
const size_t & GetDimension() const
Returns the dimension of the tesselated space.
Definition: Voronoi.hh:101
Voronoi & operator=(const Voronoi &vor)
Equality operator.
Definition: Voronoi.cc:26
void Draw(std::string name="", bool color=true, bool points=false, bool axes=false) const
Draws the Voronoi tesselation on a canvas.
Definition: Voronoi.cc:485
size_t GetBestCellID(const std::vector< double > &v) const
Finds the closest cell and returns its hull.
Definition: Voronoi.cc:362
size_t _dim
Dimension of the space.
Definition: Voronoi.hh:138
const Hull & GetBestCell(const std::vector< double > &v) const
Finds the closest cell and returns its hull.
Definition: Voronoi.cc:373
bool _bounded
Switch to bound the points.
Definition: Voronoi.hh:141
TPolyLine * BoundingBox() const
Returns a rectangle to be drawn in ROOT (only 2D)
Definition: Voronoi.cc:401
TH2Poly * DensityProfile() const
Returns a histogram where each bin is a cell and its content is its density.
Definition: Voronoi.cc:439
~Voronoi()
Destructor.
Definition: Voronoi.cc:48