VTK  9.5.20250620
vtkPolygon.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
115#ifndef vtkPolygon_h
116#define vtkPolygon_h
117
118#include "vtkCell.h"
119#include "vtkCellStatus.h" // For return type
120#include "vtkCommonDataModelModule.h" // For export macro
121
122VTK_ABI_NAMESPACE_BEGIN
123class vtkDoubleArray;
124class vtkIdTypeArray;
125class vtkLine;
126class vtkPoints;
127class vtkQuad;
128class vtkTriangle;
130
131class VTKCOMMONDATAMODEL_EXPORT vtkPolygon : public vtkCell
132{
133public:
134 static vtkPolygon* New();
135 vtkTypeMacro(vtkPolygon, vtkCell);
136 void PrintSelf(ostream& os, vtkIndent indent) override;
137
139
142 int GetCellType() override { return VTK_POLYGON; }
143 int GetCellDimension() override { return 2; }
144 int GetNumberOfEdges() override { return this->GetNumberOfPoints(); }
145 int GetNumberOfFaces() override { return 0; }
146 vtkCell* GetEdge(int edgeId) override;
147 vtkCell* GetFace(int) override { return nullptr; }
148 int CellBoundary(int subId, const double pcoords[3], vtkIdList* pts) override;
149 void Contour(double value, vtkDataArray* cellScalars, vtkIncrementalPointLocator* locator,
150 vtkCellArray* verts, vtkCellArray* lines, vtkCellArray* polys, vtkPointData* inPd,
151 vtkPointData* outPd, vtkCellData* inCd, vtkIdType cellId, vtkCellData* outCd) override;
152 void Clip(double value, vtkDataArray* cellScalars, vtkIncrementalPointLocator* locator,
153 vtkCellArray* tris, vtkPointData* inPd, vtkPointData* outPd, vtkCellData* inCd,
154 vtkIdType cellId, vtkCellData* outCd, int insideOut) override;
155 int EvaluatePosition(const double x[3], double closestPoint[3], int& subId, double pcoords[3],
156 double& dist2, double weights[]) override;
157 void EvaluateLocation(int& subId, const double pcoords[3], double x[3], double* weights) override;
158 int IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t, double x[3],
159 double pcoords[3], int& subId) override;
160 int TriangulateLocalIds(int index, vtkIdList* ptIds) override;
162 int subId, const double pcoords[3], const double* values, int dim, double* derivs) override;
163 int IsPrimaryCell() VTK_FUTURE_CONST override { return 0; }
165
172 double ComputeArea();
173
183 void InterpolateFunctions(const double x[3], double* sf) override;
184
186
190 static vtkCellStatus ComputeNormal(vtkPoints* p, int numPts, const vtkIdType* pts, double n[3]);
191 static vtkCellStatus ComputeNormal(vtkPoints* p, double n[3]);
192 static vtkCellStatus ComputeNormal(vtkIdTypeArray* ids, vtkPoints* pts, double n[3]);
194
199 static vtkCellStatus ComputeNormal(int numPts, double* pts, double n[3]);
200
207 bool IsConvex();
208
210
222 static bool IsConvex(vtkPoints* p, int numPts, const vtkIdType* pts);
223 static bool IsConvex(vtkIdTypeArray* ids, vtkPoints* p);
224 static bool IsConvex(vtkPoints* p);
226
228
253 vtkPoints* p, int numPts, const vtkIdType* pts, double centroid[3], double tolerance);
254 static bool ComputeCentroid(vtkPoints* p, int numPts, const vtkIdType* pts, double centroid[3]);
255 static bool ComputeCentroid(vtkIdTypeArray* ids, vtkPoints* pts, double centroid[3]);
257
266 static double ComputeArea(vtkPoints* p, vtkIdType numPts, const vtkIdType* pts, double normal[3]);
267
276 double p0[3], double p10[3], double& l10, double p20[3], double& l20, double n[3]);
277
289 static int PointInPolygon(double x[3], int numPts, double* pts, double bounds[6], double n[3]);
290
291 // Needed to remove warning "member function does not override any
292 // base class virtual member function"
293 int Triangulate(int index, vtkIdList* ptIds, vtkPoints* pts) override
294 {
295 return vtkCell::Triangulate(index, ptIds, pts);
296 }
297
303
311 int BoundedTriangulate(vtkIdList* outTris, double tol);
312
318 static double DistanceToPolygon(
319 double x[3], int numPts, double* pts, double bounds[6], double closest[3]);
320
329 static int IntersectPolygonWithPolygon(int npts, double* pts, double bounds[6], int npts2,
330 double* pts2, double bounds2[6], double tol, double x[3]);
331
344 vtkCell* cell1, vtkCell* cell2, double tol, double p0[3], double p1[3]);
345
347
353 vtkGetMacro(UseMVCInterpolation, bool);
354 vtkSetMacro(UseMVCInterpolation, bool);
356
358
366 vtkSetClampMacro(Tolerance, double, 0.0, 1.0);
367 vtkGetMacro(Tolerance, double);
369
370protected:
372 ~vtkPolygon() override;
373
374 // Compute the interpolation functions using Mean Value Coordinate.
375 void InterpolateFunctionsUsingMVC(const double x[3], double* weights);
376
377 // variables used by instances of this class
378 double Tolerance; // Intersection tolerance set by public API
379 double Tol; // Internal tolerance set by ComputeBounds()
380 void ComputeTolerance(); // Compute the internal tolerance Tol
381
382 int SuccessfulTriangulation; // Stops recursive triangulation if necessary
383 vtkIdList* Tris; // Output triangulation placed here
384
385 // These are used for internal computation.
390
391 // Parameter indicating whether to use Mean Value Coordinate algorithm
392 // for interpolation. The parameter is false by default.
394
395 // Helper methods for triangulation------------------------------
396 // Made public for external access
397public:
398 // Ear cut triangulation options. The order in which vertices are
399 // removed are controlled by different measures. Changing this can
400 // make subtle differences in some cases. Historically the
401 // PERIMETER2_TO_AREA_RATIO has been used.
403 {
404 PERIMETER2_TO_AREA_RATIO = 0,
405 DOT_PRODUCT = 1,
406 BEST_QUALITY = 2
407 };
408
410
418 int EarCutTriangulation(int measure = PERIMETER2_TO_AREA_RATIO);
419 int EarCutTriangulation(vtkIdList* outTris, int measure = PERIMETER2_TO_AREA_RATIO);
421
423
430 int UnbiasedEarCutTriangulation(int seed, int measure = PERIMETER2_TO_AREA_RATIO);
432 int seed, vtkIdList* outTris, int measure = PERIMETER2_TO_AREA_RATIO);
434
435private:
436 vtkPolygon(const vtkPolygon&) = delete;
437 void operator=(const vtkPolygon&) = delete;
438};
439
440VTK_ABI_NAMESPACE_END
441#endif
object to represent cell connectivity
represent and manipulate cell attribute data
abstract class to specify cell behavior
Definition vtkCell.h:129
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.
Definition vtkCell.h:207
abstract superclass for arrays of numeric data
dynamic, self-adjusting array of double
list of point or cell ids
Definition vtkIdList.h:133
dynamic, self-adjusting array of vtkIdType
Abstract class in support of both point location and point insertion.
a simple class to control print indentation
Definition vtkIndent.h:108
cell represents a 1D line
Definition vtkLine.h:132
represent and manipulate point attribute data
represent and manipulate 3D points
Definition vtkPoints.h:139
a cell that represents an n-sided polygon
Definition vtkPolygon.h:132
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.
int GetCellType() override
See the vtkCell API for descriptions of these methods.
Definition vtkPolygon.h:142
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.
vtkTriangle * Triangle
Definition vtkPolygon.h:386
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.
Definition vtkPolygon.h:144
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.
Definition vtkPolygon.h:293
void ComputeTolerance()
bool UseMVCInterpolation
Definition vtkPolygon.h:393
double Tolerance
Definition vtkPolygon.h:378
void InterpolateFunctionsUsingMVC(const double x[3], double *weights)
static vtkCellStatus ComputeNormal(vtkPoints *p, double n[3])
Computes the unit normal to the polygon.
int IsPrimaryCell() VTK_FUTURE_CONST override
See the vtkCell API for descriptions of these methods.
Definition vtkPolygon.h:163
int GetNumberOfFaces() override
See the vtkCell API for descriptions of these methods.
Definition vtkPolygon.h:145
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.
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.
Definition vtkPolygon.h:143
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
Definition vtkPolygon.h:382
vtkCell * GetEdge(int edgeId) override
See the vtkCell API for descriptions of these methods.
void EvaluateLocation(int &subId, const double pcoords[3], double x[3], double *weights) override
See the vtkCell API for descriptions of these methods.
int TriangulateLocalIds(int index, vtkIdList *ptIds) override
See the vtkCell API for descriptions of these methods.
vtkQuad * Quad
Definition vtkPolygon.h:387
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.
vtkIdList * Tris
Definition vtkPolygon.h:383
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.
~vtkPolygon() override
static bool IsConvex(vtkIdTypeArray *ids, vtkPoints *p)
Determine whether or not a polygon is convex.
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.
int EarCutTriangulation(vtkIdList *outTris, int measure=PERIMETER2_TO_AREA_RATIO)
A fast triangulation method.
vtkDoubleArray * TriScalars
Definition vtkPolygon.h:388
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.
Definition vtkPolygon.h:147
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.
vtkLine * Line
Definition vtkPolygon.h:389
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()
double Tol
Definition vtkPolygon.h:379
static vtkCellStatus ComputeCentroid(vtkPoints *p, int numPts, const vtkIdType *pts, double centroid[3], double tolerance)
Compute the centroid of a set of points.
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 cell that represents a 2D quadrilateral
Definition vtkQuad.h:87
a cell that represents a triangle
vtkCellStatus
Diagnostic values indicating how well-specified a cell is.
@ VTK_POLYGON
Definition vtkCellType.h:44
int vtkIdType
Definition vtkType.h:332