00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00028 #ifndef __vtkTriangle_h
00029 #define __vtkTriangle_h
00030
00031 #include "vtkCell.h"
00032
00033 #include "vtkMath.h"
00034
00035 class vtkLine;
00036 class vtkQuadric;
00037
00038 class VTK_FILTERING_EXPORT vtkTriangle : public vtkCell
00039 {
00040 public:
00041 static vtkTriangle *New();
00042 vtkTypeRevisionMacro(vtkTriangle,vtkCell);
00043 void PrintSelf(ostream& os, vtkIndent indent);
00044
00047 vtkCell *GetEdge(int edgeId);
00048
00050
00051 int GetCellType() {return VTK_TRIANGLE;};
00052 int GetCellDimension() {return 2;};
00053 int GetNumberOfEdges() {return 3;};
00054 int GetNumberOfFaces() {return 0;};
00055 vtkCell *GetFace(int) {return 0;};
00056 int CellBoundary(int subId, double pcoords[3], vtkIdList *pts);
00057 void Contour(double value, vtkDataArray *cellScalars,
00058 vtkPointLocator *locator, vtkCellArray *verts,
00059 vtkCellArray *lines, vtkCellArray *polys,
00060 vtkPointData *inPd, vtkPointData *outPd,
00061 vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd);
00062 int EvaluatePosition(double x[3], double* closestPoint,
00063 int& subId, double pcoords[3],
00064 double& dist2, double *weights);
00065 void EvaluateLocation(int& subId, double pcoords[3], double x[3],
00066 double *weights);
00067 int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts);
00068 void Derivatives(int subId, double pcoords[3], double *values,
00069 int dim, double *derivs);
00070 virtual double *GetParametricCoords();
00072
00074
00076 void Clip(double value, vtkDataArray *cellScalars,
00077 vtkPointLocator *locator, vtkCellArray *polys,
00078 vtkPointData *inPd, vtkPointData *outPd,
00079 vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd,
00080 int insideOut);
00082
00084
00086 static void InterpolationFunctions(double pcoords[3], double sf[3]);
00087
00088
00089 static void InterpolationDerivs(double pcoords[3], double derivs[6]);
00090
00091
00092
00093 virtual void InterpolateFunctions(double pcoords[3], double sf[3])
00094 {
00095 vtkTriangle::InterpolationFunctions(pcoords,sf);
00096 }
00097 virtual void InterpolateDerivs(double pcoords[3], double derivs[6])
00098 {
00099 vtkTriangle::InterpolationDerivs(pcoords,derivs);
00100 }
00101
00102
00103
00104 int *GetEdgeArray(int edgeId);
00106
00108
00110 int IntersectWithLine(double p1[3], double p2[3], double tol, double& t,
00111 double x[3], double pcoords[3], int& subId);
00113
00115 int GetParametricCenter(double pcoords[3]);
00116
00119 double GetParametricDistance(double pcoords[3]);
00120
00122
00123 static void TriangleCenter(double p1[3], double p2[3], double p3[3],
00124 double center[3]);
00126
00128 static double TriangleArea(double p1[3], double p2[3], double 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 double n[3]);
00170
00172 static void ComputeNormal(double v1[3], double v2[3], double v3[3], double n[3]);
00173
00175
00177 static void ComputeNormalDirection(double v1[3], double v2[3], double v3[3],
00178 double n[3]);
00180
00182
00187 static int PointInTriangle(double x[3], double x1[3],
00188 double x2[3], double x3[3],
00189 double tol2);
00191
00193
00196 static void ComputeQuadric(double x1[3], double x2[3], double x3[3],
00197 double quadric[4][4]);
00198 static void ComputeQuadric(double x1[3], double x2[3], double x3[3],
00199 vtkQuadric *quadric);
00201
00202
00203 protected:
00204 vtkTriangle();
00205 ~vtkTriangle();
00206
00207 vtkLine *Line;
00208
00209 private:
00210 vtkTriangle(const vtkTriangle&);
00211 void operator=(const vtkTriangle&);
00212 };
00213
00214
00215 inline int vtkTriangle::GetParametricCenter(double pcoords[3])
00216 {
00217 pcoords[0] = pcoords[1] = 1./3; pcoords[2] = 0.0;
00218 return 0;
00219 }
00220
00221
00222 inline void vtkTriangle::ComputeNormalDirection(double v1[3], double v2[3],
00223 double v3[3], double n[3])
00224 {
00225 double ax, ay, az, bx, by, bz;
00226
00227
00228 ax = v3[0] - v2[0]; ay = v3[1] - v2[1]; az = v3[2] - v2[2];
00229 bx = v1[0] - v2[0]; by = v1[1] - v2[1]; bz = v1[2] - v2[2];
00230
00231 n[0] = (ay * bz - az * by);
00232 n[1] = (az * bx - ax * bz);
00233 n[2] = (ax * by - ay * bx);
00234 }
00235
00236
00237 inline void vtkTriangle::ComputeNormal(double v1[3], double v2[3],
00238 double v3[3], double n[3])
00239 {
00240 double length;
00241
00242 vtkTriangle::ComputeNormalDirection(v1, v2, v3, n);
00243
00244 if ( (length = sqrt((n[0]*n[0] + n[1]*n[1] + n[2]*n[2]))) != 0.0 )
00245 {
00246 n[0] /= length;
00247 n[1] /= length;
00248 n[2] /= length;
00249 }
00250 }
00251
00252
00253 inline void vtkTriangle::TriangleCenter(double p1[3], double p2[3],
00254 double p3[3], double center[3])
00255 {
00256 center[0] = (p1[0]+p2[0]+p3[0]) / 3.0;
00257 center[1] = (p1[1]+p2[1]+p3[1]) / 3.0;
00258 center[2] = (p1[2]+p2[2]+p3[2]) / 3.0;
00259 }
00260
00261
00262 inline double vtkTriangle::TriangleArea(double p1[3], double p2[3], double p3[3])
00263 {
00264 double a,b,c;
00265 a = vtkMath::Distance2BetweenPoints(p1,p2);
00266 b = vtkMath::Distance2BetweenPoints(p2,p3);
00267 c = vtkMath::Distance2BetweenPoints(p3,p1);
00268 return (0.25* sqrt(fabs(4.0*a*c - (a-b+c)*(a-b+c))));
00269 }
00270
00271 #endif
00272
00273