VTK  9.3.20240415
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 "vtkCommonDataModelModule.h" // For export macro
120 #include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_3_0
121 
122 VTK_ABI_NAMESPACE_BEGIN
123 class vtkDoubleArray;
124 class vtkIdTypeArray;
125 class vtkLine;
126 class vtkPoints;
127 class vtkQuad;
128 class vtkTriangle;
130 
131 class VTKCOMMONDATAMODEL_EXPORT vtkPolygon : public vtkCell
132 {
133 public:
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() override { return 0; }
165 
172  double ComputeArea();
173 
183  void InterpolateFunctions(const double x[3], double* sf) override;
184 
186 
190  static void ComputeNormal(vtkPoints* p, int numPts, const vtkIdType* pts, double n[3]);
191  static void ComputeNormal(vtkPoints* p, double n[3]);
192  static void ComputeNormal(vtkIdTypeArray* ids, vtkPoints* pts, double n[3]);
194 
199  static void ComputeNormal(int numPts, double* pts, double n[3]);
200 
207  bool IsConvex();
208 
210 
214  static bool IsConvex(vtkPoints* p, int numPts, const vtkIdType* pts);
215  static bool IsConvex(vtkIdTypeArray* ids, vtkPoints* p);
216  static bool IsConvex(vtkPoints* p);
218 
220 
224  static bool ComputeCentroid(vtkPoints* p, int numPts, const vtkIdType* pts, double centroid[3]);
225  static bool ComputeCentroid(vtkIdTypeArray* ids, vtkPoints* pts, double centroid[3]);
227 
236  static double ComputeArea(vtkPoints* p, vtkIdType numPts, const vtkIdType* pts, double normal[3]);
237 
246  double p0[3], double p10[3], double& l10, double p20[3], double& l20, double n[3]);
247 
259  static int PointInPolygon(double x[3], int numPts, double* pts, double bounds[6], double n[3]);
260 
261  // Needed to remove warning "member function does not override any
262  // base class virtual member function"
263  int Triangulate(int index, vtkIdList* ptIds, vtkPoints* pts) override
264  {
265  return vtkCell::Triangulate(index, ptIds, pts);
266  }
275  VTK_DEPRECATED_IN_9_3_0("Replaced by its parent's implementation vtkCell::TriangulateLocalIds")
276  int Triangulate(vtkIdList* outTris);
277 
282  int NonDegenerateTriangulate(vtkIdList* outTris);
283 
291  int BoundedTriangulate(vtkIdList* outTris, double tol);
292 
298  static double DistanceToPolygon(
299  double x[3], int numPts, double* pts, double bounds[6], double closest[3]);
300 
309  static int IntersectPolygonWithPolygon(int npts, double* pts, double bounds[6], int npts2,
310  double* pts2, double bounds2[6], double tol, double x[3]);
311 
323  static int IntersectConvex2DCells(
324  vtkCell* cell1, vtkCell* cell2, double tol, double p0[3], double p1[3]);
325 
327 
333  vtkGetMacro(UseMVCInterpolation, bool);
334  vtkSetMacro(UseMVCInterpolation, bool);
336 
338 
346  vtkSetClampMacro(Tolerance, double, 0.0, 1.0);
347  vtkGetMacro(Tolerance, double);
349 
350 protected:
352  ~vtkPolygon() override;
353 
354  // Compute the interpolation functions using Mean Value Coordinate.
355  void InterpolateFunctionsUsingMVC(const double x[3], double* weights);
356 
357  // variables used by instances of this class
358  double Tolerance; // Intersection tolerance set by public API
359  double Tol; // Internal tolerance set by ComputeBounds()
360  void ComputeTolerance(); // Compute the internal tolerance Tol
361 
362  int SuccessfulTriangulation; // Stops recursive triangulation if necessary
363  vtkIdList* Tris; // Output triangulation placed here
364 
365  // These are used for internal computation.
366  vtkTriangle* Triangle;
367  vtkQuad* Quad;
368  vtkDoubleArray* TriScalars;
369  vtkLine* Line;
370 
371  // Parameter indicating whether to use Mean Value Coordinate algorithm
372  // for interpolation. The parameter is false by default.
373  bool UseMVCInterpolation;
374 
375  // Helper methods for triangulation------------------------------
376  // Made public for external access
377 public:
378  // Ear cut triangulation options. The order in which vertices are
379  // removed are controlled by different measures. Changing this can
380  // make subtle differences in some cases. Historically the
381  // PERIMETER2_TO_AREA_RATIO has been used.
383  {
384  PERIMETER2_TO_AREA_RATIO = 0,
385  DOT_PRODUCT = 1,
386  BEST_QUALITY = 2
387  };
388 
390 
398  int EarCutTriangulation(int measure = PERIMETER2_TO_AREA_RATIO);
399  int EarCutTriangulation(vtkIdList* outTris, int measure = PERIMETER2_TO_AREA_RATIO);
401 
403 
410  int UnbiasedEarCutTriangulation(int seed, int measure = PERIMETER2_TO_AREA_RATIO);
412  int seed, vtkIdList* outTris, int measure = PERIMETER2_TO_AREA_RATIO);
414 
415 private:
416  vtkPolygon(const vtkPolygon&) = delete;
417  void operator=(const vtkPolygon&) = delete;
418 };
419 
420 VTK_ABI_NAMESPACE_END
421 #endif
object to represent cell connectivity
Definition: vtkCellArray.h:286
represent and manipulate cell attribute data
Definition: vtkCellData.h:141
abstract class to specify cell behavior
Definition: vtkCell.h:130
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:213
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:155
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
Definition: vtkPointData.h:140
represent and manipulate 3D points
Definition: vtkPoints.h:139
a cell that represents an n-sided polygon
Definition: vtkPolygon.h:132
int IsPrimaryCell() override
See the vtkCell API for descriptions of these methods.
Definition: vtkPolygon.h:163
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.
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.
vtkCell * GetFace(int) override
See the vtkCell API for descriptions of these methods.
Definition: vtkPolygon.h:147
static void ComputeNormal(int numPts, double *pts, double n[3])
Compute the polygon normal from an array of points.
int UnbiasedEarCutTriangulation(int seed, int measure=PERIMETER2_TO_AREA_RATIO)
A fast triangulation method.
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:263
static void ComputeNormal(vtkPoints *p, double n[3])
Computes the unit normal to the polygon.
int GetNumberOfFaces() override
See the vtkCell API for descriptions of these methods.
Definition: vtkPolygon.h:145
static vtkPolygon * New()
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 GetCellDimension() override
See the vtkCell API for descriptions of these methods.
Definition: vtkPolygon.h:143
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.
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.
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.
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.
static void ComputeNormal(vtkIdTypeArray *ids, vtkPoints *pts, double n[3])
Computes the unit normal to the polygon.
int EarCutTriangulation(int measure=PERIMETER2_TO_AREA_RATIO)
A fast triangulation method.
vtkCell * GetEdge(int edgeId) 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.
int UnbiasedEarCutTriangulation(int seed, vtkIdList *outTris, int measure=PERIMETER2_TO_AREA_RATIO)
A fast triangulation method.
static void ComputeNormal(vtkPoints *p, int numPts, const vtkIdType *pts, double n[3])
Computes the unit normal to the polygon.
a cell that represents a 2D quadrilateral
Definition: vtkQuad.h:87
a cell that represents a triangle
Definition: vtkTriangle.h:137
@ value
Definition: vtkX3D.h:220
@ index
Definition: vtkX3D.h:246
@ VTK_POLYGON
Definition: vtkCellType.h:63
#define VTK_DEPRECATED_IN_9_3_0(reason)
int vtkIdType
Definition: vtkType.h:315