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 =========================================================================*/
31 #ifndef vtkPolygon_h
32 #define vtkPolygon_h
33 
34 #include "vtkCommonDataModelModule.h" // For export macro
35 #include "vtkCell.h"
36 
37 class vtkDoubleArray;
38 class vtkIdTypeArray;
39 class vtkLine;
40 class vtkPoints;
41 class vtkQuad;
42 class vtkTriangle;
44 
45 class VTKCOMMONDATAMODEL_EXPORT vtkPolygon : public vtkCell
46 {
47 public:
48  static vtkPolygon *New();
49  vtkTypeMacro(vtkPolygon,vtkCell);
50  void PrintSelf(ostream& os, vtkIndent indent) override;
51 
53 
56  int GetCellType() override {return VTK_POLYGON;};
57  int GetCellDimension() override {return 2;};
58  int GetNumberOfEdges() override {return this->GetNumberOfPoints();};
59  int GetNumberOfFaces() override {return 0;};
60  vtkCell *GetEdge(int edgeId) override;
61  vtkCell *GetFace(int) override {return nullptr;};
62  int CellBoundary(int subId, const double pcoords[3], vtkIdList *pts) override;
63  void Contour(double value, vtkDataArray *cellScalars,
65  vtkCellArray *lines, vtkCellArray *polys,
66  vtkPointData *inPd, vtkPointData *outPd,
67  vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd) override;
68  void Clip(double value, vtkDataArray *cellScalars,
70  vtkPointData *inPd, vtkPointData *outPd,
71  vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd,
72  int insideOut) override;
73  int EvaluatePosition(const double x[3], double closestPoint[3],
74  int& subId, double pcoords[3],
75  double& dist2, double weights[]) override;
76  void EvaluateLocation(int& subId, const double pcoords[3], double x[3],
77  double *weights) override;
78  int IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t,
79  double x[3], double pcoords[3], int& subId) override;
80  int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts) override;
81  void Derivatives(int subId, const double pcoords[3], const double *values,
82  int dim, double *derivs) override;
83  int IsPrimaryCell() override {return 0;}
85 
92  double ComputeArea();
93 
103  void InterpolateFunctions(const double x[3], double *sf) override;
104 
106 
110  static void ComputeNormal(vtkPoints *p, int numPts, vtkIdType *pts,
111  double n[3]);
112  static void ComputeNormal(vtkPoints *p, double n[3]);
113  static void ComputeNormal(vtkIdTypeArray *ids, vtkPoints *pts, double n[3]);
115 
120  static void ComputeNormal(int numPts, double *pts, double n[3]);
121 
128  bool IsConvex();
129 
131 
135  static bool IsConvex(vtkPoints *p, int numPts, vtkIdType *pts);
136  static bool IsConvex(vtkIdTypeArray *ids, vtkPoints *p);
137  static bool IsConvex(vtkPoints *p);
139 
141 
145  static bool ComputeCentroid(vtkPoints *p, int numPts, vtkIdType *pts,
146  double centroid[3]);
147  static bool ComputeCentroid(vtkIdTypeArray *ids, vtkPoints *pts,
148  double centroid[3]);
150 
159  static double ComputeArea(vtkPoints *p, vtkIdType numPts, vtkIdType *pts,
160  double normal[3]);
161 
169  int ParameterizePolygon(double p0[3], double p10[3], double &l10,
170  double p20[3], double &l20, double n[3]);
171 
178  static int PointInPolygon(double x[3], int numPts, double *pts,
179  double bounds[6], double n[3]);
180 
187  int Triangulate(vtkIdList *outTris);
188 
193  int NonDegenerateTriangulate(vtkIdList *outTris);
194 
202  int BoundedTriangulate(vtkIdList *outTris, double tol);
203 
209  static double DistanceToPolygon(double x[3], int numPts, double *pts,
210  double bounds[6], double closest[3]);
211 
220  static int IntersectPolygonWithPolygon(int npts, double *pts, double bounds[6],
221  int npts2, double *pts2,
222  double bounds2[3], double tol,
223  double x[3]);
224 
236  static int IntersectConvex2DCells(vtkCell *cell1, vtkCell *cell2,
237  double tol, double p0[3], double p1[3]);
238 
240 
246  vtkGetMacro(UseMVCInterpolation, bool);
247  vtkSetMacro(UseMVCInterpolation, bool);
249 
250 protected:
251  vtkPolygon();
252  ~vtkPolygon() override;
253 
254  // Compute the interpolation functions using Mean Value Coordinate.
255  void InterpolateFunctionsUsingMVC(const double x[3], double *weights);
256 
257  // variables used by instances of this class
258  double Tolerance; // Intersection tolerance
259  int SuccessfulTriangulation; // Stops recursive tri. if necessary
260  double Normal[3]; //polygon normal
266 
267  // Parameter indicating whether to use Mean Value Coordinate algorithm
268  // for interpolation. The parameter is false by default.
270 
271  // Helper methods for triangulation------------------------------
278  int EarCutTriangulation();
279 
287  int UnbiasedEarCutTriangulation(int seed);
288 
289 private:
290  vtkPolygon(const vtkPolygon&) = delete;
291  void operator=(const vtkPolygon&) = delete;
292 };
293 
294 #endif
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:39
vtkCell::IntersectWithLine
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.
vtkCell::Contour
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.
vtkPointData
represent and manipulate point attribute data
Definition: vtkPointData.h:37
vtkPolygon::GetNumberOfFaces
int GetNumberOfFaces() override
Return the number of faces in the cell.
Definition: vtkPolygon.h:59
vtkX3D::value
Definition: vtkX3D.h:220
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkPolygon::GetFace
vtkCell * GetFace(int) override
Return the face cell from the faceId of the cell.
Definition: vtkPolygon.h:61
vtkPolygon
a cell that represents an n-sided polygon
Definition: vtkPolygon.h:45
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkX3D::Normal
Definition: vtkX3D.h:45
vtkPolygon::Tolerance
double Tolerance
Definition: vtkPolygon.h:258
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
vtkCell::EvaluateLocation
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.
vtkPolygon::Triangle
vtkTriangle * Triangle
Definition: vtkPolygon.h:262
vtkPolygon::GetCellType
int GetCellType() override
See the vtkCell API for descriptions of these methods.
Definition: vtkPolygon.h:56
vtkLine
cell represents a 1D line
Definition: vtkLine.h:35
vtkCell.h
vtkPolygon::SuccessfulTriangulation
int SuccessfulTriangulation
Definition: vtkPolygon.h:259
vtkCell::Triangulate
virtual int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts)=0
Generate simplices of proper dimension.
vtkCell
abstract class to specify cell behavior
Definition: vtkCell.h:59
vtkCellData
represent and manipulate cell attribute data
Definition: vtkCellData.h:38
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkCell::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkCellArray
object to represent cell connectivity
Definition: vtkCellArray.h:50
vtkIncrementalPointLocator
Abstract class in support of both point location and point insertion.
Definition: vtkIncrementalPointLocator.h:51
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:36
vtkPolygon::TriScalars
vtkDoubleArray * TriScalars
Definition: vtkPolygon.h:264
vtkPolygon::Tris
vtkIdList * Tris
Definition: vtkPolygon.h:261
vtkPolygon::GetNumberOfEdges
int GetNumberOfEdges() override
Return the number of edges in the cell.
Definition: vtkPolygon.h:58
vtkPolygon::UseMVCInterpolation
bool UseMVCInterpolation
Definition: vtkPolygon.h:269
vtkCell::GetNumberOfPoints
vtkIdType GetNumberOfPoints()
Return the number of points in the cell.
Definition: vtkCell.h:140
vtkTriangle
a cell that represents a triangle
Definition: vtkTriangle.h:41
vtkCell::CellBoundary
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...
vtkCell::EvaluatePosition
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...
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:41
vtkCell::Clip
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::GetEdge
virtual vtkCell * GetEdge(int edgeId)=0
Return the edge cell from the edgeId of the cell.
vtkCell::InterpolateFunctions
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:357
VTK_POLYGON
Definition: vtkCellType.h:52
vtkPolygon::IsPrimaryCell
int IsPrimaryCell() override
Return whether this cell type has a fixed topology or whether the topology varies depending on the da...
Definition: vtkPolygon.h:83
vtkCell::Derivatives
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.
vtkDoubleArray
dynamic, self-adjusting array of double
Definition: vtkDoubleArray.h:41
vtkPolygon::GetCellDimension
int GetCellDimension() override
Return the topological dimensional of the cell (0,1,2, or 3).
Definition: vtkPolygon.h:57
vtkPolygon::Line
vtkLine * Line
Definition: vtkPolygon.h:265
vtkX3D::index
Definition: vtkX3D.h:246
vtkQuad
a cell that represents a 2D quadrilateral
Definition: vtkQuad.h:41
vtkPolygon::Quad
vtkQuad * Quad
Definition: vtkPolygon.h:263