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 class vtkIncrementalPointLocator;
00038
00039 class VTK_FILTERING_EXPORT vtkTriangle : public vtkCell
00040 {
00041 public:
00042 static vtkTriangle *New();
00043 vtkTypeMacro(vtkTriangle,vtkCell);
00044 void PrintSelf(ostream& os, vtkIndent indent);
00045
00048 vtkCell *GetEdge(int edgeId);
00049
00051
00052 int GetCellType() {return VTK_TRIANGLE;};
00053 int GetCellDimension() {return 2;};
00054 int GetNumberOfEdges() {return 3;};
00055 int GetNumberOfFaces() {return 0;};
00056 vtkCell *GetFace(int) {return 0;};
00057 int CellBoundary(int subId, double pcoords[3], vtkIdList *pts);
00058 void Contour(double value, vtkDataArray *cellScalars,
00059 vtkIncrementalPointLocator *locator, vtkCellArray *verts,
00060 vtkCellArray *lines, vtkCellArray *polys,
00061 vtkPointData *inPd, vtkPointData *outPd,
00062 vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd);
00063 int EvaluatePosition(double x[3], double* closestPoint,
00064 int& subId, double pcoords[3],
00065 double& dist2, double *weights);
00066 void EvaluateLocation(int& subId, double pcoords[3], double x[3],
00067 double *weights);
00068 int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts);
00069 void Derivatives(int subId, double pcoords[3], double *values,
00070 int dim, double *derivs);
00071 virtual double *GetParametricCoords();
00073
00075 double ComputeArea();
00076
00078
00080 void Clip(double value, vtkDataArray *cellScalars,
00081 vtkIncrementalPointLocator *locator, vtkCellArray *polys,
00082 vtkPointData *inPd, vtkPointData *outPd,
00083 vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd,
00084 int insideOut);
00086
00088
00090 static void InterpolationFunctions(double pcoords[3], double sf[3]);
00091
00092
00093 static void InterpolationDerivs(double pcoords[3], double derivs[6]);
00094
00095
00096
00097 virtual void InterpolateFunctions(double pcoords[3], double sf[3])
00098 {
00099 vtkTriangle::InterpolationFunctions(pcoords,sf);
00100 }
00101 virtual void InterpolateDerivs(double pcoords[3], double derivs[6])
00102 {
00103 vtkTriangle::InterpolationDerivs(pcoords,derivs);
00104 }
00105
00106
00107
00108 int *GetEdgeArray(int edgeId);
00110
00112
00114 int IntersectWithLine(double p1[3], double p2[3], double tol, double& t,
00115 double x[3], double pcoords[3], int& subId);
00117
00119 int GetParametricCenter(double pcoords[3]);
00120
00123 double GetParametricDistance(double pcoords[3]);
00124
00126
00127 static void TriangleCenter(double p1[3], double p2[3], double p3[3],
00128 double center[3]);
00130
00133 static double TriangleArea(double p1[3], double p2[3], double p3[3]);
00134
00136
00140 static double Circumcircle(double p1[2], double p2[2], double p3[2],
00141 double center[2]);
00143
00145
00156 static int BarycentricCoords(double x[2], double x1[2], double x2[2],
00157 double x3[2], double bcoords[3]);
00159
00160
00162
00165 static int ProjectTo2D(double x1[3], double x2[3], double x3[3],
00166 double v1[2], double v2[2], double v3[2]);
00168
00170
00172 static void ComputeNormal(vtkPoints *p, int numPts, vtkIdType *pts,
00173 double n[3]);
00175
00177 static void ComputeNormal(double v1[3], double v2[3], double v3[3], double n[3]);
00178
00180
00182 static void ComputeNormalDirection(double v1[3], double v2[3], double v3[3],
00183 double n[3]);
00185
00187
00192 static int PointInTriangle(double x[3], double x1[3],
00193 double x2[3], double x3[3],
00194 double tol2);
00196
00198
00201 static void ComputeQuadric(double x1[3], double x2[3], double x3[3],
00202 double quadric[4][4]);
00203 static void ComputeQuadric(double x1[3], double x2[3], double x3[3],
00204 vtkQuadric *quadric);
00206
00207
00208 protected:
00209 vtkTriangle();
00210 ~vtkTriangle();
00211
00212 vtkLine *Line;
00213
00214 private:
00215 vtkTriangle(const vtkTriangle&);
00216 void operator=(const vtkTriangle&);
00217 };
00218
00219
00220 inline int vtkTriangle::GetParametricCenter(double pcoords[3])
00221 {
00222 pcoords[0] = pcoords[1] = 1./3; pcoords[2] = 0.0;
00223 return 0;
00224 }
00225
00226
00227 inline void vtkTriangle::ComputeNormalDirection(double v1[3], double v2[3],
00228 double v3[3], double n[3])
00229 {
00230 double ax, ay, az, bx, by, bz;
00231
00232
00233 ax = v3[0] - v2[0]; ay = v3[1] - v2[1]; az = v3[2] - v2[2];
00234 bx = v1[0] - v2[0]; by = v1[1] - v2[1]; bz = v1[2] - v2[2];
00235
00236 n[0] = (ay * bz - az * by);
00237 n[1] = (az * bx - ax * bz);
00238 n[2] = (ax * by - ay * bx);
00239 }
00240
00241
00242 inline void vtkTriangle::ComputeNormal(double v1[3], double v2[3],
00243 double v3[3], double n[3])
00244 {
00245 double length;
00246
00247 vtkTriangle::ComputeNormalDirection(v1, v2, v3, n);
00248
00249 if ( (length = sqrt((n[0]*n[0] + n[1]*n[1] + n[2]*n[2]))) != 0.0 )
00250 {
00251 n[0] /= length;
00252 n[1] /= length;
00253 n[2] /= length;
00254 }
00255 }
00256
00257
00258 inline void vtkTriangle::TriangleCenter(double p1[3], double p2[3],
00259 double p3[3], double center[3])
00260 {
00261 center[0] = (p1[0]+p2[0]+p3[0]) / 3.0;
00262 center[1] = (p1[1]+p2[1]+p3[1]) / 3.0;
00263 center[2] = (p1[2]+p2[2]+p3[2]) / 3.0;
00264 }
00265
00266
00267 inline double vtkTriangle::TriangleArea(double p1[3], double p2[3], double p3[3])
00268 {
00269 double a,b,c;
00270 a = vtkMath::Distance2BetweenPoints(p1,p2);
00271 b = vtkMath::Distance2BetweenPoints(p2,p3);
00272 c = vtkMath::Distance2BetweenPoints(p3,p1);
00273 return (0.25* sqrt(fabs(4.0*a*c - (a-b+c)*(a-b+c))));
00274 }
00275
00276 #endif
00277
00278