Main Page | Directories | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

vtkTriangle.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkTriangle.h,v $
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00038 #ifndef __vtkTriangle_h
00039 #define __vtkTriangle_h
00040 
00041 #include "vtkCell.h"
00042 
00043 #include "vtkMath.h" // Needed for inline methods
00044 
00045 class vtkLine;
00046 class vtkQuadric;
00047 
00048 class VTK_FILTERING_EXPORT vtkTriangle : public vtkCell
00049 {
00050 public:
00051   static vtkTriangle *New();
00052   vtkTypeRevisionMacro(vtkTriangle,vtkCell);
00053   void PrintSelf(ostream& os, vtkIndent indent);
00054 
00060   vtkCell *GetEdge(int edgeId);
00061 
00063 
00064   int GetCellType() {return VTK_TRIANGLE;};
00065   int GetCellDimension() {return 2;};
00066   int GetNumberOfEdges() {return 3;};
00067   int GetNumberOfFaces() {return 0;};
00068   vtkCell *GetFace(int) {return 0;};
00069   int CellBoundary(int subId, double pcoords[3], vtkIdList *pts);
00070   void Contour(double value, vtkDataArray *cellScalars, 
00071                vtkPointLocator *locator, vtkCellArray *verts,
00072                vtkCellArray *lines, vtkCellArray *polys, 
00073                vtkPointData *inPd, vtkPointData *outPd,
00074                vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd);
00075   int EvaluatePosition(double x[3], double* closestPoint,
00076                        int& subId, double pcoords[3],
00077                        double& dist2, double *weights);
00078   void EvaluateLocation(int& subId, double pcoords[3], double x[3],
00079                         double *weights);
00080   int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts);
00081   void Derivatives(int subId, double pcoords[3], double *values, 
00082                    int dim, double *derivs);
00083   virtual double *GetParametricCoords();
00085 
00087 
00089   void Clip(double value, vtkDataArray *cellScalars, 
00090             vtkPointLocator *locator, vtkCellArray *polys,
00091             vtkPointData *inPd, vtkPointData *outPd,
00092             vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd,
00093             int insideOut);
00095 
00097 
00098   static void InterpolationFunctions(double pcoords[3], double sf[3]);
00099   static void InterpolationDerivs(double pcoords[3], double derivs[6]);
00101 
00103 
00105   int IntersectWithLine(double p1[3], double p2[3], double tol, double& t,
00106                         double x[3], double pcoords[3], int& subId);
00108 
00110   int GetParametricCenter(double pcoords[3]);
00111 
00114   double GetParametricDistance(double pcoords[3]);
00115 
00117 
00118   static void TriangleCenter(double p1[3], double p2[3], double p3[3], 
00119                              double center[3]);
00121 
00123   static double TriangleArea(double p1[3], double p2[3], double p3[3]);
00124   
00126 
00130   static double Circumcircle(double  p1[2], double p2[2], double p3[2], 
00131                             double center[2]);
00133 
00135 
00146   static int BarycentricCoords(double x[2], double  x1[2], double x2[2], 
00147                                double x3[2], double bcoords[3]);
00149   
00150   
00152 
00155   static int ProjectTo2D(double x1[3], double x2[3], double x3[3],
00156                          double v1[2], double v2[2], double v3[2]);
00158 
00160 
00162   static void ComputeNormal(vtkPoints *p, int numPts, vtkIdType *pts,
00163                             double n[3]);
00165 
00167   static void ComputeNormal(double v1[3], double v2[3], double v3[3], double n[3]);
00168 
00170 
00172   static void ComputeNormalDirection(double v1[3], double v2[3], double v3[3],
00173                                      double n[3]);
00175   
00177 
00182   static int PointInTriangle(double x[3], double x1[3], 
00183                              double x2[3], double x3[3], 
00184                              double tol2);
00186 
00188 
00191   static void ComputeQuadric(double x1[3], double x2[3], double x3[3],
00192                              double quadric[4][4]);
00193   static void ComputeQuadric(double x1[3], double x2[3], double x3[3],
00194                              vtkQuadric *quadric);
00196   
00197 
00198 protected:
00199   vtkTriangle();
00200   ~vtkTriangle();
00201 
00202   vtkLine *Line;
00203 
00204 private:
00205   vtkTriangle(const vtkTriangle&);  // Not implemented.
00206   void operator=(const vtkTriangle&);  // Not implemented.
00207 };
00208 
00209 //----------------------------------------------------------------------------
00210 inline int vtkTriangle::GetParametricCenter(double pcoords[3])
00211 {
00212   pcoords[0] = pcoords[1] = 1./3; pcoords[2] = 0.0;
00213   return 0;
00214 }
00215 
00216 //----------------------------------------------------------------------------
00217 inline void vtkTriangle::ComputeNormalDirection(double v1[3], double v2[3], 
00218                                        double v3[3], double n[3])
00219 {
00220   double ax, ay, az, bx, by, bz;
00221 
00222   // order is important!!! maintain consistency with triangle vertex order 
00223   ax = v3[0] - v2[0]; ay = v3[1] - v2[1]; az = v3[2] - v2[2];
00224   bx = v1[0] - v2[0]; by = v1[1] - v2[1]; bz = v1[2] - v2[2];
00225 
00226   n[0] = (ay * bz - az * by);
00227   n[1] = (az * bx - ax * bz);
00228   n[2] = (ax * by - ay * bx);
00229 }
00230 
00231 //----------------------------------------------------------------------------
00232 inline void vtkTriangle::ComputeNormal(double v1[3], double v2[3], 
00233                                        double v3[3], double n[3])
00234 {
00235   double length;
00236 
00237   vtkTriangle::ComputeNormalDirection(v1, v2, v3, n);
00238 
00239   if ( (length = sqrt((n[0]*n[0] + n[1]*n[1] + n[2]*n[2]))) != 0.0 )
00240     {
00241     n[0] /= length;
00242     n[1] /= length;
00243     n[2] /= length;
00244     }
00245 }
00246 
00247 //----------------------------------------------------------------------------
00248 inline void vtkTriangle::TriangleCenter(double p1[3], double p2[3], 
00249                                         double p3[3], double center[3])
00250 {
00251   center[0] = (p1[0]+p2[0]+p3[0]) / 3.0;
00252   center[1] = (p1[1]+p2[1]+p3[1]) / 3.0;
00253   center[2] = (p1[2]+p2[2]+p3[2]) / 3.0;
00254 }
00255 
00256 //----------------------------------------------------------------------------
00257 inline double vtkTriangle::TriangleArea(double p1[3], double p2[3], double p3[3])
00258 {
00259   double a,b,c;
00260   a = vtkMath::Distance2BetweenPoints(p1,p2);
00261   b = vtkMath::Distance2BetweenPoints(p2,p3);
00262   c = vtkMath::Distance2BetweenPoints(p3,p1);
00263   return (0.25* sqrt(fabs(4.0*a*c - (a-b+c)*(a-b+c))));
00264 } 
00265 
00266 #endif
00267 
00268