VTK
vtkPolyhedron.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkPolyhedron.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 =========================================================================*/
37 #ifndef __vtkPolyhedron_h
38 #define __vtkPolyhedron_h
39 
40 #include "vtkCommonDataModelModule.h" // For export macro
41 #include "vtkCell3D.h"
42 
43 class vtkIdTypeArray;
44 class vtkCellArray;
45 class vtkTriangle;
46 class vtkQuad;
47 class vtkTetra;
48 class vtkPolygon;
49 class vtkLine;
50 class vtkPointIdMap;
51 class vtkIdToIdVectorMapType;
52 class vtkIdToIdMapType;
53 class vtkEdgeTable;
54 class vtkPolyData;
55 class vtkCellLocator;
56 class vtkGenericCell;
57 class vtkPointLocator;
58 
59 class VTKCOMMONDATAMODEL_EXPORT vtkPolyhedron : public vtkCell3D
60 {
61 public:
63 
64  static vtkPolyhedron *New();
65  vtkTypeMacro(vtkPolyhedron,vtkCell3D);
66  void PrintSelf(ostream& os, vtkIndent indent);
68 
70 
71  virtual void GetEdgePoints(int vtkNotUsed(edgeId), int* &vtkNotUsed(pts)) {}
72  virtual void GetFacePoints(int vtkNotUsed(faceId), int* &vtkNotUsed(pts)) {}
73  virtual double *GetParametricCoords();
75 
77  virtual int GetCellType() {return VTK_POLYHEDRON;}
78 
80 
81  virtual int RequiresInitialization() {return 1;}
82  virtual void Initialize();
84 
86 
88  virtual int GetNumberOfEdges();
89  virtual vtkCell *GetEdge(int);
90  virtual int GetNumberOfFaces();
91  virtual vtkCell *GetFace(int faceId);
93 
95 
99  virtual void Contour(double value, vtkDataArray *scalars,
100  vtkIncrementalPointLocator *locator, vtkCellArray *verts,
101  vtkCellArray *lines, vtkCellArray *polys,
102  vtkPointData *inPd, vtkPointData *outPd,
103  vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd);
105 
107 
115  virtual void Clip(double value, vtkDataArray *scalars,
116  vtkIncrementalPointLocator *locator, vtkCellArray *connectivity,
117  vtkPointData *inPd, vtkPointData *outPd,
118  vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd,
119  int insideOut);
121 
123 
129  virtual int EvaluatePosition(double x[3], double* closestPoint,
130  int& subId, double pcoords[3],
131  double& dist2, double *weights);
133 
135 
137  virtual void EvaluateLocation(int& subId, double pcoords[3], double x[3],
138  double *weights);
140 
142 
146  virtual int IntersectWithLine(double p1[3], double p2[3], double tol, double& t,
147  double x[3], double pcoords[3], int& subId);
149 
163  virtual int Triangulate(int index, vtkIdList *ptIds, vtkPoints *pts);
164 
166 
171  virtual void Derivatives(int subId, double pcoords[3], double *values,
172  int dim, double *derivs);
174 
177  virtual int CellBoundary(int subId, double pcoords[3], vtkIdList *pts);
178 
181  virtual int GetParametricCenter(double pcoords[3]);
182 
184  int IsPrimaryCell() {return 1;}
185 
187 
190  virtual void InterpolateFunctions(double x[3], double *sf);
191  virtual void InterpolateDerivs(double x[3], double *derivs);
193 
195 
201  virtual int RequiresExplicitFaceRepresentation() {return 1;}
202  virtual void SetFaces(vtkIdType *faces);
203  virtual vtkIdType *GetFaces();
205 
206  // Descriprion:
207  // A method particular to vtkPolyhedron. It determines whether a point x[3]
208  // is inside the polyhedron or not (returns 1 is the point is inside, 0
209  // otherwise). The tolerance is expressed in normalized space; i.e., a
210  // fraction of the size of the bounding box.
211  int IsInside(double x[3], double tolerance);
212 
214  vtkPolyData* GetPolyData();
215 
216 protected:
217  vtkPolyhedron();
218  ~vtkPolyhedron();
219 
220  // Internal classes for supporting operations on this cell
226  vtkIdTypeArray *GlobalFaces; //these are numbered in gloabl id space
228 
229  // vtkCell has the data members Points (x,y,z coordinates) and PointIds
230  // (global cell ids corresponding to cell canonical numbering (0,1,2,....)).
231  // These data members are implicitly organized in canonical space, i.e., where
232  // the cell point ids are (0,1,...,npts-1). The PointIdMap maps global point id
233  // back to these canonoical point ids.
234  vtkPointIdMap *PointIdMap;
235 
236  // If edges are needed. Note that the edge numbering is in
237  // canonical space.
238  int EdgesGenerated; //true/false
239  vtkEdgeTable *EdgeTable; //keep track of all edges
240  vtkIdTypeArray *Edges; //edge pairs kept in this list, in canonical id space
241  int GenerateEdges(); //method populates the edge table and edge array
242 
243  // If faces need renumbering into canonical numbering space these members
244  // are used. When initiallly loaded, the face numbering uses global dataset
245  // ids. Once renumbered, they are converted to canonical space.
246  vtkIdTypeArray *Faces; //these are numbered in canonical id space
248  void GenerateFaces();
249 
250  // Bounds management
252  void ComputeBounds();
253  void ComputeParametricCoordinate(double x[3], double pc[3]);
254  void ComputePositionFromParametricCoordinate(double pc[3], double x[3]);
255 
256  // Members for supporting geometric operations
261  void ConstructPolyData();
264  void ConstructLocator();
267 
268  // This is the internal implementation of contouring a polyhedron. It is used
269  // by both Clip and Contour functions.
270  int InternalContour(double value,
271  int insideOut,
273  vtkDataArray *inScalars,
274  vtkDataArray *outScalars,
275  vtkPointData *inPd,
276  vtkPointData *outPd,
277  vtkCellArray *contourPolys,
278  vtkIdToIdVectorMapType & faceToPointsMap,
279  vtkIdToIdVectorMapType & pointToFacesMap,
280  vtkIdToIdMapType & pointIdMap);
281 
282 
283  // Check if the polyhedron cell intersect with the contour/clip function.
284  // If intersect, return 0. Otherwise return 1 or -1 when the polyhedron cell
285  // is on the positive or negative side of contour/clip function respectively.
286  int IntersectWithContour(double value,
287  int insideOut,
288  vtkDataArray *inScalars);
289 
290 private:
291  vtkPolyhedron(const vtkPolyhedron&); // Not implemented.
292  void operator=(const vtkPolyhedron&); // Not implemented.
293 
294  //BTX
295  class vtkInternal;
296  vtkInternal * Internal;
297  //ETX
298 };
299 
300 //----------------------------------------------------------------------------
301 inline int vtkPolyhedron::GetParametricCenter(double pcoords[3])
302 {
303  pcoords[0] = pcoords[1] = pcoords[2] = 0.5;
304  return 0;
305 }
306 
307 #endif