VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkPolygon.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00030 #ifndef __vtkPolygon_h 00031 #define __vtkPolygon_h 00032 00033 #include "vtkCell.h" 00034 00035 class vtkDoubleArray; 00036 class vtkIdTypeArray; 00037 class vtkLine; 00038 class vtkPoints; 00039 class vtkQuad; 00040 class vtkTriangle; 00041 class vtkIncrementalPointLocator; 00042 00043 class VTK_FILTERING_EXPORT vtkPolygon : public vtkCell 00044 { 00045 public: 00046 static vtkPolygon *New(); 00047 vtkTypeMacro(vtkPolygon,vtkCell); 00048 void PrintSelf(ostream& os, vtkIndent indent); 00049 00051 00052 int GetCellType() {return VTK_POLYGON;}; 00053 int GetCellDimension() {return 2;}; 00054 int GetNumberOfEdges() {return this->GetNumberOfPoints();}; 00055 int GetNumberOfFaces() {return 0;}; 00056 vtkCell *GetEdge(int edgeId); 00057 vtkCell *GetFace(int) {return 0;}; 00058 int CellBoundary(int subId, double pcoords[3], vtkIdList *pts); 00059 void Contour(double value, vtkDataArray *cellScalars, 00060 vtkIncrementalPointLocator *locator,vtkCellArray *verts, 00061 vtkCellArray *lines, vtkCellArray *polys, 00062 vtkPointData *inPd, vtkPointData *outPd, 00063 vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd); 00064 void Clip(double value, vtkDataArray *cellScalars, 00065 vtkIncrementalPointLocator *locator, vtkCellArray *tris, 00066 vtkPointData *inPd, vtkPointData *outPd, 00067 vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd, 00068 int insideOut); 00069 int EvaluatePosition(double x[3], double* closestPoint, 00070 int& subId, double pcoords[3], 00071 double& dist2, double *weights); 00072 void EvaluateLocation(int& subId, double pcoords[3], double x[3], 00073 double *weights); 00074 int IntersectWithLine(double p1[3], double p2[3], double tol, double& t, 00075 double x[3], double pcoords[3], int& subId); 00076 int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts); 00077 void Derivatives(int subId, double pcoords[3], double *values, 00078 int dim, double *derivs); 00079 int IsPrimaryCell() {return 0;} 00081 00086 double ComputeArea(); 00087 00089 00091 virtual void InterpolateFunctions(double pcoords[3], double *sf); 00092 virtual void InterpolateDerivs(double pcoords[3], double *derivs); 00094 00096 00097 static void ComputeNormal(vtkPoints *p, int numPts, vtkIdType *pts, 00098 double n[3]); 00099 static void ComputeNormal(vtkPoints *p, double n[3]); 00100 static void ComputeNormal(vtkIdTypeArray *ids, vtkPoints *pts, double n[3]); 00102 00106 static void ComputeNormal(int numPts, double *pts, double n[3]); 00107 00109 00110 static void ComputeCentroid(vtkIdTypeArray *ids, vtkPoints *pts, 00111 double centroid[3]); 00113 00117 VTK_LEGACY(void ComputeWeights(double x[3], double *weights)); 00118 00120 00125 static double ComputeArea(vtkPoints *p, vtkIdType numPts, vtkIdType *pts, 00126 double normal[3]); 00128 00130 00135 int ParameterizePolygon(double p0[3], double p10[3], double &l10, 00136 double p20[3], double &l20, double n[3]); 00138 00140 00144 static int PointInPolygon(double x[3], int numPts, double *pts, 00145 double bounds[6], double n[3]); 00147 00152 int Triangulate(vtkIdList *outTris); 00153 00156 int NonDegenerateTriangulate(vtkIdList *outTris); 00157 00159 00162 static double DistanceToPolygon(double x[3], int numPts, double *pts, 00163 double bounds[6], double closest[3]); 00165 00167 00173 static int IntersectPolygonWithPolygon(int npts, double *pts, double bounds[6], 00174 int npts2, double *pts2, 00175 double bounds2[3], double tol, 00176 double x[3]); 00178 00179 00180 // Intersect two convex 2D polygons to produce a line segment as output. 00181 // The return status of the methods indicated no intersection (returns 0); 00182 // a single point of intersection (returns 1); or a line segment (i.e., two 00183 // points of intersection, returns 2). The points of intersection are 00184 // returned in the arrays p0 and p1. If less than two points of 00185 // intersection are generated then p1 and/or p0 may be 00186 // indeterminiate. Finally, if the two convex polygons are parallel, then 00187 // "0" is returned (i.e., no intersection) even if the triangles lie on one 00188 // another. 00189 static int IntersectConvex2DCells(vtkCell *cell1, vtkCell *cell2, 00190 double tol, double p0[3], double p1[3]); 00191 00192 protected: 00193 vtkPolygon(); 00194 ~vtkPolygon(); 00195 00196 // variables used by instances of this class 00197 double Tolerance; // Intersection tolerance 00198 int SuccessfulTriangulation; // Stops recursive tri. if necessary 00199 double Normal[3]; //polygon normal 00200 vtkIdList *Tris; 00201 vtkTriangle *Triangle; 00202 vtkQuad *Quad; 00203 vtkDoubleArray *TriScalars; 00204 vtkLine *Line; 00205 00206 // Helper methods for triangulation------------------------------ 00211 int EarCutTriangulation(); 00212 00213 private: 00214 vtkPolygon(const vtkPolygon&); // Not implemented. 00215 void operator=(const vtkPolygon&); // Not implemented. 00216 }; 00217 00218 #endif 00219