VTK
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 =========================================================================*/
25 #ifndef vtkPolygon_h
26 #define vtkPolygon_h
27 
28 #include "vtkCommonDataModelModule.h" // For export macro
29 #include "vtkCell.h"
30 
31 class vtkDoubleArray;
32 class vtkIdTypeArray;
33 class vtkLine;
34 class vtkPoints;
35 class vtkQuad;
36 class vtkTriangle;
38 
39 class VTKCOMMONDATAMODEL_EXPORT vtkPolygon : public vtkCell
40 {
41 public:
42  static vtkPolygon *New();
43  vtkTypeMacro(vtkPolygon,vtkCell);
44  void PrintSelf(ostream& os, vtkIndent indent) override;
45 
47 
50  int GetCellType() override {return VTK_POLYGON;};
51  int GetCellDimension() override {return 2;};
52  int GetNumberOfEdges() override {return this->GetNumberOfPoints();};
53  int GetNumberOfFaces() override {return 0;};
54  vtkCell *GetEdge(int edgeId) override;
55  vtkCell *GetFace(int) override {return nullptr;};
56  int CellBoundary(int subId, double pcoords[3], vtkIdList *pts) override;
57  void Contour(double value, vtkDataArray *cellScalars,
59  vtkCellArray *lines, vtkCellArray *polys,
60  vtkPointData *inPd, vtkPointData *outPd,
61  vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd) override;
62  void Clip(double value, vtkDataArray *cellScalars,
64  vtkPointData *inPd, vtkPointData *outPd,
65  vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd,
66  int insideOut) override;
67  int EvaluatePosition(double x[3], double* closestPoint,
68  int& subId, double pcoords[3],
69  double& dist2, double *weights) override;
70  void EvaluateLocation(int& subId, double pcoords[3], double x[3],
71  double *weights) override;
72  int IntersectWithLine(double p1[3], double p2[3], double tol, double& t,
73  double x[3], double pcoords[3], int& subId) override;
74  int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts) override;
75  void Derivatives(int subId, double pcoords[3], double *values,
76  int dim, double *derivs) override;
77  int IsPrimaryCell() override {return 0;}
79 
86  double ComputeArea();
87 
97  void InterpolateFunctions(double x[3], double *sf) override;
98 
100 
104  static void ComputeNormal(vtkPoints *p, int numPts, vtkIdType *pts,
105  double n[3]);
106  static void ComputeNormal(vtkPoints *p, double n[3]);
107  static void ComputeNormal(vtkIdTypeArray *ids, vtkPoints *pts, double n[3]);
109 
114  static void ComputeNormal(int numPts, double *pts, double n[3]);
115 
122  bool IsConvex();
123 
125 
129  static bool IsConvex(vtkPoints *p, int numPts, vtkIdType *pts);
130  static bool IsConvex(vtkIdTypeArray *ids, vtkPoints *p);
131  static bool IsConvex(vtkPoints *p);
133 
135 
139  static bool ComputeCentroid(vtkPoints *p, int numPts, vtkIdType *pts,
140  double centroid[3]);
141  static bool ComputeCentroid(vtkIdTypeArray *ids, vtkPoints *pts,
142  double centroid[3]);
144 
153  static double ComputeArea(vtkPoints *p, vtkIdType numPts, vtkIdType *pts,
154  double normal[3]);
155 
163  int ParameterizePolygon(double p0[3], double p10[3], double &l10,
164  double p20[3], double &l20, double n[3]);
165 
172  static int PointInPolygon(double x[3], int numPts, double *pts,
173  double bounds[6], double n[3]);
174 
181  int Triangulate(vtkIdList *outTris);
182 
187  int NonDegenerateTriangulate(vtkIdList *outTris);
188 
196  int BoundedTriangulate(vtkIdList *outTris, double tol);
197 
203  static double DistanceToPolygon(double x[3], int numPts, double *pts,
204  double bounds[6], double closest[3]);
205 
214  static int IntersectPolygonWithPolygon(int npts, double *pts, double bounds[6],
215  int npts2, double *pts2,
216  double bounds2[3], double tol,
217  double x[3]);
218 
230  static int IntersectConvex2DCells(vtkCell *cell1, vtkCell *cell2,
231  double tol, double p0[3], double p1[3]);
232 
234 
240  vtkGetMacro(UseMVCInterpolation, bool);
241  vtkSetMacro(UseMVCInterpolation, bool);
243 
244 protected:
245  vtkPolygon();
246  ~vtkPolygon() override;
247 
248  // Compute the interpolation functions using Mean Value Coordinate.
249  void InterpolateFunctionsUsingMVC(double x[3], double *weights);
250 
251  // variables used by instances of this class
252  double Tolerance; // Intersection tolerance
253  int SuccessfulTriangulation; // Stops recursive tri. if necessary
254  double Normal[3]; //polygon normal
260 
261  // Parameter indicating whether to use Mean Value Coordinate algorithm
262  // for interpolation. The parameter is false by default.
264 
265  // Helper methods for triangulation------------------------------
272  int EarCutTriangulation();
273 
281  int UnbiasedEarCutTriangulation(int seed);
282 
283 private:
284  vtkPolygon(const vtkPolygon&) = delete;
285  void operator=(const vtkPolygon&) = delete;
286 };
287 
288 #endif
vtkIdType GetNumberOfPoints()
Return the number of points in the cell.
Definition: vtkCell.h:137
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:31
virtual void InterpolateFunctions(double vtkNotUsed(pcoords)[3], double *vtkNotUsed(weight))
Compute the interpolation functions/derivatives (aka shape functions/derivatives) No-ops at this leve...
Definition: vtkCell.h:354
double Tolerance
Definition: vtkPolygon.h:252
represent and manipulate cell attribute data
Definition: vtkCellData.h:32
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 EvaluateLocation(int &subId, double pcoords[3], double x[3], double *weights)=0
Determine global coordinate (x[3]) from subId and parametric coordinates.
virtual int EvaluatePosition(double x[3], double *closestPoint, 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...
a cell that represents a 2D quadrilateral
Definition: vtkQuad.h:35
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:345
int GetNumberOfEdges() override
See the vtkCell API for descriptions of these methods.
Definition: vtkPolygon.h:52
dynamic, self-adjusting array of double
int GetNumberOfFaces() override
See the vtkCell API for descriptions of these methods.
Definition: vtkPolygon.h:53
int GetCellType() override
See the vtkCell API for descriptions of these methods.
Definition: vtkPolygon.h:50
cell represents a 1D line
Definition: vtkLine.h:29
abstract class to specify cell behavior
Definition: vtkCell.h:56
vtkDoubleArray * TriScalars
Definition: vtkPolygon.h:258
a simple class to control print indentation
Definition: vtkIndent.h:33
list of point or cell ids
Definition: vtkIdList.h:30
int SuccessfulTriangulation
Definition: vtkPolygon.h:253
virtual void Derivatives(int subId, double pcoords[3], double *values, int dim, double *derivs)=0
Compute derivatives given cell subId and parametric coordinates.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
virtual int IntersectWithLine(double p1[3], double p2[3], double tol, double &t, double x[3], double pcoords[3], int &subId)=0
Intersect with a ray.
a cell that represents an n-sided polygon
Definition: vtkPolygon.h:39
bool UseMVCInterpolation
Definition: vtkPolygon.h:263
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:55
object to represent cell connectivity
Definition: vtkCellArray.h:44
virtual vtkCell * GetEdge(int edgeId)=0
Return the edge cell from the edgeId of the cell.
vtkLine * Line
Definition: vtkPolygon.h:259
int IsPrimaryCell() override
See the vtkCell API for descriptions of these methods.
Definition: vtkPolygon.h:77
a cell that represents a triangle
Definition: vtkTriangle.h:35
vtkIdList * Tris
Definition: vtkPolygon.h:255
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.
vtkQuad * Quad
Definition: vtkPolygon.h:257
vtkTriangle * Triangle
Definition: vtkPolygon.h:256
virtual int CellBoundary(int subId, double pcoords[3], vtkIdList *pts)=0
Given parametric coordinates of a point, return the closest cell boundary, and whether the point is i...
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
int GetCellDimension() override
See the vtkCell API for descriptions of these methods.
Definition: vtkPolygon.h:51
represent and manipulate 3D points
Definition: vtkPoints.h:33