Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Common/vtkTriangle.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkTriangle.h,v $
00005   Language:  C++
00006 
00007 
00008 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00009 All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without
00012 modification, are permitted provided that the following conditions are met:
00013 
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016 
00017  * Redistributions in binary form must reproduce the above copyright notice,
00018    this list of conditions and the following disclaimer in the documentation
00019    and/or other materials provided with the distribution.
00020 
00021  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00022    of any contributors may be used to endorse or promote products derived
00023    from this software without specific prior written permission.
00024 
00025  * Modified source versions must be plainly marked as such, and must not be
00026    misrepresented as being the original software.
00027 
00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00029 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00032 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00033 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00034 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00035 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00036 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 
00039 =========================================================================*/
00056 #ifndef __vtkTriangle_h
00057 #define __vtkTriangle_h
00058 
00059 #include "vtkCell.h"
00060 #include "vtkMath.h"
00061 #include "vtkLine.h"
00062 #include "vtkQuadric.h"
00063 
00064 class VTK_COMMON_EXPORT vtkTriangle : public vtkCell
00065 {
00066 public:
00067   static vtkTriangle *New();
00068   vtkTypeMacro(vtkTriangle,vtkCell);
00069 
00072   vtkCell *MakeObject();
00073 
00076   vtkCell *GetEdge(int edgeId);
00077 
00079 
00080   int GetCellType() {return VTK_TRIANGLE;};
00081   int GetCellDimension() {return 2;};
00082   int GetNumberOfEdges() {return 3;};
00083   int GetNumberOfFaces() {return 0;};
00084   vtkCell *GetFace(int) {return 0;};
00085   int CellBoundary(int subId, float pcoords[3], vtkIdList *pts);
00086   void Contour(float value, vtkDataArray *cellScalars, 
00087                vtkPointLocator *locator, vtkCellArray *verts,
00088                vtkCellArray *lines, vtkCellArray *polys, 
00089                vtkPointData *inPd, vtkPointData *outPd,
00090                vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd);
00091   int EvaluatePosition(float x[3], float* closestPoint,
00092                        int& subId, float pcoords[3],
00093                        float& dist2, float *weights);
00094   void EvaluateLocation(int& subId, float pcoords[3], float x[3],
00095                         float *weights);
00096   int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts);
00097   void Derivatives(int subId, float pcoords[3], float *values, 
00098                    int dim, float *derivs);
00100 
00102 
00104   void Clip(float value, vtkDataArray *cellScalars, 
00105             vtkPointLocator *locator, vtkCellArray *polys,
00106             vtkPointData *inPd, vtkPointData *outPd,
00107             vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd,
00108             int insideOut);
00110 
00112 
00114   int IntersectWithLine(float p1[3], float p2[3], float tol, float& t,
00115                         float x[3], float pcoords[3], int& subId);
00117 
00119   int GetParametricCenter(float pcoords[3]);
00120 
00122 
00123   static void TriangleCenter(float p1[3], float p2[3], float p3[3], 
00124                              float center[3]);
00126 
00128   static float TriangleArea(float p1[3], float p2[3], float 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                             float n[3]);
00170 
00172   static void ComputeNormal(float v1[3], float v2[3], float v3[3], float n[3]);
00173 
00175 
00177   static void ComputeNormalDirection(float v1[3], float v2[3], float v3[3],
00178                                      float n[3]);
00180   
00182 
00184   static void ComputeNormal(double v1[3], double v2[3], double v3[3], 
00185                             double n[3]);
00187   
00189 
00191   static void ComputeNormalDirection(double v1[3], double v2[3], double v3[3],
00192                                      double n[3]);
00194 
00196 
00201   static int PointInTriangle(float x[3], float x1[3], float x2[3], float x3[3], 
00202                              float tol2);
00204 
00206 
00209   static void ComputeQuadric(float x1[3], float x2[3], float x3[3],
00210                              float quadric[4][4]);
00211   static void ComputeQuadric(float x1[3], float x2[3], float x3[3],
00212                              vtkQuadric *quadric);
00214   
00215 
00216 protected:
00217   vtkTriangle();
00218   ~vtkTriangle();
00219 
00220   vtkLine *Line;
00221 
00222 private:
00223   vtkTriangle(const vtkTriangle&);  // Not implemented.
00224   void operator=(const vtkTriangle&);  // Not implemented.
00225 };
00226 
00227 inline int vtkTriangle::GetParametricCenter(float pcoords[3])
00228 {
00229   pcoords[0] = pcoords[1] = 0.333; pcoords[2] = 0.0;
00230   return 0;
00231 }
00232 
00233 inline void vtkTriangle::ComputeNormalDirection(float v1[3], float v2[3], 
00234                                        float v3[3], float n[3])
00235 {
00236   float ax, ay, az, bx, by, bz;
00237 
00238   // order is important!!! maintain consistency with triangle vertex order 
00239   ax = v3[0] - v2[0]; ay = v3[1] - v2[1]; az = v3[2] - v2[2];
00240   bx = v1[0] - v2[0]; by = v1[1] - v2[1]; bz = v1[2] - v2[2];
00241 
00242   n[0] = (ay * bz - az * by);
00243   n[1] = (az * bx - ax * bz);
00244   n[2] = (ax * by - ay * bx);
00245 }
00246 
00247 inline void vtkTriangle::ComputeNormal(float v1[3], float v2[3], 
00248                                        float v3[3], float n[3])
00249 {
00250   float length;
00251   
00252   vtkTriangle::ComputeNormalDirection(v1, v2, v3, n);
00253   
00254   if ( (length = sqrt((n[0]*n[0] + n[1]*n[1] + n[2]*n[2]))) != 0.0 )
00255     {
00256     n[0] /= length;
00257     n[1] /= length;
00258     n[2] /= length;
00259     }
00260 }
00261 
00262 inline void vtkTriangle::ComputeNormalDirection(double v1[3], double v2[3], 
00263                                        double v3[3], double n[3])
00264 {
00265   double ax, ay, az, bx, by, bz;
00266 
00267   // order is important!!! maintain consistency with triangle vertex order 
00268   ax = v3[0] - v2[0]; ay = v3[1] - v2[1]; az = v3[2] - v2[2];
00269   bx = v1[0] - v2[0]; by = v1[1] - v2[1]; bz = v1[2] - v2[2];
00270 
00271   n[0] = (ay * bz - az * by);
00272   n[1] = (az * bx - ax * bz);
00273   n[2] = (ax * by - ay * bx);
00274 }
00275 
00276 inline void vtkTriangle::ComputeNormal(double v1[3], double v2[3], 
00277                                        double v3[3], double n[3])
00278 {
00279   double length;
00280 
00281   vtkTriangle::ComputeNormalDirection(v1, v2, v3, n);
00282 
00283   if ( (length = sqrt((n[0]*n[0] + n[1]*n[1] + n[2]*n[2]))) != 0.0 )
00284     {
00285     n[0] /= length;
00286     n[1] /= length;
00287     n[2] /= length;
00288     }
00289 }
00290 
00291 inline void vtkTriangle::TriangleCenter(float p1[3], float p2[3], float p3[3],
00292                                        float center[3])
00293 {
00294   center[0] = (p1[0]+p2[0]+p3[0]) / 3.0;
00295   center[1] = (p1[1]+p2[1]+p3[1]) / 3.0;
00296   center[2] = (p1[2]+p2[2]+p3[2]) / 3.0;
00297 }
00298 
00299 inline float vtkTriangle::TriangleArea(float p1[3], float p2[3], float p3[3])
00300 {
00301   float a,b,c;
00302   a = vtkMath::Distance2BetweenPoints(p1,p2);
00303   b = vtkMath::Distance2BetweenPoints(p2,p3);
00304   c = vtkMath::Distance2BetweenPoints(p3,p1);
00305   return (0.25* sqrt(fabs((double)4.0*a*c - (a-b+c)*(a-b+c))));
00306 } 
00307 
00308 #endif
00309 
00310 

Generated on Thu Mar 28 14:19:17 2002 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001