122#include "vtkCommonDataModelModule.h"
128VTK_ABI_NAMESPACE_BEGIN
162 int EvaluatePosition(
const double x[3],
double closestPoint[3],
int& subId,
double pcoords[3],
163 double& dist2,
double weights[])
override;
164 void EvaluateLocation(
int& subId,
const double pcoords[3],
double x[3],
double* weights)
override;
165 int IntersectWithLine(
const double p1[3],
const double p2[3],
double tol,
double& t,
double x[3],
166 double pcoords[3],
int& subId)
override;
169 int subId,
const double pcoords[3],
const double* values,
int dim,
double* derivs)
override;
260 vtkPoints* p,
int numPts,
const vtkIdType* pts,
double centroid[3],
double tolerance);
292 static double ComputeArea(
int numPts,
double* pts,
double normal[3]);
302 double p0[3],
double p10[3],
double& l10,
double p20[3],
double& l20,
double n[3]);
315 static int PointInPolygon(
double x[3],
int numPts,
double* pts,
double bounds[6],
double n[3]);
345 double x[3],
int numPts,
double* pts,
double bounds[6],
double closest[3]);
356 double* pts2,
double bounds2[6],
double tol,
double x[3]);
370 vtkCell* cell1,
vtkCell* cell2,
double tol,
double p0[3],
double p1[3]);
490 template <
typename Po
intsRange,
typename CellIter>
492 const PointsRange& points, CellIter cell,
int cellSize, std::vector<int>& ring);
493 template <
typename Po
intsRange,
typename CellIter>
495 const PointsRange& points, CellIter cell,
int cellSize, std::vector<int>& ring);
496 template <
typename Po
intsRange,
typename CellIter,
typename EmitFn>
497 static void EarClipPolygon3D(
const PointsRange& points, CellIter cell,
int cellSize,
498 std::vector<int>& prevBuf, std::vector<int>& nextBuf, std::vector<int>& ring, EmitFn&& emit);
507template <
typename Po
intsRange,
typename CellIter>
509 const PointsRange& points, CellIter cell,
int cellSize, std::vector<int>& ring)
518 for (
int i = 0; i < cellSize; ++i)
522 auto pPrev = points[cell[ring.back()]];
523 auto pCur = points[cell[i]];
524 if (pPrev[0] == pCur[0] && pPrev[1] == pCur[1] && pPrev[2] == pCur[2])
532 if (ring.size() >= 2)
534 auto pFirst = points[cell[ring.front()]];
535 auto pLast = points[cell[ring.back()]];
536 if (pFirst[0] == pLast[0] && pFirst[1] == pLast[1] && pFirst[2] == pLast[2])
541 return static_cast<int>(ring.size());
545template <
typename Po
intsRange,
typename CellIter>
547 const PointsRange& points, CellIter cell,
int cellSize, std::vector<int>& ring)
550 return m >= 3 ?
static_cast<vtkIdType>(m - 2) : 0;
554template <
typename Po
intsRange,
typename CellIter,
typename EmitFn>
556 std::vector<int>& prevBuf, std::vector<int>& nextBuf, std::vector<int>& ring, EmitFn&& emit)
567 auto P = [&](
int k) {
return points[cell[ring[k]]]; };
570 double normal[3] = { 0.0, 0.0, 0.0 };
572 auto pLast = P(m - 1);
573 double xp = pLast[0], yp = pLast[1], zp = pLast[2];
574 for (
int i = 0; i < m; ++i)
577 double x = pi[0], y = pi[1], z = pi[2];
578 normal[0] += (yp - y) * (zp + z);
579 normal[1] += (zp - z) * (xp + x);
580 normal[2] += (xp - x) * (yp + y);
589 auto emitRing = [&](
int a,
int b,
int c)
591 auto isBoundary = [m](
int x,
int y) ->
int
593 const int d = (y - x + m) % m;
594 return (d == 1 || d == m - 1) ? 1 : 0;
596 int mask = isBoundary(a, b);
597 mask |= isBoundary(b, c) << 1;
598 mask |= isBoundary(c, a) << 2;
599 emit(ring[a], ring[b], ring[c], mask);
602 const double normLen2 = normal[0] * normal[0] + normal[1] * normal[1] + normal[2] * normal[2];
607 for (
int i = 1; i < m - 1; ++i)
609 emitRing(0, i, i + 1);
617 for (
int i = 0; i < m; ++i)
619 prevBuf[i] = (i + m - 1) % m;
620 nextBuf[i] = (i + 1) % m;
623 auto isEar = [&](
int b) ->
bool
625 const int a = prevBuf[b];
626 const int c = nextBuf[b];
630 const double ax = pa[0], ay = pa[1], az = pa[2];
631 const double bx = pb[0], by = pb[1], bz = pb[2];
632 const double cx = pc[0], cy = pc[1], cz = pc[2];
635 const double e1x = bx - ax, e1y = by - ay, e1z = bz - az;
636 const double e2x = cx - bx, e2y = cy - by, e2z = cz - bz;
637 const double crx = e1y * e2z - e1z * e2y;
638 const double cry = e1z * e2x - e1x * e2z;
639 const double crz = e1x * e2y - e1y * e2x;
640 if (crx * normal[0] + cry * normal[1] + crz * normal[2] <= 0.0)
648 for (
int q = nextBuf[c]; q != a; q = nextBuf[q])
651 const double qx = pq[0], qy = pq[1], qz = pq[2];
652 auto sideOf = [&](
double sx,
double sy,
double sz,
double ex,
double ey,
double ez) ->
double
654 const double dx = ex - sx, dy = ey - sy, dz = ez - sz;
655 const double rx = qx - sx, ry = qy - sy, rz = qz - sz;
656 const double tcrx = dy * rz - dz * ry;
657 const double tcry = dz * rx - dx * rz;
658 const double tcrz = dx * ry - dy * rx;
659 return tcrx * normal[0] + tcry * normal[1] + tcrz * normal[2];
661 const double s1 = sideOf(ax, ay, az, bx, by, bz);
662 const double s2 = sideOf(bx, by, bz, cx, cy, cz);
663 const double s3 = sideOf(cx, cy, cz, ax, ay, az);
664 if (s1 > 0.0 &&
s2 > 0.0 && s3 > 0.0)
683 int safetyBudget = 2 * m;
684 while (remaining > 3 && safetyBudget > 0)
688 const int a = prevBuf[current];
689 const int c = nextBuf[current];
690 emitRing(a, current, c);
695 safetyBudget = 2 * m;
699 current = nextBuf[current];
709 const int head = current;
710 int v = nextBuf[head];
714 emitRing(head, v, vn);
725 const int b = current;
726 const int a = prevBuf[b];
727 const int c = nextBuf[b];
object to represent cell connectivity
represent and manipulate cell attribute data
virtual int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts)
Generate simplices of proper dimension.
vtkIdType GetNumberOfPoints() const
Return the number of points in the cell.
dynamic, self-adjusting array of double
list of point or cell ids
dynamic, self-adjusting array of vtkIdType
Abstract class in support of both point location and point insertion.
a simple class to control print indentation
cell represents a 1D line
represent and manipulate point attribute data
represent and manipulate 3D points
static int PointInPolygon(double x[3], int numPts, double *pts, double bounds[6], double n[3])
Determine whether a point is inside the specified polygon.
double ComputeArea()
Compute the area of a polygon.
@ PERIMETER2_TO_AREA_RATIO
int GetCellType() override
See the vtkCell API for descriptions of these methods.
void Clip(double value, vtkDataArray *cellScalars, vtkIncrementalPointLocator *locator, vtkCellArray *tris, vtkPointData *inPd, vtkPointData *outPd, vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd, int insideOut) override
See the vtkCell API for descriptions of these methods.
static vtkIdType EarClipTriangleCount(const PointsRange &points, CellIter cell, int cellSize, std::vector< int > &ring)
Templated, allocation-free ear-clip triangulation of a simple (possibly non-convex) 3D polygon,...
static bool IsConvex(vtkPoints *p, int numPts, const vtkIdType *pts)
Determine whether or not a polygon is convex.
int CellBoundary(int subId, const double pcoords[3], vtkIdList *pts) override
See the vtkCell API for descriptions of these methods.
int UnbiasedEarCutTriangulation(int seed, int measure=PERIMETER2_TO_AREA_RATIO)
A fast triangulation method.
static int IntersectPolygonWithPolygon(int npts, double *pts, double bounds[6], int npts2, double *pts2, double bounds2[6], double tol, double x[3])
Method intersects two polygons.
int GetNumberOfEdges() override
See the vtkCell API for descriptions of these methods.
static bool IsConvex(vtkPoints *p)
Determine whether or not a polygon is convex.
int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts) override
Generate simplices of proper dimension.
void InterpolateFunctionsUsingMVC(const double x[3], double *weights)
static vtkCellStatus ComputeNormal(vtkPoints *p, double n[3])
Computes the unit normal to the polygon.
static int CompactPolygonRing(const PointsRange &points, CellIter cell, int cellSize, std::vector< int > &ring)
Templated, allocation-free ear-clip triangulation of a simple (possibly non-convex) 3D polygon,...
int IsPrimaryCell() VTK_FUTURE_CONST override
See the vtkCell API for descriptions of these methods.
int GetNumberOfFaces() override
See the vtkCell API for descriptions of these methods.
int EvaluatePosition(const double x[3], double closestPoint[3], int &subId, double pcoords[3], double &dist2, double weights[]) override
See the vtkCell API for descriptions of these methods.
vtkSmartPointer< vtkIdList > Tris
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int NonDegenerateTriangulate(vtkIdList *outTris)
Same as Triangulate(vtkIdList *outTris) but with a first pass to split the polygon into non-degenerat...
int GetCellDimension() override
See the vtkCell API for descriptions of these methods.
static double DistanceToPolygon(double x[3], int numPts, double *pts, double bounds[6], double closest[3])
Compute the distance of a point to a polygon.
int SuccessfulTriangulation
vtkCell * GetEdge(int edgeId) override
See the vtkCell API for descriptions of these methods.
~vtkPolygon() override=default
vtkSmartPointer< vtkTriangle > Triangle
void EvaluateLocation(int &subId, const double pcoords[3], double x[3], double *weights) override
See the vtkCell API for descriptions of these methods.
vtkSmartPointer< vtkLine > Line
int TriangulateLocalIds(int index, vtkIdList *ptIds) override
See the vtkCell API for descriptions of these methods.
void Derivatives(int subId, const double pcoords[3], const double *values, int dim, double *derivs) override
See the vtkCell API for descriptions of these methods.
static vtkCellStatus ComputeNormal(vtkPoints *p, int numPts, const vtkIdType *pts, double n[3])
Computes the unit normal to the polygon.
void Contour(double value, vtkDataArray *cellScalars, vtkIncrementalPointLocator *locator, vtkCellArray *verts, vtkCellArray *lines, vtkCellArray *polys, vtkPointData *inPd, vtkPointData *outPd, vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd) override
See the vtkCell API for descriptions of these methods.
static bool IsConvex(vtkIdTypeArray *ids, vtkPoints *p)
Determine whether or not a polygon is convex.
static double ComputeArea(int numPts, double *pts, double normal[3])
Compute the area of a polygon from a flat array of 3D point coordinates (packed as x0,...
int IntersectWithLine(const double p1[3], const double p2[3], double tol, double &t, double x[3], double pcoords[3], int &subId) override
See the vtkCell API for descriptions of these methods.
int ParameterizePolygon(double p0[3], double p10[3], double &l10, double p20[3], double &l20, double n[3])
Create a local s-t coordinate system for a polygon.
vtkSmartPointer< vtkDoubleArray > TriScalars
int EarCutTriangulation(vtkIdList *outTris, int measure=PERIMETER2_TO_AREA_RATIO)
A fast triangulation method.
static void EarClipPolygon3D(const PointsRange &points, CellIter cell, int cellSize, std::vector< int > &prevBuf, std::vector< int > &nextBuf, std::vector< int > &ring, EmitFn &&emit)
Templated, allocation-free ear-clip triangulation of a simple (possibly non-convex) 3D polygon,...
vtkSmartPointer< vtkQuad > Quad
static vtkCellStatus ComputeNormal(vtkIdTypeArray *ids, vtkPoints *pts, double n[3])
Computes the unit normal to the polygon.
int BoundedTriangulate(vtkIdList *outTris, double tol)
Triangulate polygon and enforce that the ratio of the smallest triangle area to the polygon area is g...
int EarCutTriangulation(int measure=PERIMETER2_TO_AREA_RATIO)
A fast triangulation method.
vtkCell * GetFace(int) override
See the vtkCell API for descriptions of these methods.
static bool ComputeCentroid(vtkPoints *p, int numPts, const vtkIdType *pts, double centroid[3])
Compute the centroid of a set of points.
static double ComputeArea(vtkPoints *p, vtkIdType numPts, const vtkIdType *pts, double normal[3])
Compute the area of a polygon in 3D.
void InterpolateFunctions(const double x[3], double *sf) override
Compute the interpolation functions/derivatives.
bool IsConvex()
Determine whether or not a polygon is convex.
static bool ComputeCentroid(vtkIdTypeArray *ids, vtkPoints *pts, double centroid[3])
Compute the centroid of a set of points.
static vtkCellStatus ComputeNormal(int numPts, double *pts, double n[3])
Compute the polygon normal from an array of points.
int UnbiasedEarCutTriangulation(int seed, vtkIdList *outTris, int measure=PERIMETER2_TO_AREA_RATIO)
A fast triangulation method.
static vtkPolygon * New()
static bool ComputeInteriorCircle(vtkPoints *p, int numPts, const vtkIdType *ids, double center[3], double &radius2)
Compute a circle interior to a polygon.
static vtkCellStatus ComputeCentroid(vtkPoints *p, int numPts, const vtkIdType *pts, double centroid[3], double tolerance)
Compute the centroid of a set of points.
vtkSmartPointer< vtkPriorityQueue > EarClipQueue
static int IntersectConvex2DCells(vtkCell *cell1, vtkCell *cell2, double tol, double p0[3], double p1[3])
Intersect two convex 2D polygons to produce a line segment as output.
a list of ids arranged in priority order
a cell that represents a 2D quadrilateral
Hold a reference to a vtkObjectBase instance.
a cell that represents a triangle
vtkCellStatus
Diagnostic values indicating how well-specified a cell is.