VTK
vtkTriangle.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkTriangle.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
28 #ifndef __vtkTriangle_h
29 #define __vtkTriangle_h
30 
31 #include "vtkCell.h"
32 
33 #include "vtkMath.h" // Needed for inline methods
34 
35 class vtkLine;
36 class vtkQuadric;
37 class vtkIncrementalPointLocator;
38 
39 class VTK_FILTERING_EXPORT vtkTriangle : public vtkCell
40 {
41 public:
42  static vtkTriangle *New();
43  vtkTypeMacro(vtkTriangle,vtkCell);
44  void PrintSelf(ostream& os, vtkIndent indent);
45 
48  vtkCell *GetEdge(int edgeId);
49 
51 
52  int GetCellType() {return VTK_TRIANGLE;};
53  int GetCellDimension() {return 2;};
54  int GetNumberOfEdges() {return 3;};
55  int GetNumberOfFaces() {return 0;};
56  vtkCell *GetFace(int) {return 0;};
57  int CellBoundary(int subId, double pcoords[3], vtkIdList *pts);
58  void Contour(double value, vtkDataArray *cellScalars,
59  vtkIncrementalPointLocator *locator, vtkCellArray *verts,
60  vtkCellArray *lines, vtkCellArray *polys,
61  vtkPointData *inPd, vtkPointData *outPd,
62  vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd);
63  int EvaluatePosition(double x[3], double* closestPoint,
64  int& subId, double pcoords[3],
65  double& dist2, double *weights);
66  void EvaluateLocation(int& subId, double pcoords[3], double x[3],
67  double *weights);
68  int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts);
69  void Derivatives(int subId, double pcoords[3], double *values,
70  int dim, double *derivs);
71  virtual double *GetParametricCoords();
73 
75  double ComputeArea();
76 
78 
80  void Clip(double value, vtkDataArray *cellScalars,
81  vtkIncrementalPointLocator *locator, vtkCellArray *polys,
82  vtkPointData *inPd, vtkPointData *outPd,
83  vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd,
84  int insideOut);
86 
88 
90  static void InterpolationFunctions(double pcoords[3], double sf[3]);
91  // Description:
92  // @deprecated Replaced by vtkTriangle::InterpolateDerivs as of VTK 5.2
93  static void InterpolationDerivs(double pcoords[3], double derivs[6]);
94  // Description:
95  // Compute the interpolation functions/derivatives
96  // (aka shape functions/derivatives)
97  virtual void InterpolateFunctions(double pcoords[3], double sf[3])
98  {
100  }
101  virtual void InterpolateDerivs(double pcoords[3], double derivs[6])
102  {
103  vtkTriangle::InterpolationDerivs(pcoords,derivs);
104  }
105  // Description:
106  // Return the ids of the vertices defining edge (`edgeId`).
107  // Ids are related to the cell, not to the dataset.
108  int *GetEdgeArray(int edgeId);
110 
112 
114  int IntersectWithLine(double p1[3], double p2[3], double tol, double& t,
115  double x[3], double pcoords[3], int& subId);
117 
119  int GetParametricCenter(double pcoords[3]);
120 
123  double GetParametricDistance(double pcoords[3]);
124 
126 
127  static void TriangleCenter(double p1[3], double p2[3], double p3[3],
128  double center[3]);
130 
133  static double TriangleArea(double p1[3], double p2[3], double p3[3]);
134 
136 
140  static double Circumcircle(double p1[2], double p2[2], double p3[2],
141  double center[2]);
143 
145 
156  static int BarycentricCoords(double x[2], double x1[2], double x2[2],
157  double x3[2], double bcoords[3]);
159 
160 
162 
165  static int ProjectTo2D(double x1[3], double x2[3], double x3[3],
166  double v1[2], double v2[2], double v3[2]);
168 
170 
172  static void ComputeNormal(vtkPoints *p, int numPts, vtkIdType *pts,
173  double n[3]);
175 
177  static void ComputeNormal(double v1[3], double v2[3], double v3[3], double n[3]);
178 
180 
182  static void ComputeNormalDirection(double v1[3], double v2[3], double v3[3],
183  double n[3]);
185 
187 
192  static int PointInTriangle(double x[3], double x1[3],
193  double x2[3], double x3[3],
194  double tol2);
196 
198 
201  static void ComputeQuadric(double x1[3], double x2[3], double x3[3],
202  double quadric[4][4]);
203  static void ComputeQuadric(double x1[3], double x2[3], double x3[3],
204  vtkQuadric *quadric);
206 
207 
208 protected:
209  vtkTriangle();
210  ~vtkTriangle();
211 
213 
214 private:
215  vtkTriangle(const vtkTriangle&); // Not implemented.
216  void operator=(const vtkTriangle&); // Not implemented.
217 };
218 
219 //----------------------------------------------------------------------------
220 inline int vtkTriangle::GetParametricCenter(double pcoords[3])
221 {
222  pcoords[0] = pcoords[1] = 1./3; pcoords[2] = 0.0;
223  return 0;
224 }
225 
226 //----------------------------------------------------------------------------
227 inline void vtkTriangle::ComputeNormalDirection(double v1[3], double v2[3],
228  double v3[3], double n[3])
229 {
230  double ax, ay, az, bx, by, bz;
231 
232  // order is important!!! maintain consistency with triangle vertex order
233  ax = v3[0] - v2[0]; ay = v3[1] - v2[1]; az = v3[2] - v2[2];
234  bx = v1[0] - v2[0]; by = v1[1] - v2[1]; bz = v1[2] - v2[2];
235 
236  n[0] = (ay * bz - az * by);
237  n[1] = (az * bx - ax * bz);
238  n[2] = (ax * by - ay * bx);
239 }
240 
241 //----------------------------------------------------------------------------
242 inline void vtkTriangle::ComputeNormal(double v1[3], double v2[3],
243  double v3[3], double n[3])
244 {
245  double length;
246 
248 
249  if ( (length = sqrt((n[0]*n[0] + n[1]*n[1] + n[2]*n[2]))) != 0.0 )
250  {
251  n[0] /= length;
252  n[1] /= length;
253  n[2] /= length;
254  }
255 }
256 
257 //----------------------------------------------------------------------------
258 inline void vtkTriangle::TriangleCenter(double p1[3], double p2[3],
259  double p3[3], double center[3])
260 {
261  center[0] = (p1[0]+p2[0]+p3[0]) / 3.0;
262  center[1] = (p1[1]+p2[1]+p3[1]) / 3.0;
263  center[2] = (p1[2]+p2[2]+p3[2]) / 3.0;
264 }
265 
266 //----------------------------------------------------------------------------
267 inline double vtkTriangle::TriangleArea(double p1[3], double p2[3], double p3[3])
268 {
269  double a,b,c;
273  return (0.25* sqrt(fabs(4.0*a*c - (a-b+c)*(a-b+c))));
274 }
275 
276 #endif
277 
278 
static void InterpolationDerivs(double pcoords[3], double derivs[6])
represent and manipulate point attribute data
Definition: vtkPointData.h:35
#define VTK_FILTERING_EXPORT
virtual void InterpolateDerivs(double pcoords[3], double derivs[6])
Definition: vtkTriangle.h:101
virtual void InterpolateFunctions(double pcoords[3], double sf[3])
Definition: vtkTriangle.h:97
static void ComputeNormalDirection(double v1[3], double v2[3], double v3[3], double n[3])
Definition: vtkTriangle.h:227
int vtkIdType
Definition: vtkType.h:255
int GetNumberOfEdges()
Definition: vtkTriangle.h:54
static void ComputeNormal(vtkPoints *p, int numPts, vtkIdType *pts, double n[3])
int GetCellDimension()
Definition: vtkTriangle.h:53
vtkCell * GetFace(int)
Definition: vtkTriangle.h:56
cell represents a 1D line
Definition: vtkLine.h:33
static void InterpolationFunctions(double pcoords[3], double sf[3])
a simple class to control print indentation
Definition: vtkIndent.h:37
evaluate implicit quadric function
Definition: vtkQuadric.h:34
int GetNumberOfFaces()
Definition: vtkTriangle.h:55
list of point or cell ids
Definition: vtkIdList.h:34
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:53
static void TriangleCenter(double p1[3], double p2[3], double p3[3], double center[3])
Definition: vtkTriangle.h:258
int GetCellType()
Definition: vtkTriangle.h:52
object to represent cell connectivity
Definition: vtkCellArray.h:48
a cell that represents a triangle
Definition: vtkTriangle.h:39
int GetParametricCenter(double pcoords[3])
Definition: vtkTriangle.h:220
vtkLine * Line
Definition: vtkTriangle.h:212
static float Distance2BetweenPoints(const float x[3], const float y[3])
Definition: vtkMath.h:1116
represent and manipulate 3D points
Definition: vtkPoints.h:38
static double TriangleArea(double p1[3], double p2[3], double p3[3])
Definition: vtkTriangle.h:267