67 if (
n == 0 || !
x || !
y || !z )
return;
70 xmin = *std::min_element(
x,
x+
n);
71 xmax = *std::max_element(
x,
x+
n);
73 ymin = *std::min_element(
y,
y+
n);
74 ymax = *std::max_element(
y,
y+
n);
180 s.pointlist =
nullptr;
181 s.pointattributelist =
nullptr;
182 s.pointmarkerlist =
nullptr;
183 s.numberofpoints = 0;
184 s.numberofpointattributes = 0;
186 s.trianglelist =
nullptr;
187 s.triangleattributelist =
nullptr;
188 s.trianglearealist =
nullptr;
189 s.neighborlist =
nullptr;
190 s.numberoftriangles = 0;
191 s.numberofcorners = 0;
192 s.numberoftriangleattributes = 0;
194 s.segmentlist =
nullptr;
195 s.segmentmarkerlist =
nullptr;
196 s.numberofsegments = 0;
198 s.holelist =
nullptr;
201 s.regionlist =
nullptr;
202 s.numberofregions = 0;
204 s.edgelist =
nullptr;
205 s.edgemarkerlist =
nullptr;
206 s.normlist =
nullptr;
211 if(s.pointlist !=
nullptr)
free(s.pointlist);
212 if(s.pointattributelist !=
nullptr)
free(s.pointattributelist);
213 if(s.pointmarkerlist !=
nullptr)
free(s.pointmarkerlist);
215 if(s.trianglelist !=
nullptr)
free(s.trianglelist);
216 if(s.triangleattributelist !=
nullptr)
free(s.triangleattributelist);
217 if(s.trianglearealist !=
nullptr)
free(s.trianglearealist);
218 if(s.neighborlist !=
nullptr)
free(s.neighborlist);
220 if(s.segmentlist !=
nullptr)
free(s.segmentlist);
221 if(s.segmentmarkerlist !=
nullptr)
free(s.segmentmarkerlist);
223 if(s.holelist !=
nullptr)
free(s.holelist);
225 if(s.regionlist !=
nullptr)
free(s.regionlist);
227 if(s.edgelist !=
nullptr)
free(s.edgelist);
228 if(s.edgemarkerlist !=
nullptr)
free(s.edgemarkerlist);
229 if(s.normlist !=
nullptr)
free(s.normlist);
233 initStruct(in); initStruct(out);
248 for(
int t = 0; t < out.numberoftriangles; ++t){
251 auto transform = [&] (
const unsigned int v) {
253 tri.
idx[
v] = out.trianglelist[t*out.numberofcorners +
v];
272 tri.
invDenom = 1 / ( (tri.
y[1] - tri.
y[2])*(tri.
x[0] - tri.
x[2]) + (tri.
x[2] - tri.
x[1])*(tri.
y[0] - tri.
y[2]) );
276 auto bx = std::minmax({tri.
x[0], tri.
x[1], tri.
x[2]});
277 auto by = std::minmax({tri.
y[0], tri.
y[1], tri.
y[2]});
279 unsigned int cellXmin =
CellX(bx.first);
280 unsigned int cellXmax =
CellX(bx.second);
282 unsigned int cellYmin =
CellY(by.first);
283 unsigned int cellYmax =
CellY(by.second);
285 for(
unsigned int i = cellXmin; i <= cellXmax; ++i) {
286 for(
unsigned int j = cellYmin; j <= cellYmax; ++j) {
293 freeStruct(in); freeStruct(out);
307 auto bayCoords = [&](
const unsigned int t) -> std::tuple<double, double, double> {
315 return std::make_tuple(la, lb, (1 - la - lb));
323 auto inTriangle = [](
const std::tuple<double, double, double> &coords) ->
bool {
324 constexpr double eps = -4 * std::numeric_limits<double>::epsilon();
325 return std::get<0>(coords) > eps && std::get<1>(coords) > eps && std::get<2>(coords) > eps;
336 auto coords = bayCoords(t);
341 if (inTriangle(coords)) {
359void Delaunay2D::DonormalizePoints() {
365 fNormalizedPoints.insert(std::make_pair(
p,
n));
371 fCGALdelaunay.insert(fNormalizedPoints.begin(), fNormalizedPoints.end());
373 std::transform(fCGALdelaunay.finite_faces_begin(),
374 fCGALdelaunay.finite_faces_end(), std::back_inserter(
fTriangles),
375 [] (
const Delaunay::Face face) -> Triangle {
379 auto transform = [&] (const unsigned int i) {
380 tri.x[i] = face.vertex(i)->point().x();
381 tri.y[i] = face.vertex(i)->point().y();
382 tri.idx[i] = face.vertex(i)->info();
395double Delaunay2D::DoInterpolateNormalized(
double xx,
double yy)
407 std::vector<std::pair<Point, Coord_type> > coords;
408 auto nn = CGAL::natural_neighbor_coordinates_2(fCGALdelaunay,
p,
409 std::back_inserter(coords));
418 Coord_type res = CGAL::linear_interpolation(coords.begin(), coords.end(),
419 nn.second, Value_access(fNormalizedPoints, fZ));
winID h TVirtualViewer3D TVirtualGLPainter p
int fNpoints
! Number of data points
double fXNmin
! Minimum value of fXN
std::set< unsigned int > fCells[(fNCells+1) *(fNCells+1)]
! grid cells with containing triangles
int fNdt
! Number of Delaunay triangles found
double DoInterpolateNormalized(double x, double y)
internal method to compute the interpolation
int CellY(double y) const
double Interpolate(double x, double y)
Return the Interpolated z value corresponding to the given (x,y) point.
const double * fZ
! Pointer to Z array
double fXNmax
! Maximum value of fXN
double fZout
! Height for points lying outside the convex hull
double fOffsetY
! Normalization offset Y
Triangles fTriangles
! Triangles of Triangulation
double Linear_transform(double x, double offset, double factor)
double fYCellStep
! inverse denominator to calculate X cell = fNCells / (fYNmax - fYNmin)
std::vector< double > fYN
! normalized Y
Delaunay2D(int n, const double *x, const double *y, const double *z, double xmin=0, double xmax=0, double ymin=0, double ymax=0)
class constructor from array of data points
void FindAllTriangles()
Find all triangles.
static const int fNCells
! number of cells to divide the normalized space
bool fInit
! True if FindAllTriangles() has been performed
unsigned int Cell(unsigned int x, unsigned int y) const
std::vector< double > fXN
! normalized X
double fXCellStep
! inverse denominator to calculate X cell = fNCells / (fXNmax - fXNmin)
double fYNmin
! Minimum value of fYN
double fOffsetX
! Normalization offset X
const double * fY
! Pointer to Y array
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)
set the input points for building the graph
const double * fX
! Pointer to X array (managed externally)
void DoNormalizePoints()
internal function to normalize the points.
double fYNmax
! Maximum value of fYN
double fScaleFactorY
! Normalization factor Y
double fScaleFactorX
! Normalization factor X
void DoFindTriangles()
internal function to find the triangle use Triangle or CGAL if flag is set
int CellX(double x) const
Namespace for new Math classes and functions.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
void triangulate(char *triswitches, struct triangulateio *in, struct triangulateio *out, struct triangulateio *vorout)