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 "vtkCommonDataModelModule.h" // For export macro
32 #include "vtkCell.h"
33 
34 #include "vtkMath.h" // Needed for inline methods
35 
36 class vtkLine;
37 class vtkQuadric;
39 
41 {
42 public:
43  static vtkTriangle *New();
44  vtkTypeMacro(vtkTriangle,vtkCell);
45  void PrintSelf(ostream& os, vtkIndent indent);
46 
49  vtkCell *GetEdge(int edgeId);
50 
52 
53  int GetCellType() {return VTK_TRIANGLE;};
54  int GetCellDimension() {return 2;};
55  int GetNumberOfEdges() {return 3;};
56  int GetNumberOfFaces() {return 0;};
57  vtkCell *GetFace(int) {return 0;};
58  int CellBoundary(int subId, double pcoords[3], vtkIdList *pts);
59  void Contour(double value, vtkDataArray *cellScalars,
61  vtkCellArray *lines, vtkCellArray *polys,
62  vtkPointData *inPd, vtkPointData *outPd,
63  vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd);
64  int EvaluatePosition(double x[3], double* closestPoint,
65  int& subId, double pcoords[3],
66  double& dist2, double *weights);
67  void EvaluateLocation(int& subId, double pcoords[3], double x[3],
68  double *weights);
69  int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts);
70  void Derivatives(int subId, double pcoords[3], double *values,
71  int dim, double *derivs);
72  virtual double *GetParametricCoords();
74 
76  double ComputeArea();
77 
79 
81  void Clip(double value, vtkDataArray *cellScalars,
83  vtkPointData *inPd, vtkPointData *outPd,
84  vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd,
85  int insideOut);
87 
90  static void InterpolationFunctions(double pcoords[3], double sf[3]);
92  static void InterpolationDerivs(double pcoords[3], double derivs[6]);
94 
96  virtual void InterpolateFunctions(double pcoords[3], double sf[3])
97  {
99  }
100  virtual void InterpolateDerivs(double pcoords[3], double derivs[6])
101  {
102  vtkTriangle::InterpolationDerivs(pcoords,derivs);
103  }
105 
107  int *GetEdgeArray(int edgeId);
108 
110 
112  int IntersectWithLine(double p1[3], double p2[3], double tol, double& t,
113  double x[3], double pcoords[3], int& subId);
115 
117  int GetParametricCenter(double pcoords[3]);
118 
121  double GetParametricDistance(double pcoords[3]);
122 
124 
125  static void TriangleCenter(double p1[3], double p2[3], double p3[3],
126  double center[3]);
128 
131  static double TriangleArea(double p1[3], double p2[3], double p3[3]);
132 
134 
138  static double Circumcircle(double p1[2], double p2[2], double p3[2],
139  double center[2]);
141 
143 
154  static int BarycentricCoords(double x[2], double x1[2], double x2[2],
155  double x3[2], double bcoords[3]);
157 
158 
160 
163  static int ProjectTo2D(double x1[3], double x2[3], double x3[3],
164  double v1[2], double v2[2], double v3[2]);
166 
168 
170  static void ComputeNormal(vtkPoints *p, int numPts, vtkIdType *pts,
171  double n[3]);
173 
175  static void ComputeNormal(double v1[3], double v2[3], double v3[3], double n[3]);
176 
178 
180  static void ComputeNormalDirection(double v1[3], double v2[3], double v3[3],
181  double n[3]);
183 
185 
190  static int PointInTriangle(double x[3], double x1[3],
191  double x2[3], double x3[3],
192  double tol2);
194 
196 
199  static void ComputeQuadric(double x1[3], double x2[3], double x3[3],
200  double quadric[4][4]);
201  static void ComputeQuadric(double x1[3], double x2[3], double x3[3],
202  vtkQuadric *quadric);
204 
205 
206 protected:
207  vtkTriangle();
208  ~vtkTriangle();
209 
211 
212 private:
213  vtkTriangle(const vtkTriangle&); // Not implemented.
214  void operator=(const vtkTriangle&); // Not implemented.
215 };
216 
217 //----------------------------------------------------------------------------
218 inline int vtkTriangle::GetParametricCenter(double pcoords[3])
219 {
220  pcoords[0] = pcoords[1] = 1./3; pcoords[2] = 0.0;
221  return 0;
222 }
223 
224 //----------------------------------------------------------------------------
225 inline void vtkTriangle::ComputeNormalDirection(double v1[3], double v2[3],
226  double v3[3], double n[3])
227 {
228  double ax, ay, az, bx, by, bz;
229 
230  // order is important!!! maintain consistency with triangle vertex order
231  ax = v3[0] - v2[0]; ay = v3[1] - v2[1]; az = v3[2] - v2[2];
232  bx = v1[0] - v2[0]; by = v1[1] - v2[1]; bz = v1[2] - v2[2];
233 
234  n[0] = (ay * bz - az * by);
235  n[1] = (az * bx - ax * bz);
236  n[2] = (ax * by - ay * bx);
237 }
238 
239 //----------------------------------------------------------------------------
240 inline void vtkTriangle::ComputeNormal(double v1[3], double v2[3],
241  double v3[3], double n[3])
242 {
243  double length;
244 
246 
247  if ( (length = sqrt((n[0]*n[0] + n[1]*n[1] + n[2]*n[2]))) != 0.0 )
248  {
249  n[0] /= length;
250  n[1] /= length;
251  n[2] /= length;
252  }
253 }
254 
255 //----------------------------------------------------------------------------
256 inline void vtkTriangle::TriangleCenter(double p1[3], double p2[3],
257  double p3[3], double center[3])
258 {
259  center[0] = (p1[0]+p2[0]+p3[0]) / 3.0;
260  center[1] = (p1[1]+p2[1]+p3[1]) / 3.0;
261  center[2] = (p1[2]+p2[2]+p3[2]) / 3.0;
262 }
263 
264 //----------------------------------------------------------------------------
265 inline double vtkTriangle::TriangleArea(double p1[3], double p2[3], double p3[3])
266 {
267  double n[3];
269 
270  return 0.5*vtkMath::Norm(n);
271 }
272 
273 #endif
274 
275 
static void InterpolationDerivs(double pcoords[3], double derivs[6])
represent and manipulate point attribute data
Definition: vtkPointData.h:36
void PrintSelf(ostream &os, vtkIndent indent)
virtual double * GetParametricCoords()
virtual void InterpolateDerivs(double pcoords[3], double derivs[6])
Definition: vtkTriangle.h:100
represent and manipulate cell attribute data
Definition: vtkCellData.h:37
virtual void InterpolateFunctions(double pcoords[3], double sf[3])
Definition: vtkTriangle.h:96
Abstract class in support of both point location and point insertion.
virtual int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts)=0
virtual void EvaluateLocation(int &subId, double pcoords[3], double x[3], double *weights)=0
virtual int EvaluatePosition(double x[3], double *closestPoint, int &subId, double pcoords[3], double &dist2, double *weights)=0
static void ComputeNormalDirection(double v1[3], double v2[3], double v3[3], double n[3])
Definition: vtkTriangle.h:225
int vtkIdType
Definition: vtkType.h:247
int GetNumberOfEdges()
Definition: vtkTriangle.h:55
static void ComputeNormal(vtkPoints *p, int numPts, vtkIdType *pts, double n[3])
int GetCellDimension()
Definition: vtkTriangle.h:54
vtkCell * GetFace(int)
Definition: vtkTriangle.h:57
cell represents a 1D line
Definition: vtkLine.h:34
abstract class to specify cell behavior
Definition: vtkCell.h:58
virtual double GetParametricDistance(double pcoords[3])
static void InterpolationFunctions(double pcoords[3], double sf[3])
a simple class to control print indentation
Definition: vtkIndent.h:38
evaluate implicit quadric function
Definition: vtkQuadric.h:35
int GetNumberOfFaces()
Definition: vtkTriangle.h:56
list of point or cell ids
Definition: vtkIdList.h:35
virtual void Derivatives(int subId, double pcoords[3], double *values, int dim, double *derivs)=0
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
virtual int IntersectWithLine(double p1[3], double p2[3], double tol, double &t, double x[3], double pcoords[3], int &subId)=0
virtual void Clip(double value, vtkDataArray *cellScalars, vtkIncrementalPointLocator *locator, vtkCellArray *connectivity, vtkPointData *inPd, vtkPointData *outPd, vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd, int insideOut)=0
static void TriangleCenter(double p1[3], double p2[3], double p3[3], double center[3])
Definition: vtkTriangle.h:256
int GetCellType()
Definition: vtkTriangle.h:53
object to represent cell connectivity
Definition: vtkCellArray.h:49
virtual vtkCell * GetEdge(int edgeId)=0
a cell that represents a triangle
Definition: vtkTriangle.h:40
int GetParametricCenter(double pcoords[3])
Definition: vtkTriangle.h:218
virtual void Contour(double value, vtkDataArray *cellScalars, vtkIncrementalPointLocator *locator, vtkCellArray *verts, vtkCellArray *lines, vtkCellArray *polys, vtkPointData *inPd, vtkPointData *outPd, vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd)=0
vtkLine * Line
Definition: vtkTriangle.h:210
virtual int CellBoundary(int subId, double pcoords[3], vtkIdList *pts)=0
static vtkObject * New()
static float Norm(const float *x, int n)
virtual int GetParametricCenter(double pcoords[3])
#define VTKCOMMONDATAMODEL_EXPORT
represent and manipulate 3D points
Definition: vtkPoints.h:38
static double TriangleArea(double p1[3], double p2[3], double p3[3])
Definition: vtkTriangle.h:265