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
00085 static void InterpolationFunctions(double pcoords[3], double sf[3]);
00086 static void InterpolationDerivs(double pcoords[3], double derivs[6]);
00088
00090
00092 int IntersectWithLine(double p1[3], double p2[3], double tol, double& t,
00093 double x[3], double pcoords[3], int& subId);
00095
00097 int GetParametricCenter(double pcoords[3]);
00098
00101 double GetParametricDistance(double pcoords[3]);
00102
00104
00105 static void TriangleCenter(double p1[3], double p2[3], double p3[3],
00106 double center[3]);
00108
00110 static double TriangleArea(double p1[3], double p2[3], double p3[3]);
00111
00113
00117 static double Circumcircle(double p1[2], double p2[2], double p3[2],
00118 double center[2]);
00120
00122
00133 static int BarycentricCoords(double x[2], double x1[2], double x2[2],
00134 double x3[2], double bcoords[3]);
00136
00137
00139
00142 static int ProjectTo2D(double x1[3], double x2[3], double x3[3],
00143 double v1[2], double v2[2], double v3[2]);
00145
00147
00149 static void ComputeNormal(vtkPoints *p, int numPts, vtkIdType *pts,
00150 double n[3]);
00152
00154 static void ComputeNormal(double v1[3], double v2[3], double v3[3], double n[3]);
00155
00157
00159 static void ComputeNormalDirection(double v1[3], double v2[3], double v3[3],
00160 double n[3]);
00162
00164
00169 static int PointInTriangle(double x[3], double x1[3],
00170 double x2[3], double x3[3],
00171 double tol2);
00173
00175
00178 static void ComputeQuadric(double x1[3], double x2[3], double x3[3],
00179 double quadric[4][4]);
00180 static void ComputeQuadric(double x1[3], double x2[3], double x3[3],
00181 vtkQuadric *quadric);
00183
00184
00185 protected:
00186 vtkTriangle();
00187 ~vtkTriangle();
00188
00189 vtkLine *Line;
00190
00191 private:
00192 vtkTriangle(const vtkTriangle&);
00193 void operator=(const vtkTriangle&);
00194 };
00195
00196
00197 inline int vtkTriangle::GetParametricCenter(double pcoords[3])
00198 {
00199 pcoords[0] = pcoords[1] = 1./3; pcoords[2] = 0.0;
00200 return 0;
00201 }
00202
00203
00204 inline void vtkTriangle::ComputeNormalDirection(double v1[3], double v2[3],
00205 double v3[3], double n[3])
00206 {
00207 double ax, ay, az, bx, by, bz;
00208
00209
00210 ax = v3[0] - v2[0]; ay = v3[1] - v2[1]; az = v3[2] - v2[2];
00211 bx = v1[0] - v2[0]; by = v1[1] - v2[1]; bz = v1[2] - v2[2];
00212
00213 n[0] = (ay * bz - az * by);
00214 n[1] = (az * bx - ax * bz);
00215 n[2] = (ax * by - ay * bx);
00216 }
00217
00218
00219 inline void vtkTriangle::ComputeNormal(double v1[3], double v2[3],
00220 double v3[3], double n[3])
00221 {
00222 double length;
00223
00224 vtkTriangle::ComputeNormalDirection(v1, v2, v3, n);
00225
00226 if ( (length = sqrt((n[0]*n[0] + n[1]*n[1] + n[2]*n[2]))) != 0.0 )
00227 {
00228 n[0] /= length;
00229 n[1] /= length;
00230 n[2] /= length;
00231 }
00232 }
00233
00234
00235 inline void vtkTriangle::TriangleCenter(double p1[3], double p2[3],
00236 double p3[3], double center[3])
00237 {
00238 center[0] = (p1[0]+p2[0]+p3[0]) / 3.0;
00239 center[1] = (p1[1]+p2[1]+p3[1]) / 3.0;
00240 center[2] = (p1[2]+p2[2]+p3[2]) / 3.0;
00241 }
00242
00243
00244 inline double vtkTriangle::TriangleArea(double p1[3], double p2[3], double p3[3])
00245 {
00246 double a,b,c;
00247 a = vtkMath::Distance2BetweenPoints(p1,p2);
00248 b = vtkMath::Distance2BetweenPoints(p2,p3);
00249 c = vtkMath::Distance2BetweenPoints(p3,p1);
00250 return (0.25* sqrt(fabs(4.0*a*c - (a-b+c)*(a-b+c))));
00251 }
00252
00253 #endif
00254
00255