00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00056 #ifndef __vtkTriangle_h
00057 #define __vtkTriangle_h
00058
00059 #include "vtkCell.h"
00060 #include "vtkMath.h"
00061 #include "vtkLine.h"
00062 #include "vtkQuadric.h"
00063
00064 class VTK_COMMON_EXPORT vtkTriangle : public vtkCell
00065 {
00066 public:
00067 static vtkTriangle *New();
00068 vtkTypeMacro(vtkTriangle,vtkCell);
00069
00072 vtkCell *MakeObject();
00073
00076 vtkCell *GetEdge(int edgeId);
00077
00079
00080 int GetCellType() {return VTK_TRIANGLE;};
00081 int GetCellDimension() {return 2;};
00082 int GetNumberOfEdges() {return 3;};
00083 int GetNumberOfFaces() {return 0;};
00084 vtkCell *GetFace(int) {return 0;};
00085 int CellBoundary(int subId, float pcoords[3], vtkIdList *pts);
00086 void Contour(float value, vtkDataArray *cellScalars,
00087 vtkPointLocator *locator, vtkCellArray *verts,
00088 vtkCellArray *lines, vtkCellArray *polys,
00089 vtkPointData *inPd, vtkPointData *outPd,
00090 vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd);
00091 int EvaluatePosition(float x[3], float* closestPoint,
00092 int& subId, float pcoords[3],
00093 float& dist2, float *weights);
00094 void EvaluateLocation(int& subId, float pcoords[3], float x[3],
00095 float *weights);
00096 int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts);
00097 void Derivatives(int subId, float pcoords[3], float *values,
00098 int dim, float *derivs);
00100
00102
00104 void Clip(float value, vtkDataArray *cellScalars,
00105 vtkPointLocator *locator, vtkCellArray *polys,
00106 vtkPointData *inPd, vtkPointData *outPd,
00107 vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd,
00108 int insideOut);
00110
00112
00114 int IntersectWithLine(float p1[3], float p2[3], float tol, float& t,
00115 float x[3], float pcoords[3], int& subId);
00117
00119 int GetParametricCenter(float pcoords[3]);
00120
00122
00123 static void TriangleCenter(float p1[3], float p2[3], float p3[3],
00124 float center[3]);
00126
00128 static float TriangleArea(float p1[3], float p2[3], float p3[3]);
00129
00131
00135 static double Circumcircle(double p1[2], double p2[2], double p3[2],
00136 double center[2]);
00138
00140
00151 static int BarycentricCoords(double x[2], double x1[2], double x2[2],
00152 double x3[2], double bcoords[3]);
00154
00155
00157
00160 static int ProjectTo2D(double x1[3], double x2[3], double x3[3],
00161 double v1[2], double v2[2], double v3[2]);
00163
00165
00167 static void ComputeNormal(vtkPoints *p, int numPts, vtkIdType *pts,
00168 float n[3]);
00170
00172 static void ComputeNormal(float v1[3], float v2[3], float v3[3], float n[3]);
00173
00175
00177 static void ComputeNormalDirection(float v1[3], float v2[3], float v3[3],
00178 float n[3]);
00180
00182
00184 static void ComputeNormal(double v1[3], double v2[3], double v3[3],
00185 double n[3]);
00187
00189
00191 static void ComputeNormalDirection(double v1[3], double v2[3], double v3[3],
00192 double n[3]);
00194
00196
00201 static int PointInTriangle(float x[3], float x1[3], float x2[3], float x3[3],
00202 float tol2);
00204
00206
00209 static void ComputeQuadric(float x1[3], float x2[3], float x3[3],
00210 float quadric[4][4]);
00211 static void ComputeQuadric(float x1[3], float x2[3], float x3[3],
00212 vtkQuadric *quadric);
00214
00215
00216 protected:
00217 vtkTriangle();
00218 ~vtkTriangle();
00219
00220 vtkLine *Line;
00221
00222 private:
00223 vtkTriangle(const vtkTriangle&);
00224 void operator=(const vtkTriangle&);
00225 };
00226
00227 inline int vtkTriangle::GetParametricCenter(float pcoords[3])
00228 {
00229 pcoords[0] = pcoords[1] = 0.333; pcoords[2] = 0.0;
00230 return 0;
00231 }
00232
00233 inline void vtkTriangle::ComputeNormalDirection(float v1[3], float v2[3],
00234 float v3[3], float n[3])
00235 {
00236 float ax, ay, az, bx, by, bz;
00237
00238
00239 ax = v3[0] - v2[0]; ay = v3[1] - v2[1]; az = v3[2] - v2[2];
00240 bx = v1[0] - v2[0]; by = v1[1] - v2[1]; bz = v1[2] - v2[2];
00241
00242 n[0] = (ay * bz - az * by);
00243 n[1] = (az * bx - ax * bz);
00244 n[2] = (ax * by - ay * bx);
00245 }
00246
00247 inline void vtkTriangle::ComputeNormal(float v1[3], float v2[3],
00248 float v3[3], float n[3])
00249 {
00250 float length;
00251
00252 vtkTriangle::ComputeNormalDirection(v1, v2, v3, n);
00253
00254 if ( (length = sqrt((n[0]*n[0] + n[1]*n[1] + n[2]*n[2]))) != 0.0 )
00255 {
00256 n[0] /= length;
00257 n[1] /= length;
00258 n[2] /= length;
00259 }
00260 }
00261
00262 inline void vtkTriangle::ComputeNormalDirection(double v1[3], double v2[3],
00263 double v3[3], double n[3])
00264 {
00265 double ax, ay, az, bx, by, bz;
00266
00267
00268 ax = v3[0] - v2[0]; ay = v3[1] - v2[1]; az = v3[2] - v2[2];
00269 bx = v1[0] - v2[0]; by = v1[1] - v2[1]; bz = v1[2] - v2[2];
00270
00271 n[0] = (ay * bz - az * by);
00272 n[1] = (az * bx - ax * bz);
00273 n[2] = (ax * by - ay * bx);
00274 }
00275
00276 inline void vtkTriangle::ComputeNormal(double v1[3], double v2[3],
00277 double v3[3], double n[3])
00278 {
00279 double length;
00280
00281 vtkTriangle::ComputeNormalDirection(v1, v2, v3, n);
00282
00283 if ( (length = sqrt((n[0]*n[0] + n[1]*n[1] + n[2]*n[2]))) != 0.0 )
00284 {
00285 n[0] /= length;
00286 n[1] /= length;
00287 n[2] /= length;
00288 }
00289 }
00290
00291 inline void vtkTriangle::TriangleCenter(float p1[3], float p2[3], float p3[3],
00292 float center[3])
00293 {
00294 center[0] = (p1[0]+p2[0]+p3[0]) / 3.0;
00295 center[1] = (p1[1]+p2[1]+p3[1]) / 3.0;
00296 center[2] = (p1[2]+p2[2]+p3[2]) / 3.0;
00297 }
00298
00299 inline float vtkTriangle::TriangleArea(float p1[3], float p2[3], float p3[3])
00300 {
00301 float a,b,c;
00302 a = vtkMath::Distance2BetweenPoints(p1,p2);
00303 b = vtkMath::Distance2BetweenPoints(p2,p3);
00304 c = vtkMath::Distance2BetweenPoints(p3,p1);
00305 return (0.25* sqrt(fabs((double)4.0*a*c - (a-b+c)*(a-b+c))));
00306 }
00307
00308 #endif
00309
00310