VTK  9.2.6
vtkPolygon.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkPolygon.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
28 #ifndef vtkPolygon_h
29 #define vtkPolygon_h
30 
31 #include "vtkCell.h"
32 #include "vtkCommonDataModelModule.h" // For export macro
33 
34 class vtkDoubleArray;
35 class vtkIdTypeArray;
36 class vtkLine;
37 class vtkPoints;
38 class vtkQuad;
39 class vtkTriangle;
41 
42 class VTKCOMMONDATAMODEL_EXPORT vtkPolygon : public vtkCell
43 {
44 public:
45  static vtkPolygon* New();
46  vtkTypeMacro(vtkPolygon, vtkCell);
47  void PrintSelf(ostream& os, vtkIndent indent) override;
48 
50 
53  int GetCellType() override { return VTK_POLYGON; }
54  int GetCellDimension() override { return 2; }
55  int GetNumberOfEdges() override { return this->GetNumberOfPoints(); }
56  int GetNumberOfFaces() override { return 0; }
57  vtkCell* GetEdge(int edgeId) override;
58  vtkCell* GetFace(int) override { return nullptr; }
59  int CellBoundary(int subId, const double pcoords[3], vtkIdList* pts) override;
60  void Contour(double value, vtkDataArray* cellScalars, vtkIncrementalPointLocator* locator,
61  vtkCellArray* verts, vtkCellArray* lines, vtkCellArray* polys, vtkPointData* inPd,
62  vtkPointData* outPd, vtkCellData* inCd, vtkIdType cellId, vtkCellData* outCd) override;
63  void Clip(double value, vtkDataArray* cellScalars, vtkIncrementalPointLocator* locator,
64  vtkCellArray* tris, vtkPointData* inPd, vtkPointData* outPd, vtkCellData* inCd,
65  vtkIdType cellId, vtkCellData* outCd, int insideOut) override;
66  int EvaluatePosition(const double x[3], double closestPoint[3], int& subId, double pcoords[3],
67  double& dist2, double weights[]) override;
68  void EvaluateLocation(int& subId, const double pcoords[3], double x[3], double* weights) override;
69  int IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t, double x[3],
70  double pcoords[3], int& subId) override;
71  int Triangulate(int index, vtkIdList* ptIds, vtkPoints* pts) override;
72  void Derivatives(
73  int subId, const double pcoords[3], const double* values, int dim, double* derivs) override;
74  int IsPrimaryCell() override { return 0; }
76 
83  double ComputeArea();
84 
94  void InterpolateFunctions(const double x[3], double* sf) override;
95 
97 
101  static void ComputeNormal(vtkPoints* p, int numPts, const vtkIdType* pts, double n[3]);
102  static void ComputeNormal(vtkPoints* p, double n[3]);
103  static void ComputeNormal(vtkIdTypeArray* ids, vtkPoints* pts, double n[3]);
105 
110  static void ComputeNormal(int numPts, double* pts, double n[3]);
111 
118  bool IsConvex();
119 
121 
125  static bool IsConvex(vtkPoints* p, int numPts, const vtkIdType* pts);
126  static bool IsConvex(vtkIdTypeArray* ids, vtkPoints* p);
127  static bool IsConvex(vtkPoints* p);
129 
131 
135  static bool ComputeCentroid(vtkPoints* p, int numPts, const vtkIdType* pts, double centroid[3]);
136  static bool ComputeCentroid(vtkIdTypeArray* ids, vtkPoints* pts, double centroid[3]);
138 
147  static double ComputeArea(vtkPoints* p, vtkIdType numPts, const vtkIdType* pts, double normal[3]);
148 
156  int ParameterizePolygon(
157  double p0[3], double p10[3], double& l10, double p20[3], double& l20, double n[3]);
158 
170  static int PointInPolygon(double x[3], int numPts, double* pts, double bounds[6], double n[3]);
171 
180  int Triangulate(vtkIdList* outTris);
181 
186  int NonDegenerateTriangulate(vtkIdList* outTris);
187 
195  int BoundedTriangulate(vtkIdList* outTris, double tol);
196 
202  static double DistanceToPolygon(
203  double x[3], int numPts, double* pts, double bounds[6], double closest[3]);
204 
213  static int IntersectPolygonWithPolygon(int npts, double* pts, double bounds[6], int npts2,
214  double* pts2, double bounds2[3], double tol, double x[3]);
215 
227  static int IntersectConvex2DCells(
228  vtkCell* cell1, vtkCell* cell2, double tol, double p0[3], double p1[3]);
229 
231 
237  vtkGetMacro(UseMVCInterpolation, bool);
238  vtkSetMacro(UseMVCInterpolation, bool);
240 
242 
250  vtkSetClampMacro(Tolerance, double, 0.0, 1.0);
251  vtkGetMacro(Tolerance, double);
253 
254 protected:
255  vtkPolygon();
256  ~vtkPolygon() override;
257 
258  // Compute the interpolation functions using Mean Value Coordinate.
259  void InterpolateFunctionsUsingMVC(const double x[3], double* weights);
260 
261  // variables used by instances of this class
262  double Tolerance; // Intersection tolerance set by public API
263  double Tol; // Internal tolerance set by ComputeBounds()
264  void ComputeTolerance(); // Compute the internal tolerance Tol
265 
266  int SuccessfulTriangulation; // Stops recursive triangulation if necessary
267  vtkIdList* Tris; // Output triangulation placed here
268 
269  // These are used for internal computation.
274 
275  // Parameter indicating whether to use Mean Value Coordinate algorithm
276  // for interpolation. The parameter is false by default.
278 
279  // Helper methods for triangulation------------------------------
280  // Made public for external access
281 public:
282  // Ear cut triangulation options. The order in which vertices are
283  // removed are controlled by different measures. Changing this can
284  // make subtle differences in some cases. Historically the
285  // PERIMETER2_TO_AREA_RATIO has been used.
287  {
288  PERIMETER2_TO_AREA_RATIO = 0,
289  DOT_PRODUCT = 1,
290  BEST_QUALITY = 2
291  };
292 
294 
302  int EarCutTriangulation(int measure = PERIMETER2_TO_AREA_RATIO);
303  int EarCutTriangulation(vtkIdList* outTris, int measure = PERIMETER2_TO_AREA_RATIO);
305 
307 
314  int UnbiasedEarCutTriangulation(int seed, int measure = PERIMETER2_TO_AREA_RATIO);
315  int UnbiasedEarCutTriangulation(
316  int seed, vtkIdList* outTris, int measure = PERIMETER2_TO_AREA_RATIO);
318 
319 private:
320  vtkPolygon(const vtkPolygon&) = delete;
321  void operator=(const vtkPolygon&) = delete;
322 };
323 
324 #endif
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
represent and manipulate point attribute data
Definition: vtkPointData.h:41
vtkIdType GetNumberOfPoints() const
Return the number of points in the cell.
Definition: vtkCell.h:141
double Tolerance
Definition: vtkPolygon.h:262
represent and manipulate cell attribute data
Definition: vtkCellData.h:41
Abstract class in support of both point location and point insertion.
virtual int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts)=0
Generate simplices of proper dimension.
virtual void InterpolateFunctions(const double vtkNotUsed(pcoords)[3], double *vtkNotUsed(weight))
Compute the interpolation functions/derivatives (aka shape functions/derivatives) No-ops at this leve...
Definition: vtkCell.h:391
double Tol
Definition: vtkPolygon.h:263
a cell that represents a 2D quadrilateral
Definition: vtkQuad.h:38
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:332
int GetNumberOfEdges() override
See the vtkCell API for descriptions of these methods.
Definition: vtkPolygon.h:55
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
int GetNumberOfFaces() override
See the vtkCell API for descriptions of these methods.
Definition: vtkPolygon.h:56
int GetCellType() override
See the vtkCell API for descriptions of these methods.
Definition: vtkPolygon.h:53
cell represents a 1D line
Definition: vtkLine.h:33
abstract class to specify cell behavior
Definition: vtkCell.h:60
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.
vtkDoubleArray * TriScalars
Definition: vtkPolygon.h:272
a simple class to control print indentation
Definition: vtkIndent.h:39
list of point or cell ids
Definition: vtkIdList.h:33
int SuccessfulTriangulation
Definition: vtkPolygon.h:266
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
a cell that represents an n-sided polygon
Definition: vtkPolygon.h:42
bool UseMVCInterpolation
Definition: vtkPolygon.h:277
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.
Definition: vtkPolygon.h:58
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
Definition: vtkCellArray.h:186
virtual vtkCell * GetEdge(int edgeId)=0
Return the edge cell from the edgeId of the cell.
vtkLine * Line
Definition: vtkPolygon.h:273
int IsPrimaryCell() override
See the vtkCell API for descriptions of these methods.
Definition: vtkPolygon.h:74
a cell that represents a triangle
Definition: vtkTriangle.h:38
vtkIdList * Tris
Definition: vtkPolygon.h:267
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.
vtkQuad * Quad
Definition: vtkPolygon.h:271
vtkTriangle * Triangle
Definition: vtkPolygon.h:270
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
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.
Definition: vtkPolygon.h:54
represent and manipulate 3D points
Definition: vtkPoints.h:39