00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00025 #ifndef __vtkTriangle_h
00026 #define __vtkTriangle_h
00027
00028 #include "vtkCell.h"
00029
00030 #include "vtkMath.h"
00031
00032 class vtkLine;
00033 class vtkQuadric;
00034 class vtkIncrementalPointLocator;
00035
00036 class VTK_FILTERING_EXPORT vtkTriangle : public vtkCell
00037 {
00038 public:
00039 static vtkTriangle *New();
00040 vtkTypeRevisionMacro(vtkTriangle,vtkCell);
00041 void PrintSelf(ostream& os, vtkIndent indent);
00042
00045 vtkCell *GetEdge(int edgeId);
00046
00048
00049 int GetCellType() {return VTK_TRIANGLE;};
00050 int GetCellDimension() {return 2;};
00051 int GetNumberOfEdges() {return 3;};
00052 int GetNumberOfFaces() {return 0;};
00053 vtkCell *GetFace(int) {return 0;};
00054 int CellBoundary(int subId, double pcoords[3], vtkIdList *pts);
00055 void Contour(double value, vtkDataArray *cellScalars,
00056 vtkIncrementalPointLocator *locator, vtkCellArray *verts,
00057 vtkCellArray *lines, vtkCellArray *polys,
00058 vtkPointData *inPd, vtkPointData *outPd,
00059 vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd);
00060 int EvaluatePosition(double x[3], double* closestPoint,
00061 int& subId, double pcoords[3],
00062 double& dist2, double *weights);
00063 void EvaluateLocation(int& subId, double pcoords[3], double x[3],
00064 double *weights);
00065 int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts);
00066 void Derivatives(int subId, double pcoords[3], double *values,
00067 int dim, double *derivs);
00068 virtual double *GetParametricCoords();
00070
00072 double ComputeArea();
00073
00075
00077 void Clip(double value, vtkDataArray *cellScalars,
00078 vtkIncrementalPointLocator *locator, vtkCellArray *polys,
00079 vtkPointData *inPd, vtkPointData *outPd,
00080 vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd,
00081 int insideOut);
00083
00085
00087 static void InterpolationFunctions(double pcoords[3], double sf[3]);
00088
00089
00090 static void InterpolationDerivs(double pcoords[3], double derivs[6]);
00091
00092
00093
00094 virtual void InterpolateFunctions(double pcoords[3], double sf[3])
00095 {
00096 vtkTriangle::InterpolationFunctions(pcoords,sf);
00097 }
00098 virtual void InterpolateDerivs(double pcoords[3], double derivs[6])
00099 {
00100 vtkTriangle::InterpolationDerivs(pcoords,derivs);
00101 }
00102
00103
00104
00105 int *GetEdgeArray(int edgeId);
00107
00109
00111 int IntersectWithLine(double p1[3], double p2[3], double tol, double& t,
00112 double x[3], double pcoords[3], int& subId);
00114
00116 int GetParametricCenter(double pcoords[3]);
00117
00120 double GetParametricDistance(double pcoords[3]);
00121
00123
00124 static void TriangleCenter(double p1[3], double p2[3], double p3[3],
00125 double center[3]);
00127
00130 static double TriangleArea(double p1[3], double p2[3], double p3[3]);
00131
00133
00137 static double Circumcircle(double p1[2], double p2[2], double p3[2],
00138 double center[2]);
00140
00142
00153 static int BarycentricCoords(double x[2], double x1[2], double x2[2],
00154 double x3[2], double bcoords[3]);
00156
00157
00159
00162 static int ProjectTo2D(double x1[3], double x2[3], double x3[3],
00163 double v1[2], double v2[2], double v3[2]);
00165
00167
00169 static void ComputeNormal(vtkPoints *p, int numPts, vtkIdType *pts,
00170 double n[3]);
00172
00174 static void ComputeNormal(double v1[3], double v2[3], double v3[3], double n[3]);
00175
00177
00179 static void ComputeNormalDirection(double v1[3], double v2[3], double v3[3],
00180 double n[3]);
00182
00184
00189 static int PointInTriangle(double x[3], double x1[3],
00190 double x2[3], double x3[3],
00191 double tol2);
00193
00195
00198 static void ComputeQuadric(double x1[3], double x2[3], double x3[3],
00199 double quadric[4][4]);
00200 static void ComputeQuadric(double x1[3], double x2[3], double x3[3],
00201 vtkQuadric *quadric);
00203
00204
00205 protected:
00206 vtkTriangle();
00207 ~vtkTriangle();
00208
00209 vtkLine *Line;
00210
00211 private:
00212 vtkTriangle(const vtkTriangle&);
00213 void operator=(const vtkTriangle&);
00214 };
00215
00216
00217 inline int vtkTriangle::GetParametricCenter(double pcoords[3])
00218 {
00219 pcoords[0] = pcoords[1] = 1./3; pcoords[2] = 0.0;
00220 return 0;
00221 }
00222
00223
00224 inline void vtkTriangle::ComputeNormalDirection(double v1[3], double v2[3],
00225 double v3[3], double n[3])
00226 {
00227 double ax, ay, az, bx, by, bz;
00228
00229
00230 ax = v3[0] - v2[0]; ay = v3[1] - v2[1]; az = v3[2] - v2[2];
00231 bx = v1[0] - v2[0]; by = v1[1] - v2[1]; bz = v1[2] - v2[2];
00232
00233 n[0] = (ay * bz - az * by);
00234 n[1] = (az * bx - ax * bz);
00235 n[2] = (ax * by - ay * bx);
00236 }
00237
00238
00239 inline void vtkTriangle::ComputeNormal(double v1[3], double v2[3],
00240 double v3[3], double n[3])
00241 {
00242 double length;
00243
00244 vtkTriangle::ComputeNormalDirection(v1, v2, v3, n);
00245
00246 if ( (length = sqrt((n[0]*n[0] + n[1]*n[1] + n[2]*n[2]))) != 0.0 )
00247 {
00248 n[0] /= length;
00249 n[1] /= length;
00250 n[2] /= length;
00251 }
00252 }
00253
00254
00255 inline void vtkTriangle::TriangleCenter(double p1[3], double p2[3],
00256 double p3[3], double center[3])
00257 {
00258 center[0] = (p1[0]+p2[0]+p3[0]) / 3.0;
00259 center[1] = (p1[1]+p2[1]+p3[1]) / 3.0;
00260 center[2] = (p1[2]+p2[2]+p3[2]) / 3.0;
00261 }
00262
00263
00264 inline double vtkTriangle::TriangleArea(double p1[3], double p2[3], double p3[3])
00265 {
00266 double a,b,c;
00267 a = vtkMath::Distance2BetweenPoints(p1,p2);
00268 b = vtkMath::Distance2BetweenPoints(p2,p3);
00269 c = vtkMath::Distance2BetweenPoints(p3,p1);
00270 return (0.25* sqrt(fabs(4.0*a*c - (a-b+c)*(a-b+c))));
00271 }
00272
00273 #endif
00274
00275