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 =========================================================================*/
30 #ifndef __vtkPolygon_h
31 #define __vtkPolygon_h
32 
33 #include "vtkCell.h"
34 
35 class vtkDoubleArray;
36 class vtkIdTypeArray;
37 class vtkLine;
38 class vtkPoints;
39 class vtkQuad;
40 class vtkTriangle;
42 
44 {
45 public:
46  static vtkPolygon *New();
47  vtkTypeMacro(vtkPolygon,vtkCell);
48  void PrintSelf(ostream& os, vtkIndent indent);
49 
51 
52  int GetCellType() {return VTK_POLYGON;};
53  int GetCellDimension() {return 2;};
54  int GetNumberOfEdges() {return this->GetNumberOfPoints();};
55  int GetNumberOfFaces() {return 0;};
56  vtkCell *GetEdge(int edgeId);
57  vtkCell *GetFace(int) {return 0;};
58  int CellBoundary(int subId, double pcoords[3], vtkIdList *pts);
59  void Contour(double value, vtkDataArray *cellScalars,
61  vtkCellArray *lines, vtkCellArray *polys,
62  vtkPointData *inPd, vtkPointData *outPd,
63  vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd);
64  void Clip(double value, vtkDataArray *cellScalars,
66  vtkPointData *inPd, vtkPointData *outPd,
67  vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd,
68  int insideOut);
69  int EvaluatePosition(double x[3], double* closestPoint,
70  int& subId, double pcoords[3],
71  double& dist2, double *weights);
72  void EvaluateLocation(int& subId, double pcoords[3], double x[3],
73  double *weights);
74  int IntersectWithLine(double p1[3], double p2[3], double tol, double& t,
75  double x[3], double pcoords[3], int& subId);
76  int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts);
77  void Derivatives(int subId, double pcoords[3], double *values,
78  int dim, double *derivs);
79  int IsPrimaryCell() {return 0;}
81 
86  double ComputeArea();
87 
89 
95  virtual void InterpolateFunctions(double x[3], double *sf);
96  virtual void InterpolateDerivs(double x[3], double *derivs);
98 
100 
101  static void ComputeNormal(vtkPoints *p, int numPts, vtkIdType *pts,
102  double n[3]);
103  static void ComputeNormal(vtkPoints *p, double n[3]);
104  static void ComputeNormal(vtkIdTypeArray *ids, vtkPoints *pts, double n[3]);
106 
110  static void ComputeNormal(int numPts, double *pts, double n[3]);
111 
113 
114  static void ComputeCentroid(vtkIdTypeArray *ids, vtkPoints *pts,
115  double centroid[3]);
117 
121  VTK_LEGACY(void ComputeWeights(double x[3], double *weights));
122 
124 
129  static double ComputeArea(vtkPoints *p, vtkIdType numPts, vtkIdType *pts,
130  double normal[3]);
132 
134 
139  int ParameterizePolygon(double p0[3], double p10[3], double &l10,
140  double p20[3], double &l20, double n[3]);
142 
144 
148  static int PointInPolygon(double x[3], int numPts, double *pts,
149  double bounds[6], double n[3]);
151 
156  int Triangulate(vtkIdList *outTris);
157 
160  int NonDegenerateTriangulate(vtkIdList *outTris);
161 
163 
166  static double DistanceToPolygon(double x[3], int numPts, double *pts,
167  double bounds[6], double closest[3]);
169 
171 
177  static int IntersectPolygonWithPolygon(int npts, double *pts, double bounds[6],
178  int npts2, double *pts2,
179  double bounds2[3], double tol,
180  double x[3]);
182 
184 
193  static int IntersectConvex2DCells(vtkCell *cell1, vtkCell *cell2,
194  double tol, double p0[3], double p1[3]);
196 
198 
203  vtkGetMacro(UseMVCInterpolation, bool);
204  vtkSetMacro(UseMVCInterpolation, bool);
206 
207 protected:
208  vtkPolygon();
209  ~vtkPolygon();
210 
211  // Compute the interpolation functions using Mean Value Coordinate.
212  void InterpolateFunctionsUsingMVC(double x[3], double *weights);
213 
214  // variables used by instances of this class
215  double Tolerance; // Intersection tolerance
216  int SuccessfulTriangulation; // Stops recursive tri. if necessary
217  double Normal[3]; //polygon normal
223 
224  // Parameter indicating whether to use Mean Value Coordinate algorithm
225  // for interpolation. The parameter is false by default.
227 
228  // Helper methods for triangulation------------------------------
233  int EarCutTriangulation();
234 
235 private:
236  vtkPolygon(const vtkPolygon&); // Not implemented.
237  void operator=(const vtkPolygon&); // Not implemented.
238 };
239 
240 #endif
241