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 Language: C++ 00006 00007 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 00008 All rights reserved. 00009 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00010 00011 This software is distributed WITHOUT ANY WARRANTY; without even 00012 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00013 PURPOSE. See the above copyright notice for more information. 00014 00015 =========================================================================*/ 00032 #ifndef __vtkTriangle_h 00033 #define __vtkTriangle_h 00034 00035 #include "vtkCell.h" 00036 00037 #include "vtkMath.h" // Needed for inline methods 00038 00039 class vtkLine; 00040 class vtkQuadric; 00041 00042 class VTK_COMMON_EXPORT vtkTriangle : public vtkCell 00043 { 00044 public: 00045 static vtkTriangle *New(); 00046 vtkTypeRevisionMacro(vtkTriangle,vtkCell); 00047 00053 vtkCell *GetEdge(int edgeId); 00054 00056 00057 int GetCellType() {return VTK_TRIANGLE;}; 00058 int GetCellDimension() {return 2;}; 00059 int GetNumberOfEdges() {return 3;}; 00060 int GetNumberOfFaces() {return 0;}; 00061 vtkCell *GetFace(int) {return 0;}; 00062 int CellBoundary(int subId, float pcoords[3], vtkIdList *pts); 00063 void Contour(float value, vtkDataArray *cellScalars, 00064 vtkPointLocator *locator, vtkCellArray *verts, 00065 vtkCellArray *lines, vtkCellArray *polys, 00066 vtkPointData *inPd, vtkPointData *outPd, 00067 vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd); 00068 int EvaluatePosition(float x[3], float* closestPoint, 00069 int& subId, float pcoords[3], 00070 float& dist2, float *weights); 00071 void EvaluateLocation(int& subId, float pcoords[3], float x[3], 00072 float *weights); 00073 int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts); 00074 void Derivatives(int subId, float pcoords[3], float *values, 00075 int dim, float *derivs); 00077 00079 00081 void Clip(float value, vtkDataArray *cellScalars, 00082 vtkPointLocator *locator, vtkCellArray *polys, 00083 vtkPointData *inPd, vtkPointData *outPd, 00084 vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd, 00085 int insideOut); 00087 00089 00091 int IntersectWithLine(float p1[3], float p2[3], float tol, float& t, 00092 float x[3], float pcoords[3], int& subId); 00094 00096 int GetParametricCenter(float pcoords[3]); 00097 00099 00100 static void TriangleCenter(float p1[3], float p2[3], float p3[3], 00101 float center[3]); 00103 00105 static float TriangleArea(float p1[3], float p2[3], float p3[3]); 00106 00108 00112 static double Circumcircle(double p1[2], double p2[2], double p3[2], 00113 double center[2]); 00115 00117 00128 static int BarycentricCoords(double x[2], double x1[2], double x2[2], 00129 double x3[2], double bcoords[3]); 00131 00132 00134 00137 static int ProjectTo2D(double x1[3], double x2[3], double x3[3], 00138 double v1[2], double v2[2], double v3[2]); 00140 00142 00144 static void ComputeNormal(vtkPoints *p, int numPts, vtkIdType *pts, 00145 float n[3]); 00147 00149 static void ComputeNormal(float v1[3], float v2[3], float v3[3], float n[3]); 00150 00152 00154 static void ComputeNormalDirection(float v1[3], float v2[3], float v3[3], 00155 float n[3]); 00157 00159 00161 static void ComputeNormal(double v1[3], double v2[3], double v3[3], 00162 double n[3]); 00164 00166 00168 static void ComputeNormalDirection(double v1[3], double v2[3], double v3[3], 00169 double n[3]); 00171 00173 00178 static int PointInTriangle(float x[3], float x1[3], float x2[3], float x3[3], 00179 float tol2); 00181 00183 00186 static void ComputeQuadric(float x1[3], float x2[3], float x3[3], 00187 float quadric[4][4]); 00188 static void ComputeQuadric(float x1[3], float x2[3], float x3[3], 00189 vtkQuadric *quadric); 00191 00192 00193 protected: 00194 vtkTriangle(); 00195 ~vtkTriangle(); 00196 00197 vtkLine *Line; 00198 00199 private: 00200 vtkTriangle(const vtkTriangle&); // Not implemented. 00201 void operator=(const vtkTriangle&); // Not implemented. 00202 }; 00203 00204 inline int vtkTriangle::GetParametricCenter(float pcoords[3]) 00205 { 00206 pcoords[0] = pcoords[1] = 0.333f; pcoords[2] = 0.0; 00207 return 0; 00208 } 00209 00210 inline void vtkTriangle::ComputeNormalDirection(float v1[3], float v2[3], 00211 float v3[3], float n[3]) 00212 { 00213 float ax, ay, az, bx, by, bz; 00214 00215 // order is important!!! maintain consistency with triangle vertex order 00216 ax = v3[0] - v2[0]; ay = v3[1] - v2[1]; az = v3[2] - v2[2]; 00217 bx = v1[0] - v2[0]; by = v1[1] - v2[1]; bz = v1[2] - v2[2]; 00218 00219 n[0] = (ay * bz - az * by); 00220 n[1] = (az * bx - ax * bz); 00221 n[2] = (ax * by - ay * bx); 00222 } 00223 00224 inline void vtkTriangle::ComputeNormal(float v1[3], float v2[3], 00225 float v3[3], float n[3]) 00226 { 00227 float length; 00228 00229 vtkTriangle::ComputeNormalDirection(v1, v2, v3, n); 00230 00231 if ( (length = static_cast<float>(sqrt((n[0]*n[0] + n[1]*n[1] + n[2]*n[2])))) != 0.0 ) 00232 { 00233 n[0] /= length; 00234 n[1] /= length; 00235 n[2] /= length; 00236 } 00237 } 00238 00239 inline void vtkTriangle::ComputeNormalDirection(double v1[3], double v2[3], 00240 double v3[3], double n[3]) 00241 { 00242 double ax, ay, az, bx, by, bz; 00243 00244 // order is important!!! maintain consistency with triangle vertex order 00245 ax = v3[0] - v2[0]; ay = v3[1] - v2[1]; az = v3[2] - v2[2]; 00246 bx = v1[0] - v2[0]; by = v1[1] - v2[1]; bz = v1[2] - v2[2]; 00247 00248 n[0] = (ay * bz - az * by); 00249 n[1] = (az * bx - ax * bz); 00250 n[2] = (ax * by - ay * bx); 00251 } 00252 00253 inline void vtkTriangle::ComputeNormal(double v1[3], double v2[3], 00254 double v3[3], double n[3]) 00255 { 00256 double length; 00257 00258 vtkTriangle::ComputeNormalDirection(v1, v2, v3, n); 00259 00260 if ( (length = sqrt((n[0]*n[0] + n[1]*n[1] + n[2]*n[2]))) != 0.0 ) 00261 { 00262 n[0] /= length; 00263 n[1] /= length; 00264 n[2] /= length; 00265 } 00266 } 00267 00268 inline void vtkTriangle::TriangleCenter(float p1[3], float p2[3], float p3[3], 00269 float center[3]) 00270 { 00271 center[0] = (p1[0]+p2[0]+p3[0]) / 3.0f; 00272 center[1] = (p1[1]+p2[1]+p3[1]) / 3.0f; 00273 center[2] = (p1[2]+p2[2]+p3[2]) / 3.0f; 00274 } 00275 00276 inline float vtkTriangle::TriangleArea(float p1[3], float p2[3], float p3[3]) 00277 { 00278 float a,b,c; 00279 a = vtkMath::Distance2BetweenPoints(p1,p2); 00280 b = vtkMath::Distance2BetweenPoints(p2,p3); 00281 c = vtkMath::Distance2BetweenPoints(p3,p1); 00282 return static_cast<float>(0.25* sqrt(fabs((double)4.0*a*c - (a-b+c)*(a-b+c)))); 00283 } 00284 00285 #endif 00286 00287