Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

dox/Common/vtkTriangle.h

Go to the documentation of this file.
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 =========================================================================*/ 00028 #ifndef __vtkTriangle_h 00029 #define __vtkTriangle_h 00030 00031 #include "vtkCell.h" 00032 00033 #include "vtkMath.h" // Needed for inline methods 00034 00035 class vtkLine; 00036 class vtkQuadric; 00037 00038 class VTK_COMMON_EXPORT vtkTriangle : public vtkCell 00039 { 00040 public: 00041 static vtkTriangle *New(); 00042 vtkTypeRevisionMacro(vtkTriangle,vtkCell); 00043 00049 vtkCell *GetEdge(int edgeId); 00050 00052 00053 int GetCellType() {return VTK_TRIANGLE;}; 00054 int GetCellDimension() {return 2;}; 00055 int GetNumberOfEdges() {return 3;}; 00056 int GetNumberOfFaces() {return 0;}; 00057 vtkCell *GetFace(int) {return 0;}; 00058 int CellBoundary(int subId, double pcoords[3], vtkIdList *pts); 00059 void Contour(double value, vtkDataArray *cellScalars, 00060 vtkPointLocator *locator, vtkCellArray *verts, 00061 vtkCellArray *lines, vtkCellArray *polys, 00062 vtkPointData *inPd, vtkPointData *outPd, 00063 vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd); 00064 int EvaluatePosition(double x[3], double* closestPoint, 00065 int& subId, double pcoords[3], 00066 double& dist2, double *weights); 00067 void EvaluateLocation(int& subId, double pcoords[3], double x[3], 00068 double *weights); 00069 int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts); 00070 void Derivatives(int subId, double pcoords[3], double *values, 00071 int dim, double *derivs); 00072 virtual double *GetParametricCoords(); 00074 00076 00078 void Clip(double value, vtkDataArray *cellScalars, 00079 vtkPointLocator *locator, vtkCellArray *polys, 00080 vtkPointData *inPd, vtkPointData *outPd, 00081 vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd, 00082 int insideOut); 00084 00086 00088 int IntersectWithLine(double p1[3], double p2[3], double tol, double& t, 00089 double x[3], double pcoords[3], int& subId); 00091 00093 int GetParametricCenter(double pcoords[3]); 00094 00097 double GetParametricDistance(double pcoords[3]); 00098 00100 00101 static void TriangleCenter(double p1[3], double p2[3], double p3[3], 00102 double center[3]); 00104 00106 static double TriangleArea(double p1[3], double p2[3], double p3[3]); 00107 00109 00113 static double Circumcircle(double p1[2], double p2[2], double p3[2], 00114 double center[2]); 00116 00118 00129 static int BarycentricCoords(double x[2], double x1[2], double x2[2], 00130 double x3[2], double bcoords[3]); 00132 00133 00135 00138 static int ProjectTo2D(double x1[3], double x2[3], double x3[3], 00139 double v1[2], double v2[2], double v3[2]); 00141 00143 00145 static void ComputeNormal(vtkPoints *p, int numPts, vtkIdType *pts, 00146 double n[3]); 00148 00150 static void ComputeNormal(double v1[3], double v2[3], double v3[3], double n[3]); 00151 00153 00155 static void ComputeNormalDirection(double v1[3], double v2[3], double v3[3], 00156 double n[3]); 00158 00160 00165 static int PointInTriangle(double x[3], double x1[3], 00166 double x2[3], double x3[3], 00167 double tol2); 00169 00171 00174 static void ComputeQuadric(double x1[3], double x2[3], double x3[3], 00175 double quadric[4][4]); 00176 static void ComputeQuadric(double x1[3], double x2[3], double x3[3], 00177 vtkQuadric *quadric); 00179 00180 00181 protected: 00182 vtkTriangle(); 00183 ~vtkTriangle(); 00184 00185 vtkLine *Line; 00186 00187 private: 00188 vtkTriangle(const vtkTriangle&); // Not implemented. 00189 void operator=(const vtkTriangle&); // Not implemented. 00190 }; 00191 00192 inline int vtkTriangle::GetParametricCenter(double pcoords[3]) 00193 { 00194 pcoords[0] = pcoords[1] = 0.333f; pcoords[2] = 0.0; 00195 return 0; 00196 } 00197 00198 inline void vtkTriangle::ComputeNormalDirection(double v1[3], double v2[3], 00199 double v3[3], double n[3]) 00200 { 00201 double ax, ay, az, bx, by, bz; 00202 00203 // order is important!!! maintain consistency with triangle vertex order 00204 ax = v3[0] - v2[0]; ay = v3[1] - v2[1]; az = v3[2] - v2[2]; 00205 bx = v1[0] - v2[0]; by = v1[1] - v2[1]; bz = v1[2] - v2[2]; 00206 00207 n[0] = (ay * bz - az * by); 00208 n[1] = (az * bx - ax * bz); 00209 n[2] = (ax * by - ay * bx); 00210 } 00211 00212 inline void vtkTriangle::ComputeNormal(double v1[3], double v2[3], 00213 double v3[3], double n[3]) 00214 { 00215 double length; 00216 00217 vtkTriangle::ComputeNormalDirection(v1, v2, v3, n); 00218 00219 if ( (length = sqrt((n[0]*n[0] + n[1]*n[1] + n[2]*n[2]))) != 0.0 ) 00220 { 00221 n[0] /= length; 00222 n[1] /= length; 00223 n[2] /= length; 00224 } 00225 } 00226 00227 inline void vtkTriangle::TriangleCenter(double p1[3], double p2[3], 00228 double p3[3], double center[3]) 00229 { 00230 center[0] = (p1[0]+p2[0]+p3[0]) / 3.0f; 00231 center[1] = (p1[1]+p2[1]+p3[1]) / 3.0f; 00232 center[2] = (p1[2]+p2[2]+p3[2]) / 3.0f; 00233 } 00234 00235 inline double vtkTriangle::TriangleArea(double p1[3], double p2[3], double p3[3]) 00236 { 00237 double a,b,c; 00238 a = vtkMath::Distance2BetweenPoints(p1,p2); 00239 b = vtkMath::Distance2BetweenPoints(p2,p3); 00240 c = vtkMath::Distance2BetweenPoints(p3,p1); 00241 return (0.25* sqrt(fabs(4.0*a*c - (a-b+c)*(a-b+c)))); 00242 } 00243 00244 #endif 00245 00246