VTK  9.7.1
vtkPolyhedron.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
128 #ifndef vtkPolyhedron_h
129 #define vtkPolyhedron_h
130 
131 #include "vtkCell3D.h"
132 #include "vtkCellStatus.h" // For enum.
133 #include "vtkCommonDataModelModule.h" // For export macro
134 #include "vtkDeprecation.h" // VTK_DEPRECATED_IN_9_6_0()
135 #include "vtkNew.h" // For vtkNew
136 
137 VTK_ABI_NAMESPACE_BEGIN
138 class vtkIdTypeArray;
139 class vtkCellArray;
140 class vtkTriangle;
141 class vtkQuad;
142 class vtkTetra;
143 class vtkPolygon;
144 class vtkLine;
145 class vtkEdgeTable;
146 class vtkPolyData;
147 class vtkCellLocator;
148 class vtkGenericCell;
150 class vtkUnstructuredGrid;
151 
152 class VTKCOMMONDATAMODEL_EXPORT vtkPolyhedron : public vtkCell3D
153 {
154 public:
155  using vtkPointIdMap = std::map<vtkIdType, vtkIdType>;
156 
159 
161 
164  static vtkPolyhedron* New();
165  vtkTypeMacro(vtkPolyhedron, vtkCell3D);
166  void PrintSelf(ostream& os, vtkIndent indent) override;
168 
170 
174  void GetEdgePoints(vtkIdType vtkNotUsed(edgeId), const vtkIdType*& vtkNotUsed(pts)) override
175  {
176  vtkWarningMacro(<< "vtkPolyhedron::GetEdgePoints Not Implemented");
177  }
178  vtkIdType GetFacePoints(vtkIdType faceId, const vtkIdType*& pts) override;
180  vtkIdType vtkNotUsed(edgeId), const vtkIdType*& vtkNotUsed(pts)) override
181  {
182  vtkWarningMacro(<< "vtkPolyhedron::GetEdgeToAdjacentFaces Not Implemented");
183  }
185  vtkIdType vtkNotUsed(faceId), const vtkIdType*& vtkNotUsed(faceIds)) override
186  {
187  vtkWarningMacro(<< "vtkPolyhedron::GetFaceToAdjacentFaces Not Implemented");
188  return 0;
189  }
191  vtkIdType vtkNotUsed(pointId), const vtkIdType*& vtkNotUsed(edgeIds)) override
192  {
193  vtkWarningMacro(<< "vtkPolyhedron::GetPointToIncidentEdges Not Implemented");
194  return 0;
195  }
196  vtkIdType GetPointToIncidentFaces(vtkIdType pointId, const vtkIdType*& faceIds) override;
198  vtkIdType vtkNotUsed(pointId), const vtkIdType*& vtkNotUsed(pts)) override
199  {
200  vtkWarningMacro(<< "vtkPolyhedron::GetPointToOneRingPoints Not Implemented");
201  return 0;
202  }
203  bool GetCentroid(double centroid[3]) const override;
204 
210  double ComputeVolume();
212 
216  int GetCellType() override { return VTK_POLYHEDRON; }
217 
221  int RequiresInitialization() override { return 1; }
222 
228  void Initialize() override;
229 
231 
235  int GetNumberOfEdges() override;
236  vtkCell* GetEdge(int) override;
237  int GetNumberOfFaces() override;
238  vtkCell* GetFace(int faceId) override;
240 
246  void Contour(double value, vtkDataArray* scalars, vtkIncrementalPointLocator* locator,
247  vtkCellArray* verts, vtkCellArray* lines, vtkCellArray* polys, vtkPointData* inPd,
248  vtkPointData* outPd, vtkCellData* inCd, vtkIdType cellId, vtkCellData* outCd) override;
249 
259  void Clip(double value, vtkDataArray* scalars, vtkIncrementalPointLocator* locator,
260  vtkCellArray* connectivity, vtkPointData* inPd, vtkPointData* outPd, vtkCellData* inCd,
261  vtkIdType cellId, vtkCellData* outCd, int insideOut) override;
262 
270  void ClipWithContext(double value, vtkDataArray* scalars, vtkIncrementalPointLocator* locator,
271  vtkCellArray* connectivity, vtkPointData* inPd, vtkPointData* outPd, vtkCellData* inCd,
272  vtkIdType cellId, vtkCellData* outCd, int insideOut, vtkCellArray* outFaces,
273  vtkCellArray* outFaceLocs);
274 
279  void ClipWithContext(double value, vtkDataArray* scalars, vtkIncrementalPointLocator* locator,
280  vtkCellArray* connectivity, vtkPointData* inPd, vtkPointData* outPd, vtkCellData* inCd,
281  vtkIdType cellId, vtkCellData* outCd, int insideOut, vtkUnstructuredGrid* outUG);
282 
290  int EvaluatePosition(const double x[3], double closestPoint[3], int& subId, double pcoords[3],
291  double& dist2, double weights[]) override;
292 
297  void EvaluateLocation(int& subId, const double pcoords[3], double x[3], double* weights) override;
298 
305  int IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t, double x[3],
306  double pcoords[3], int& subId) override;
307 
323  int TriangulateLocalIds(int index, vtkIdList* ptIds) override;
324 
331  int TriangulateFaces(vtkIdList* newFaces);
332 
339  int TriangulateFaces(vtkCellArray* newFaces);
340 
348  void Derivatives(
349  int subId, const double pcoords[3], const double* values, int dim, double* derivs) override;
350 
355  int CellBoundary(int subId, const double pcoords[3], vtkIdList* pts) override;
356 
361  int GetParametricCenter(double pcoords[3]) override;
362 
366  int IsPrimaryCell() VTK_FUTURE_CONST override { return 1; }
367 
369 
374  void InterpolateFunctions(const double x[3], double* sf) override;
375  void InterpolateDerivs(const double x[3], double* derivs) override;
377 
383  int RequiresExplicitFaceRepresentation() VTK_FUTURE_CONST override { return 1; }
384 
402  VTK_DEPRECATED_IN_9_6_0("This function is deprecated, use SetCellFaces")
403  void SetFaces(vtkIdType* faces);
404 
421  VTK_DEPRECATED_IN_9_6_0("This function is deprecated, use GetCellFaces")
422  vtkIdType* GetFaces();
423 
431  int SetCellFaces(vtkCellArray* faces);
432 
434 
440  vtkCellArray* GetCellFaces();
441  void GetCellFaces(vtkCellArray* faces);
443 
450  int IsInside(const double x[3], double tolerance);
451 
468  bool IsConvex();
469  Status IsConvex(double planarThreshold);
470 
474  vtkPolyData* GetPolyData();
475 
479  void ShallowCopy(vtkCell* c) override;
480 
484  void DeepCopy(vtkCell* c) override;
485 
486 protected:
487  vtkPolyhedron();
488  ~vtkPolyhedron() override;
489 
490  // Internal classes for supporting operations on this cell
492  vtkNew<vtkTriangle> Triangle;
494  vtkNew<vtkPolygon> Polygon;
495  vtkNew<vtkTetra> Tetra;
496 
497  // Filled with the SetFaces method.
498  // These faces are numbered in global id space
499  vtkNew<vtkCellArray> GlobalFaces;
500 
501  // VTK_DEPRECATED_IN_9_6_0()
502  // Backward compatibility
503  vtkNew<vtkIdTypeArray> LegacyGlobalFaces;
504 
505  // If edges are needed. Note that the edge numbering is in canonical space.
506  int EdgesGenerated = 0; // true/false
507  vtkNew<vtkEdgeTable> EdgeTable; // keep track of all edges
508  vtkNew<vtkIdTypeArray> Edges; // edge pairs kept in this list, in canonical id space
509  vtkNew<vtkIdTypeArray> EdgeFaces; // face pairs that comprise each edge, with the
510  // same ordering as EdgeTable
511  int GenerateEdges(); // method populates the edge table and edge array
512 
513  // Numerous methods needs faces to be numbered in the canonical space.
514  // This method uses PointIdMap to fill the Faces member (faces described
515  // with canonical IDs) from the GlobalFaces member (faces described with
516  // global IDs).
517  void GenerateFaces();
518  vtkNew<vtkCellArray> Faces; // These are numbered in canonical id space
519  int FacesGenerated = 0; // True when Faces have been successfully constructed
520 
521  // Bounds management
522  int BoundsComputed = 0;
523  void ComputeBounds();
524  void ComputeParametricCoordinate(const double x[3], double pc[3]);
525  void ComputePositionFromParametricCoordinate(const double pc[3], double x[3]);
526 
527  // Members for supporting geometric operations
528  int PolyDataConstructed = 0;
529  vtkNew<vtkPolyData> PolyData;
530  void ConstructPolyData();
531  int LocatorConstructed = 0;
532  vtkNew<vtkCellLocator> CellLocator;
533  void ConstructLocator();
534  vtkNew<vtkIdList> CellIds;
536 
537 private:
538  vtkPolyhedron(const vtkPolyhedron&) = delete;
539  void operator=(const vtkPolyhedron&) = delete;
540 
542  friend class vtkPolyhedronContour;
543 
544  // vtkCell has the data members Points (x,y,z coordinates) and PointIds (global cell ids).
545  // These data members are implicitly organized in canonical space, i.e., where the cell
546  // point ids are (0,1,...,npts-1).
547  // The PointIdMap is constructed during the call of the Initialize() method and maps global
548  // point ids to the canonical point ids.
549  vtkPointIdMap PointIdMap;
550 
551  void GeneratePointToIncidentFaces();
552 
553  // This variant of GenerateEdges() always regenerates edges but also populates
554  // \a unevenCoedges with a map from edge ID to the signed number of mismatched coedges.
555  int GenerateEdges(std::map<vtkIdType, int>& unevenCoedges);
556 
557  // Members used in GetPointToIncidentFaces
558  std::vector<std::vector<vtkIdType>> PointToIncidentFaces;
559 };
560 
561 VTK_ABI_NAMESPACE_END
562 #endif
virtual void InterpolateDerivs(const double pcoords[3], double *derivs)
Definition: vtkCell.h:407
void Contour(double value, vtkDataArray *cellScalars, vtkIncrementalPointLocator *locator, vtkCellArray *verts, vtkCellArray *lines, vtkCellArray *polys, vtkPointData *inPd, vtkPointData *outPd, vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd) override
Generate contouring primitives.
represent and manipulate point attribute data
Definition: vtkPointData.h:30
virtual int GetNumberOfFaces()=0
Return the number of faces in the cell.
Isosurface extraction using López polygon tracing algorithm.
int RequiresInitialization() override
This cell requires that it be initialized prior to access.
vtkIdType GetPointToIncidentEdges(vtkIdType pointId, const vtkIdType *&edgeIds) override
See vtkCell3D API for description of these methods.
represent and manipulate cell attribute data
Definition: vtkCellData.h:31
Abstract class in support of both point location and point insertion.
void GetEdgeToAdjacentFaces(vtkIdType edgeId, const vtkIdType *&pts) override
See vtkCell3D API for description of these methods.
a cell that represents a 2D quadrilateral
Definition: vtkQuad.h:27
std::map< vtkIdType, vtkIdType > vtkPointIdMap
dynamic, self-adjusting array of vtkIdType
virtual bool GetCentroid(double centroid[3]) const =0
Computes the centroid of the cell.
int vtkIdType
Definition: vtkType.h:363
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:71
provides thread-safe access to cells
abstract class to specify 3D cell interface
Definition: vtkCell3D.h:27
virtual int CellBoundary(int subId, const double pcoords[3], vtkIdList *pts)=0
Given parametric coordinates of a point, return the closest cell boundary, and whether the point is i...
keep track of edges (edge is pair of integer id's)
Definition: vtkEdgeTable.h:30
virtual vtkIdType GetFacePoints(vtkIdType faceId, const vtkIdType *&pts)=0
Get the list of vertices that define a face.
a 3D cell that represents a tetrahedron
Definition: vtkTetra.h:33
cell represents a 1D line
Definition: vtkLine.h:22
abstract class to specify cell behavior
Definition: vtkCell.h:50
virtual void EvaluateLocation(int &subId, const double pcoords[3], double x[3], double *weights)=0
Determine global coordinate (x[3]) from subId and parametric coordinates.
octree-based spatial search object to quickly locate cells
#define VTK_DEPRECATED_IN_9_6_0(reason)
int RequiresExplicitFaceRepresentation() VTK_FUTURE_CONST override
Satisfy the vtkCell API.
vtkIdType GetFaceToAdjacentFaces(vtkIdType faceId, const vtkIdType *&faceIds) override
See vtkCell3D API for description of these methods.
a simple class to control print indentation
Definition: vtkIndent.h:28
virtual int TriangulateLocalIds(int index, vtkIdList *ptIds)=0
Generate simplices of proper dimension.
list of point or cell ids
Definition: vtkIdList.h:25
dataset represents arbitrary combinations of all possible cell types
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
a cell that represents an n-sided polygon
Definition: vtkPolygon.h:39
virtual void InterpolateFunctions(const double pcoords[3], double *weight)
Compute the interpolation functions/derivatives (aka shape functions/derivatives) No-ops at this leve...
Definition: vtkCell.h:404
vtkCellStatus
Diagnostic values indicating how well-specified a cell is.
Definition: vtkCellStatus.h:16
vtkPolyhedron utilities
void GetEdgePoints(vtkIdType edgeId, const vtkIdType *&pts) override
See vtkCell3D API for description of these methods.
virtual vtkCell * GetFace(int faceId)=0
Return the face cell from the faceId of the cell.
virtual int GetNumberOfEdges()=0
Return the number of edges in the cell.
virtual int EvaluatePosition(const double x[3], double closestPoint[3], int &subId, double pcoords[3], double &dist2, double weights[])=0
Given a point x[3] return inside(=1), outside(=0) cell, or (-1) computational problem encountered; ev...
object to represent cell connectivity
Definition: vtkCellArray.h:177
virtual vtkCell * GetEdge(int edgeId)=0
Return the edge cell from the edgeId of the cell.
Allocate and hold a VTK object.
a cell that represents a triangle
Definition: vtkTriangle.h:27
virtual void Derivatives(int subId, const double pcoords[3], const double *values, int dim, double *derivs)=0
Compute derivatives given cell subId and parametric coordinates.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
A 3D cell defined by a set of polygonal faces.
virtual void Initialize()
Definition: vtkCell.h:105
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
int IsPrimaryCell() VTK_FUTURE_CONST override
A polyhedron is a full-fledged primary cell.
virtual int GetParametricCenter(double pcoords[3])
Return center of the cell in parametric coordinates.
virtual int IntersectWithLine(const double p1[3], const double p2[3], double tol, double &t, double x[3], double pcoords[3], int &subId)=0
Intersect with a ray.
virtual vtkIdType GetPointToIncidentFaces(vtkIdType pointId, const vtkIdType *&faceIds)=0
Get the ids of the incident faces point of id pointId.
void Clip(double value, vtkDataArray *cellScalars, vtkIncrementalPointLocator *locator, vtkCellArray *connectivity, vtkPointData *inPd, vtkPointData *outPd, vtkCellData *inCd, vtkIdType cellId, vtkCellData *outCd, int insideOut) override
Cut (or clip) the cell based on the input cellScalars and the specified value.
int GetCellType() override
See the vtkCell API for descriptions of these methods.
vtkIdType GetPointToOneRingPoints(vtkIdType pointId, const vtkIdType *&pts) override
See vtkCell3D API for description of these methods.