14 #ifndef ROOT_Math_Delaunay2D
15 #define ROOT_Math_Delaunay2D
35 #pragma push_macro("PTR")
38 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
39 #include <CGAL/Delaunay_triangulation_2.h>
40 #include <CGAL/Triangulation_vertex_base_with_info_2.h>
41 #include <CGAL/Interpolation_traits_2.h>
42 #include <CGAL/natural_neighbor_coordinates_2.h>
43 #include <CGAL/interpolation_functions.h>
45 #pragma pop_macro("PTR")
85 typedef std::vector<Triangle> Triangles;
90 Delaunay2D(
int n,
const double *x,
const double * y,
const double * z,
double xmin=0,
double xmax=0,
double ymin=0,
double ymax=0);
93 void SetInputPoints(
int n,
const double *x,
const double * y,
const double * z,
double xmin=0,
double xmax=0,
double ymin=0,
double ymax=0);
96 double Interpolate(
double x,
double y);
99 void FindAllTriangles();
102 Int_t NumberOfTriangles()
const {
return fNdt;}
104 double XMin()
const {
return fXNmin;}
105 double XMax()
const {
return fXNmax;}
106 double YMin()
const {
return fYNmin;}
107 double YMax()
const {
return fYNmax;}
110 void SetZOuterValue(
double z=0.) { fZout = z; }
113 double ZOuterValue()
const {
return fZout; }
116 Triangles::const_iterator begin()
const {
return fTriangles.begin(); }
117 Triangles::const_iterator end()
const {
return fTriangles.end(); }
125 inline double Linear_transform(
double x,
double offset,
double factor){
126 return (x+offset)*factor;
130 void DoNormalizePoints();
134 void DoFindTriangles();
137 double DoInterpolateNormalized(
double x,
double y);
143 Delaunay2D(
const Delaunay2D&);
144 Delaunay2D& operator=(
const Delaunay2D&);
168 double fScaleFactorX;
169 double fScaleFactorY;
175 enum class Initialization : char {UNINITIALIZED, INITIALIZING, INITIALIZED};
176 std::atomic<Initialization> fInit;
183 Triangles fTriangles;
188 template<
class Po
intWithInfoMap,
typename ValueType >
189 struct Data_access :
public std::unary_function< typename PointWithInfoMap::key_type,
190 std::pair<ValueType, bool> >
193 Data_access(
const PointWithInfoMap& points,
const ValueType * values)
194 : _points(points), _values(values){};
196 std::pair< ValueType, bool>
197 operator()(
const typename PointWithInfoMap::key_type& p)
const {
198 typename PointWithInfoMap::const_iterator mit = _points.find(p);
199 if(mit!= _points.end())
200 return std::make_pair(_values[mit->second],
true);
201 return std::make_pair(ValueType(),
false);
204 const PointWithInfoMap& _points;
205 const ValueType * _values;
208 typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
209 typedef CGAL::Triangulation_vertex_base_with_info_2<uint, K> Vb;
210 typedef CGAL::Triangulation_data_structure_2<Vb> Tds;
211 typedef CGAL::Delaunay_triangulation_2<K, Tds> Delaunay;
212 typedef CGAL::Interpolation_traits_2<K> Traits;
213 typedef K::FT Coord_type;
214 typedef K::Point_2 Point;
215 typedef std::map<Point, Vb::Info, K::Less_xy_2> PointWithInfoMap;
216 typedef Data_access< PointWithInfoMap, double > Value_access;
218 Delaunay fCGALdelaunay;
219 PointWithInfoMap fNormalizedPoints;
261 std::vector<double> fXN;
262 std::vector<double> fYN;
269 static const int fNCells = 25;
272 std::set<UInt_t> fCells[(fNCells+1)*(fNCells+1)];
274 inline unsigned int Cell(UInt_t x, UInt_t y)
const {
275 return x*(fNCells+1) + y;
278 inline int CellX(
double x)
const {
279 return (x - fXNmin) * fXCellStep;
282 inline int CellY(
double y)
const {
283 return (y - fYNmin) * fYCellStep;