VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkTriangle.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 =========================================================================*/ 00025 #ifndef __vtkTriangle_h 00026 #define __vtkTriangle_h 00027 00028 #include "vtkCell.h" 00029 00030 #include "vtkMath.h" // Needed for inline methods 00031 00032 class vtkLine; 00033 class vtkQuadric; 00034 00035 class VTK_FILTERING_EXPORT vtkTriangle : public vtkCell 00036 { 00037 public: 00038 static vtkTriangle *New(); 00039 vtkTypeRevisionMacro(vtkTriangle,vtkCell); 00040 void PrintSelf(ostream& os, vtkIndent indent); 00041 00044 vtkCell *GetEdge(int edgeId); 00045 00047 00048 int GetCellType() {return VTK_TRIANGLE;}; 00049 int GetCellDimension() {return 2;}; 00050 int GetNumberOfEdges() {return 3;}; 00051 int GetNumberOfFaces() {return 0;}; 00052 vtkCell *GetFace(int) {return 0;}; 00053 int CellBoundary(int subId, double pcoords[3], vtkIdList *pts); 00054 void Contour(double value, vtkDataArray *cellScalars, 00055 vtkPointLocator *locator, vtkCellArray *verts, 00056 vtkCellArray *lines, vtkCellArray *polys, 00057 vtkPointData *inPd, vtkPointData *outPd, 00058 vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd); 00059 int EvaluatePosition(double x[3], double* closestPoint, 00060 int& subId, double pcoords[3], 00061 double& dist2, double *weights); 00062 void EvaluateLocation(int& subId, double pcoords[3], double x[3], 00063 double *weights); 00064 int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts); 00065 void Derivatives(int subId, double pcoords[3], double *values, 00066 int dim, double *derivs); 00067 virtual double *GetParametricCoords(); 00069 00071 00073 void Clip(double value, vtkDataArray *cellScalars, 00074 vtkPointLocator *locator, vtkCellArray *polys, 00075 vtkPointData *inPd, vtkPointData *outPd, 00076 vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd, 00077 int insideOut); 00079 00081 00083 static void InterpolationFunctions(double pcoords[3], double sf[3]); 00084 // Description: 00085 // @deprecated Replaced by vtkTriangle::InterpolateDerivs as of VTK 5.2 00086 static void InterpolationDerivs(double pcoords[3], double derivs[6]); 00087 // Description: 00088 // Compute the interpolation functions/derivatives 00089 // (aka shape functions/derivatives) 00090 virtual void InterpolateFunctions(double pcoords[3], double sf[3]) 00091 { 00092 vtkTriangle::InterpolationFunctions(pcoords,sf); 00093 } 00094 virtual void InterpolateDerivs(double pcoords[3], double derivs[6]) 00095 { 00096 vtkTriangle::InterpolationDerivs(pcoords,derivs); 00097 } 00098 // Description: 00099 // Return the ids of the vertices defining edge (`edgeId`). 00100 // Ids are related to the cell, not to the dataset. 00101 int *GetEdgeArray(int edgeId); 00103 00105 00107 int IntersectWithLine(double p1[3], double p2[3], double tol, double& t, 00108 double x[3], double pcoords[3], int& subId); 00110 00112 int GetParametricCenter(double pcoords[3]); 00113 00116 double GetParametricDistance(double pcoords[3]); 00117 00119 00120 static void TriangleCenter(double p1[3], double p2[3], double p3[3], 00121 double center[3]); 00123 00125 static double TriangleArea(double p1[3], double p2[3], double p3[3]); 00126 00128 00132 static double Circumcircle(double p1[2], double p2[2], double p3[2], 00133 double center[2]); 00135 00137 00148 static int BarycentricCoords(double x[2], double x1[2], double x2[2], 00149 double x3[2], double bcoords[3]); 00151 00152 00154 00157 static int ProjectTo2D(double x1[3], double x2[3], double x3[3], 00158 double v1[2], double v2[2], double v3[2]); 00160 00162 00164 static void ComputeNormal(vtkPoints *p, int numPts, vtkIdType *pts, 00165 double n[3]); 00167 00169 static void ComputeNormal(double v1[3], double v2[3], double v3[3], double n[3]); 00170 00172 00174 static void ComputeNormalDirection(double v1[3], double v2[3], double v3[3], 00175 double n[3]); 00177 00179 00184 static int PointInTriangle(double x[3], double x1[3], 00185 double x2[3], double x3[3], 00186 double tol2); 00188 00190 00193 static void ComputeQuadric(double x1[3], double x2[3], double x3[3], 00194 double quadric[4][4]); 00195 static void ComputeQuadric(double x1[3], double x2[3], double x3[3], 00196 vtkQuadric *quadric); 00198 00199 00200 protected: 00201 vtkTriangle(); 00202 ~vtkTriangle(); 00203 00204 vtkLine *Line; 00205 00206 private: 00207 vtkTriangle(const vtkTriangle&); // Not implemented. 00208 void operator=(const vtkTriangle&); // Not implemented. 00209 }; 00210 00211 //---------------------------------------------------------------------------- 00212 inline int vtkTriangle::GetParametricCenter(double pcoords[3]) 00213 { 00214 pcoords[0] = pcoords[1] = 1./3; pcoords[2] = 0.0; 00215 return 0; 00216 } 00217 00218 //---------------------------------------------------------------------------- 00219 inline void vtkTriangle::ComputeNormalDirection(double v1[3], double v2[3], 00220 double v3[3], double n[3]) 00221 { 00222 double ax, ay, az, bx, by, bz; 00223 00224 // order is important!!! maintain consistency with triangle vertex order 00225 ax = v3[0] - v2[0]; ay = v3[1] - v2[1]; az = v3[2] - v2[2]; 00226 bx = v1[0] - v2[0]; by = v1[1] - v2[1]; bz = v1[2] - v2[2]; 00227 00228 n[0] = (ay * bz - az * by); 00229 n[1] = (az * bx - ax * bz); 00230 n[2] = (ax * by - ay * bx); 00231 } 00232 00233 //---------------------------------------------------------------------------- 00234 inline void vtkTriangle::ComputeNormal(double v1[3], double v2[3], 00235 double v3[3], double n[3]) 00236 { 00237 double length; 00238 00239 vtkTriangle::ComputeNormalDirection(v1, v2, v3, n); 00240 00241 if ( (length = sqrt((n[0]*n[0] + n[1]*n[1] + n[2]*n[2]))) != 0.0 ) 00242 { 00243 n[0] /= length; 00244 n[1] /= length; 00245 n[2] /= length; 00246 } 00247 } 00248 00249 //---------------------------------------------------------------------------- 00250 inline void vtkTriangle::TriangleCenter(double p1[3], double p2[3], 00251 double p3[3], double center[3]) 00252 { 00253 center[0] = (p1[0]+p2[0]+p3[0]) / 3.0; 00254 center[1] = (p1[1]+p2[1]+p3[1]) / 3.0; 00255 center[2] = (p1[2]+p2[2]+p3[2]) / 3.0; 00256 } 00257 00258 //---------------------------------------------------------------------------- 00259 inline double vtkTriangle::TriangleArea(double p1[3], double p2[3], double p3[3]) 00260 { 00261 double a,b,c; 00262 a = vtkMath::Distance2BetweenPoints(p1,p2); 00263 b = vtkMath::Distance2BetweenPoints(p2,p3); 00264 c = vtkMath::Distance2BetweenPoints(p3,p1); 00265 return (0.25* sqrt(fabs(4.0*a*c - (a-b+c)*(a-b+c)))); 00266 } 00267 00268 #endif 00269 00270