VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkPolygon.h,v $ 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 =========================================================================*/ 00027 #ifndef __vtkPolygon_h 00028 #define __vtkPolygon_h 00029 00030 #include "vtkCell.h" 00031 00032 class vtkDoubleArray; 00033 class vtkIdTypeArray; 00034 class vtkLine; 00035 class vtkPoints; 00036 class vtkQuad; 00037 class vtkTriangle; 00038 00039 class VTK_FILTERING_EXPORT vtkPolygon : public vtkCell 00040 { 00041 public: 00042 static vtkPolygon *New(); 00043 vtkTypeRevisionMacro(vtkPolygon,vtkCell); 00044 void PrintSelf(ostream& os, vtkIndent indent); 00045 00047 00048 int GetCellType() {return VTK_POLYGON;}; 00049 int GetCellDimension() {return 2;}; 00050 int GetNumberOfEdges() {return this->GetNumberOfPoints();}; 00051 int GetNumberOfFaces() {return 0;}; 00052 vtkCell *GetEdge(int edgeId); 00053 vtkCell *GetFace(int) {return 0;}; 00054 int CellBoundary(int subId, double pcoords[3], vtkIdList *pts); 00055 void Contour(double value, vtkDataArray *cellScalars, 00056 vtkPointLocator *locator,vtkCellArray *verts, 00057 vtkCellArray *lines, vtkCellArray *polys, 00058 vtkPointData *inPd, vtkPointData *outPd, 00059 vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd); 00060 void Clip(double value, vtkDataArray *cellScalars, 00061 vtkPointLocator *locator, vtkCellArray *tris, 00062 vtkPointData *inPd, vtkPointData *outPd, 00063 vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd, 00064 int insideOut); 00065 int EvaluatePosition(double x[3], double* closestPoint, 00066 int& subId, double pcoords[3], 00067 double& dist2, double *weights); 00068 void EvaluateLocation(int& subId, double pcoords[3], double x[3], 00069 double *weights); 00070 int IntersectWithLine(double p1[3], double p2[3], double tol, double& t, 00071 double x[3], double pcoords[3], int& subId); 00072 int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts); 00073 void Derivatives(int subId, double pcoords[3], double *values, 00074 int dim, double *derivs); 00075 int IsPrimaryCell() {return 0;} 00077 00079 00081 virtual void InterpolateFunctions(double pcoords[3], double *sf); 00082 virtual void InterpolateDerivs(double pcoords[3], double *derivs); 00084 00086 00087 static void ComputeNormal(vtkPoints *p, int numPts, vtkIdType *pts, 00088 double n[3]); 00089 static void ComputeNormal(vtkPoints *p, double n[3]); 00090 static void ComputeNormal(vtkIdTypeArray *ids, vtkPoints *pts, double n[3]); 00092 00096 static void ComputeNormal(int numPts, double *pts, double n[3]); 00097 00099 00100 static void ComputeCentroid(vtkIdTypeArray *ids, vtkPoints *pts, 00101 double centroid[3]); 00103 00107 VTK_LEGACY(void ComputeWeights(double x[3], double *weights)); 00108 00110 00113 static double ComputeArea(vtkPoints *p, vtkIdType numPts, vtkIdType *pts, 00114 double normal[3]); 00116 00118 00123 int ParameterizePolygon(double p0[3], double p10[3], double &l10, 00124 double p20[3], double &l20, double n[3]); 00126 00128 00132 static int PointInPolygon(double x[3], int numPts, double *pts, 00133 double bounds[6], double n[3]); 00135 00140 int Triangulate(vtkIdList *outTris); 00141 00144 int NonDegenerateTriangulate(vtkIdList *outTris); 00145 00147 00150 static double DistanceToPolygon(double x[3], int numPts, double *pts, 00151 double bounds[6], double closest[3]); 00153 00155 00161 static int IntersectPolygonWithPolygon(int npts, double *pts, double bounds[6], 00162 int npts2, double *pts2, 00163 double bounds2[3], double tol, 00164 double x[3]); 00166 00167 00168 // Intersect two convex 2D polygons to produce a line segment as output. 00169 // The return status of the methods indicated no intersection (returns 0); 00170 // a single point of intersection (returns 1); or a line segment (i.e., two 00171 // points of intersection, returns 2). The points of intersection are 00172 // returned in the arrays p0 and p1. If less than two points of 00173 // intersection are generated then p1 and/or p0 may be 00174 // indeterminiate. Finally, if the two convex polygons are parallel, then 00175 // "0" is returned (i.e., no intersection) even if the triangles lie on one 00176 // another. 00177 static int IntersectConvex2DCells(vtkCell *cell1, vtkCell *cell2, 00178 double tol, double p0[3], double p1[3]); 00179 00180 protected: 00181 vtkPolygon(); 00182 ~vtkPolygon(); 00183 00184 // variables used by instances of this class 00185 double Tolerance; // Intersection tolerance 00186 int SuccessfulTriangulation; // Stops recursive tri. if necessary 00187 double Normal[3]; //polygon normal 00188 vtkIdList *Tris; 00189 vtkTriangle *Triangle; 00190 vtkQuad *Quad; 00191 vtkDoubleArray *TriScalars; 00192 vtkLine *Line; 00193 00194 // Helper methods for triangulation------------------------------ 00199 int EarCutTriangulation(); 00200 00201 private: 00202 vtkPolygon(const vtkPolygon&); // Not implemented. 00203 void operator=(const vtkPolygon&); // Not implemented. 00204 }; 00205 00206 #endif 00207