23 #include "vtkCommonDataModelModule.h"
29 VTK_ABI_NAMESPACE_BEGIN
63 int EvaluatePosition(
const double x[3],
double closestPoint[3],
int& subId,
double pcoords[3],
64 double& dist2,
double weights[])
override;
65 void EvaluateLocation(
int& subId,
const double pcoords[3],
double x[3],
double* weights)
override;
66 int IntersectWithLine(
const double p1[3],
const double p2[3],
double tol,
double& t,
double x[3],
67 double pcoords[3],
int& subId)
override;
70 int subId,
const double pcoords[3],
const double* values,
int dim,
double* derivs)
override;
107 static vtkCellStatus ComputeNormal(
int numPts,
double* pts,
double n[3]);
161 vtkPoints* p,
int numPts,
const vtkIdType* pts,
double centroid[3],
double tolerance);
162 static bool ComputeCentroid(
vtkPoints* p,
int numPts,
const vtkIdType* pts,
double centroid[3]);
173 static bool ComputeInteriorCircle(
193 int ParameterizePolygon(
194 double p0[3],
double p10[3],
double& l10,
double p20[3],
double& l20,
double n[3]);
207 static int PointInPolygon(
double x[3],
int numPts,
double* pts,
double bounds[6],
double n[3]);
220 int NonDegenerateTriangulate(
vtkIdList* outTris);
229 int BoundedTriangulate(
vtkIdList* outTris,
double tol);
236 static double DistanceToPolygon(
237 double x[3],
int numPts,
double* pts,
double bounds[6],
double closest[3]);
247 static int IntersectPolygonWithPolygon(
int npts,
double* pts,
double bounds[6],
int npts2,
248 double* pts2,
double bounds2[6],
double tol,
double x[3]);
261 static int IntersectConvex2DCells(
262 vtkCell* cell1,
vtkCell* cell2,
double tol,
double p0[3],
double p1[3]);
271 vtkGetMacro(UseMVCInterpolation,
bool);
272 vtkSetMacro(UseMVCInterpolation,
bool);
284 vtkSetClampMacro(Tolerance,
double, 0.0, 1.0);
285 vtkGetMacro(Tolerance,
double);
293 void InterpolateFunctionsUsingMVC(
const double x[3],
double* weights);
298 void ComputeTolerance();
323 PERIMETER2_TO_AREA_RATIO = 0,
337 int EarCutTriangulation(
int measure = PERIMETER2_TO_AREA_RATIO);
338 int EarCutTriangulation(
vtkIdList* outTris,
int measure = PERIMETER2_TO_AREA_RATIO);
349 int UnbiasedEarCutTriangulation(
int seed,
int measure = PERIMETER2_TO_AREA_RATIO);
350 int UnbiasedEarCutTriangulation(
351 int seed,
vtkIdList* outTris,
int measure = PERIMETER2_TO_AREA_RATIO);
382 template <
typename Po
intsRange,
typename CellIter>
383 static int CompactPolygonRing(
384 const PointsRange&
points, CellIter cell,
int cellSize, std::vector<int>& ring);
385 template <
typename Po
intsRange,
typename CellIter>
387 const PointsRange&
points, CellIter cell,
int cellSize, std::vector<int>& ring);
388 template <
typename Po
intsRange,
typename CellIter,
typename EmitFn>
389 static void EarClipPolygon3D(
const PointsRange&
points, CellIter cell,
int cellSize,
390 std::vector<int>& prevBuf, std::vector<int>& nextBuf, std::vector<int>& ring, EmitFn&& emit);
399 template <
typename Po
intsRange,
typename CellIter>
401 const PointsRange&
points, CellIter cell,
int cellSize, std::vector<int>& ring)
410 for (
int i = 0; i < cellSize; ++i)
414 auto pPrev = points[cell[ring.back()]];
415 auto pCur = points[cell[i]];
416 if (pPrev[0] == pCur[0] && pPrev[1] == pCur[1] && pPrev[2] == pCur[2])
424 if (ring.size() >= 2)
426 auto pFirst = points[cell[ring.front()]];
427 auto pLast = points[cell[ring.back()]];
428 if (pFirst[0] == pLast[0] && pFirst[1] == pLast[1] && pFirst[2] == pLast[2])
433 return static_cast<int>(ring.size());
437 template <
typename Po
intsRange,
typename CellIter>
439 const PointsRange&
points, CellIter cell,
int cellSize, std::vector<int>& ring)
442 return m >= 3 ?
static_cast<vtkIdType>(m - 2) : 0;
446 template <
typename Po
intsRange,
typename CellIter,
typename EmitFn>
448 std::vector<int>& prevBuf, std::vector<int>& nextBuf, std::vector<int>& ring, EmitFn&& emit)
459 auto P = [&](
int k) {
return points[cell[ring[k]]]; };
462 double normal[3] = { 0.0, 0.0, 0.0 };
464 auto pLast = P(m - 1);
465 double xp = pLast[0], yp = pLast[1], zp = pLast[2];
466 for (
int i = 0; i < m; ++i)
469 double x = pi[0], y = pi[1], z = pi[2];
470 normal[0] += (yp - y) * (zp + z);
471 normal[1] += (zp - z) * (xp + x);
472 normal[2] += (xp - x) * (yp + y);
481 auto emitRing = [&](
int a,
int b,
int c)
483 auto isBoundary = [m](
int x,
int y) ->
int
485 const int d = (y - x + m) % m;
486 return (d == 1 || d == m - 1) ? 1 : 0;
488 int mask = isBoundary(a, b);
489 mask |= isBoundary(b, c) << 1;
490 mask |= isBoundary(c, a) << 2;
491 emit(ring[a], ring[b], ring[c], mask);
494 const double normLen2 = normal[0] * normal[0] + normal[1] * normal[1] + normal[2] * normal[2];
499 for (
int i = 1; i < m - 1; ++i)
501 emitRing(0, i, i + 1);
509 for (
int i = 0; i < m; ++i)
511 prevBuf[i] = (i + m - 1) % m;
512 nextBuf[i] = (i + 1) % m;
515 auto isEar = [&](
int b) ->
bool
517 const int a = prevBuf[b];
518 const int c = nextBuf[b];
522 const double ax = pa[0], ay = pa[1], az = pa[2];
523 const double bx = pb[0], by = pb[1], bz = pb[2];
524 const double cx = pc[0], cy = pc[1], cz = pc[2];
527 const double e1x = bx - ax, e1y = by - ay, e1z = bz - az;
528 const double e2x = cx - bx, e2y = cy - by, e2z = cz - bz;
529 const double crx = e1y * e2z - e1z * e2y;
530 const double cry = e1z * e2x - e1x * e2z;
531 const double crz = e1x * e2y - e1y * e2x;
532 if (crx * normal[0] + cry * normal[1] + crz * normal[2] <= 0.0)
540 for (
int q = nextBuf[c]; q != a; q = nextBuf[q])
543 const double qx = pq[0], qy = pq[1], qz = pq[2];
544 auto sideOf = [&](
double sx,
double sy,
double sz,
double ex,
double ey,
double ez) ->
double
546 const double dx = ex - sx, dy = ey - sy, dz = ez - sz;
547 const double rx = qx - sx, ry = qy - sy, rz = qz - sz;
548 const double tcrx = dy * rz - dz * ry;
549 const double tcry = dz * rx - dx * rz;
550 const double tcrz = dx * ry - dy * rx;
551 return tcrx * normal[0] + tcry * normal[1] + tcrz * normal[2];
553 const double s1 = sideOf(ax, ay, az, bx, by, bz);
554 const double s2 = sideOf(bx, by, bz, cx, cy, cz);
555 const double s3 = sideOf(cx, cy, cz, ax, ay, az);
556 if (s1 > 0.0 && s2 > 0.0 && s3 > 0.0)
575 int safetyBudget = 2 * m;
576 while (remaining > 3 && safetyBudget > 0)
580 const int a = prevBuf[current];
581 const int c = nextBuf[current];
582 emitRing(a, current, c);
587 safetyBudget = 2 * m;
591 current = nextBuf[current];
601 const int head = current;
602 int v = nextBuf[
head];
606 emitRing(head, v, vn);
617 const int b = current;
618 const int a = prevBuf[b];
619 const int c = nextBuf[b];
623 VTK_ABI_NAMESPACE_END
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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...
represent and manipulate point attribute data
vtkIdType GetNumberOfPoints() const
Return the number of points in the cell.
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...
represent and manipulate cell attribute data
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...
Abstract class in support of both point location and point insertion.
virtual int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts)
Generate simplices of proper dimension.
int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts) override
Generate simplices of proper dimension.
a cell that represents a 2D quadrilateral
dynamic, self-adjusting array of vtkIdType
vtkSmartPointer< vtkDoubleArray > TriScalars
int GetNumberOfEdges() override
See the vtkCell API for descriptions of these methods.
virtual int CellBoundary(int subId, const double pcoords[3], vtkIdList *pts)=0
Given parametric coordinates of a point, return the closest cell boundary, and whether the point is i...
dynamic, self-adjusting array of double
a list of ids arranged in priority order
int GetNumberOfFaces() override
See the vtkCell API for descriptions of these methods.
int GetCellType() override
See the vtkCell API for descriptions of these methods.
cell represents a 1D line
abstract class to specify cell behavior
virtual void EvaluateLocation(int &subId, const double pcoords[3], double x[3], double *weights)=0
Determine global coordinate (x[3]) from subId and parametric coordinates.
a simple class to control print indentation
virtual int TriangulateLocalIds(int index, vtkIdList *ptIds)=0
Generate simplices of proper dimension.
list of point or cell ids
int SuccessfulTriangulation
vtkSmartPointer< vtkQuad > Quad
abstract superclass for arrays of numeric data
a cell that represents an n-sided polygon
virtual void InterpolateFunctions(const double pcoords[3], double *weight)
Compute the interpolation functions/derivatives (aka shape functions/derivatives) No-ops at this leve...
vtkSmartPointer< vtkPriorityQueue > EarClipQueue
vtkCellStatus
Diagnostic values indicating how well-specified a cell is.
virtual void Clip(double value, vtkDataArray *cellScalars, vtkIncrementalPointLocator *locator, vtkCellArray *connectivity, vtkPointData *inPd, vtkPointData *outPd, vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd, int insideOut)=0
Cut (or clip) the cell based on the input cellScalars and the specified value.
vtkCell * GetFace(int) override
See the vtkCell API for descriptions of these methods.
virtual int EvaluatePosition(const double x[3], double closestPoint[3], int &subId, double pcoords[3], double &dist2, double weights[])=0
Given a point x[3] return inside(=1), outside(=0) cell, or (-1) computational problem encountered; ev...
object to represent cell connectivity
virtual vtkCell * GetEdge(int edgeId)=0
Return the edge cell from the edgeId of the cell.
vtkSmartPointer< vtkTriangle > Triangle
a cell that represents a triangle
vtkSmartPointer< vtkLine > Line
virtual void Contour(double value, vtkDataArray *cellScalars, vtkIncrementalPointLocator *locator, vtkCellArray *verts, vtkCellArray *lines, vtkCellArray *polys, vtkPointData *inPd, vtkPointData *outPd, vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd)=0
Generate contouring primitives.
virtual void Derivatives(int subId, const double pcoords[3], const double *values, int dim, double *derivs)=0
Compute derivatives given cell subId and parametric coordinates.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkSmartPointer< vtkIdList > Tris
virtual int IntersectWithLine(const double p1[3], const double p2[3], double tol, double &t, double x[3], double pcoords[3], int &subId)=0
Intersect with a ray.
int GetCellDimension() override
See the vtkCell API for descriptions of these methods.
int IsPrimaryCell() VTK_FUTURE_CONST override
See the vtkCell API for descriptions of these methods.
represent and manipulate 3D points