VTK  9.3.20240328
vtkUnstructuredGrid.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
131 #ifndef vtkUnstructuredGrid_h
132 #define vtkUnstructuredGrid_h
133 
134 #include "vtkAbstractCellLinks.h" // For vtkAbstractCellLinks
135 #include "vtkCellArray.h" // inline GetCellPoints()
136 #include "vtkCommonDataModelModule.h" // For export macro
137 #include "vtkIdTypeArray.h" // inline GetCellPoints()
138 #include "vtkUnstructuredGridBase.h"
139 
140 #include "vtkSmartPointer.h" // for smart pointer
141 
142 VTK_ABI_NAMESPACE_BEGIN
143 class vtkCellArray;
144 class vtkIdList;
145 class vtkIdTypeArray;
147 class vtkIdTypeArray;
148 
149 class VTKCOMMONDATAMODEL_EXPORT vtkUnstructuredGrid : public vtkUnstructuredGridBase
150 {
151 public:
157 
159 
163  void PrintSelf(ostream& os, vtkIndent indent) override;
165 
169  int GetDataObjectType() override { return VTK_UNSTRUCTURED_GRID; }
170 
180  bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
181  {
182  return this->AllocateExact(numCells, numCells * maxCellSize);
183  }
184 
194  bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize);
195 
205  void Allocate(vtkIdType numCells = 1000, int vtkNotUsed(extSize) = 1000) override
206  {
207  this->AllocateExact(numCells, numCells);
208  }
209 
211 
214  void Reset();
215  void CopyStructure(vtkDataSet* ds) override;
217  using vtkDataSet::GetCell;
218  vtkCell* GetCell(vtkIdType cellId) override;
219  void GetCell(vtkIdType cellId, vtkGenericCell* cell) override;
220  void GetCellBounds(vtkIdType cellId, double bounds[6]) override;
221  void GetCellPoints(vtkIdType cellId, vtkIdList* ptIds) override;
222  void GetPointCells(vtkIdType ptId, vtkIdList* cellIds) override;
225 
229  int GetCellType(vtkIdType cellId) override;
230 
234  vtkIdType GetCellSize(vtkIdType cellId) override;
235 
247  void GetCellTypes(vtkCellTypes* types) override;
248 
262 
275  void GetCellPoints(vtkIdType cellId, vtkIdType& npts, vtkIdType const*& pts)
276  {
277  this->Connectivity->GetCellAtId(cellId, npts, pts);
278  }
279 
296  vtkIdType cellId, vtkIdType& npts, vtkIdType const*& pts, vtkIdList* ptIds) override
297  {
298  this->Connectivity->GetCellAtId(cellId, npts, pts, ptIds);
299  }
300 
302 
307  void GetPointCells(vtkIdType ptId, vtkIdType& ncells, vtkIdType*& cells)
308  VTK_SIZEHINT(cells, ncells);
310 
318 
322  void Squeeze() override;
323 
327  void Initialize() override;
328 
332  int GetMaxCellSize() override;
333 
338  int GetMaxSpatialDimension() override;
339 
344  void BuildLinks();
345 
347 
353 
361  VTK_DEPRECATED_IN_9_3_0("Use GetLinks() instead.")
362  vtkAbstractCellLinks* GetCellLinks();
363 
371  void GetFaceStream(vtkIdType cellId, vtkIdList* ptIds);
372 
382  VTK_DEPRECATED_IN_9_4_0("Use the threadsafe GetFaceStream or GetPolyhedronFaces.")
383  void GetFaceStream(vtkIdType cellId, vtkIdType& nfaces, vtkIdType const*& ptIds);
384 
386 
396  void SetCells(int type, vtkCellArray* cells);
397  void SetCells(int* types, vtkCellArray* cells);
398  void SetCells(vtkUnsignedCharArray* cellTypes, vtkCellArray* cells);
400  vtkCellArray* faceLocations, vtkCellArray* faces);
401  VTK_DEPRECATED_IN_9_4_0("This function is deprecated, use SetPolyhedralCells")
402  void SetCells(vtkUnsignedCharArray* cellTypes, vtkCellArray* cells, vtkIdTypeArray* faceLocations,
403  vtkIdTypeArray* faces);
405 
409  vtkCellArray* GetCells() { return this->Connectivity; }
410 
412 
418  void GetCellNeighbors(vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds) override
419  {
420  this->GetCellNeighbors(cellId, ptIds->GetNumberOfIds(), ptIds->GetPointer(0), cellIds);
421  }
423  vtkIdType cellId, vtkIdType npts, const vtkIdType* ptIds, vtkIdList* cellIds);
425 
427 
438  vtkIdType cellId, vtkIdType npts, const vtkIdType* ptIds, vtkIdType& neighborCellId);
439  bool IsCellBoundary(vtkIdType cellId, vtkIdType npts, const vtkIdType* ptIds)
440  {
441  vtkIdType neighborCellId;
442  return this->IsCellBoundary(cellId, npts, ptIds, neighborCellId);
443  }
444  VTK_DEPRECATED_IN_9_3_0("Use the overload that doesn't take a vtkIdList instead.")
445  bool IsCellBoundary(
446  vtkIdType cellId, vtkIdType npts, const vtkIdType* ptIds, vtkIdList* vtkNotUsed(cellIds))
447  {
448  return this->IsCellBoundary(cellId, npts, ptIds);
449  }
451 
453 
457  vtkIdType InsertNextLinkedCell(int type, int npts, const vtkIdType pts[]) VTK_SIZEHINT(pts, npts);
460  void ResizeCellList(vtkIdType ptId, int size);
462 
464 
467  virtual int GetPiece();
468  virtual int GetNumberOfPieces();
470 
474  virtual int GetGhostLevel();
475 
484  unsigned long GetActualMemorySize() override;
485 
487 
490  void ShallowCopy(vtkDataObject* src) override;
491  void DeepCopy(vtkDataObject* src) override;
493 
499  void GetIdsOfCellsOfType(int type, vtkIdTypeArray* array) override;
500 
504  int IsHomogeneous() override;
505 
512 
514 
520 
524  VTK_DEPRECATED_IN_9_4_0("Use GetPolyhedronFaces instead.")
525  vtkIdType* GetFaces(vtkIdType cellId);
526 
530  void GetPolyhedronFaces(vtkIdType cellId, vtkCellArray* faces);
531 
533 
537  VTK_DEPRECATED_IN_9_4_0("Use GetPolyhedronFaces instead.")
538  vtkIdTypeArray* GetFaces();
539  VTK_DEPRECATED_IN_9_4_0("Use GetPolyhedronFaceLocations instead.")
540  vtkIdTypeArray* GetFaceLocations();
545  vtkCellArray* GetPolyhedronFaces();
546  vtkCellArray* GetPolyhedronFaceLocations();
548 
556  int InitializeFacesRepresentation(vtkIdType numPrevCells);
557 
565  virtual vtkMTimeType GetMeshMTime();
566 
579  static void DecomposeAPolyhedronCell(vtkCellArray* polyhedronCellArray, vtkIdType& nCellpts,
580  vtkIdType& nCellfaces, vtkCellArray* cellArray, vtkIdTypeArray* faces);
581 
582  static void DecomposeAPolyhedronCell(const vtkIdType* polyhedronCellStream, vtkIdType& nCellpts,
583  vtkIdType& nCellfaces, vtkCellArray* cellArray, vtkIdTypeArray* faces);
584 
597  static void DecomposeAPolyhedronCell(vtkIdType nCellFaces, const vtkIdType* inFaceStream,
598  vtkIdType& nCellpts, vtkCellArray* cellArray, vtkIdTypeArray* faces);
599 
606  static void ConvertFaceStreamPointIds(vtkIdList* faceStream, vtkIdType* idMap);
607 
613  static void ConvertFaceStreamPointIds(vtkIdType nfaces, vtkIdType* faceStream, vtkIdType* idMap);
614 
620  static void ConvertFaceStreamPointIds(vtkCellArray* faces, vtkIdType* idMap);
621 
622  //====================== Begin Legacy Methods ================================
623 
631  vtkIdTypeArray* GetCellLocationsArray();
632 
634 
650  void SetCells(
651  vtkUnsignedCharArray* cellTypes, vtkIdTypeArray* cellLocations, vtkCellArray* cells);
652  void SetCells(vtkUnsignedCharArray* cellTypes, vtkIdTypeArray* cellLocations, vtkCellArray* cells,
653  vtkIdTypeArray* faceLocations, vtkIdTypeArray* faces);
655 
656  //====================== End Legacy Methods ==================================
657 
658 protected:
660  ~vtkUnstructuredGrid() override;
661 
662  void ReportReferences(vtkGarbageCollector*) override;
663 
664  // Points derived from vtkPointSet.
665  // Attribute data (i.e., point and cell data (i.e., scalars, vectors, normals, tcoords)
666  // derived from vtkDataSet.
667 
668  // The heart of the data representation. The points are managed by the
669  // superclass vtkPointSet. A cell is defined by its connectivity (i.e., the
670  // point ids that define the cell) and the cell type, represented by the
671  // Connectivity and Types arrays.
672  // Finally, when certain topological information is needed (e.g.,
673  // all the cells that use a point), the cell links array is built.
677 
678  // Set of all cell types present in the grid. All entries are unique.
679  vtkSmartPointer<vtkCellTypes> DistinctCellTypes;
680 
681  // The DistinctCellTypes is cached, so we keep track of the last time it was
682  // updated so we can compare it to the modified time of the Types array.
683  vtkMTimeType DistinctCellTypesUpdateMTime;
684 
693 
694  // Legacy support -- stores the old-style cell array locations.
696 
697  vtkIdType InternalInsertNextCell(int type, vtkIdType npts, const vtkIdType ptIds[]) override;
698  vtkIdType InternalInsertNextCell(int type, vtkIdList* ptIds) override;
699  vtkIdType InternalInsertNextCell(
700  int type, vtkIdType npts, const vtkIdType ptIds[], vtkIdType nfaces, const vtkIdType faces[]);
701  vtkIdType InternalInsertNextCell(
702  int type, vtkIdType npts, const vtkIdType pts[], vtkCellArray* faces) override;
703  void InternalReplaceCell(vtkIdType cellId, int npts, const vtkIdType pts[]) override;
704 
718  vtkSmartPointer<vtkIdTypeArray> LegacyFaceLocations;
719 
724  VTK_DEPRECATED_IN_9_4_0("This member is deprecated.")
725  vtkSmartPointer<vtkIdList> LegacyPointIdsBuffer;
726 
739  static void DecomposeAPolyhedronCell(const vtkIdType* cellStream, vtkIdType& numCellPts,
740  vtkIdType& nCellFaces, vtkCellArray* cellArray, vtkCellArray* faces);
741 
742  static void DecomposeAPolyhedronCell(vtkIdType nCellFaces, const vtkIdType* cellStream,
743  vtkIdType& numCellPts, vtkCellArray* cellArray, vtkCellArray* facesArray);
744 
745  static void DecomposeAPolyhedronCell(vtkCellArray* polyhedronCell, vtkIdType& numCellPts,
746  vtkIdType& nCellfaces, vtkCellArray* cellArray, vtkCellArray* faces);
747 
748  static void DecomposeAPolyhedronCell(const vtkIdType* cellStream, vtkIdType& numCellPts,
749  vtkIdType& nCellFaces, vtkCellArray* cellArray, vtkCellArray* faces,
750  vtkCellArray* faceLocations);
751 
752  static void DecomposeAPolyhedronCell(vtkIdType nCellFaces, const vtkIdType* cellStream,
753  vtkIdType& numCellPts, vtkCellArray* cellArray, vtkCellArray* faces,
754  vtkCellArray* faceLocations);
755 
759  static int CopyPolyhedronToFaceStream(vtkCellArray* faceArray, vtkCellArray* faceLocationArray,
760  vtkIdTypeArray* faceStream, vtkIdTypeArray* faceLocation);
761 
762 private:
763  // Hide these from the user and the compiler.
764  vtkUnstructuredGrid(const vtkUnstructuredGrid&) = delete;
765  void operator=(const vtkUnstructuredGrid&) = delete;
766 
767  void Cleanup();
768 };
769 
770 VTK_ABI_NAMESPACE_END
771 #endif
object to represent cell connectivity
Definition: vtkCellArray.h:285
Efficient cell iterator for vtkDataSet topologies.
object provides direct access to cells in vtkCellArray and type information
Definition: vtkCellTypes.h:134
abstract class to specify cell behavior
Definition: vtkCell.h:130
general representation of visualization data
abstract class to specify dataset behavior
Definition: vtkDataSet.h:165
virtual vtkCell * GetCell(vtkIdType cellId)=0
Get cell with cellId such that: 0 <= cellId < NumberOfCells.
virtual void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds, vtkIdList *cellIds)
Topological inquiry to get all cells using list of points exclusive of cell specified (e....
Detect and break reference loops.
provides thread-safe access to cells
list of point or cell ids
Definition: vtkIdList.h:132
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition: vtkIdList.h:158
vtkIdType * GetPointer(vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:224
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition: vtkIndent.h:108
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
Hold a reference to a vtkObjectBase instance.
dynamic, self-adjusting array of unsigned char
dataset represents arbitrary combinations of all possible cell types.
dataset represents arbitrary combinations of all possible cell types
void RemoveReferenceToCell(vtkIdType ptId, vtkIdType cellId)
Use these methods only if the dataset has been specified as Editable.
void GetCellTypes(vtkCellTypes *types) override
Get a list of types of cells in a dataset.
vtkCell * GetCell(vtkIdType cellId) override
Standard vtkDataSet methods; see vtkDataSet.h for documentation.
void GetCell(vtkIdType cellId, vtkGenericCell *cell) override
Standard vtkDataSet methods; see vtkDataSet.h for documentation.
static vtkUnstructuredGrid * GetData(vtkInformation *info)
Retrieve an instance of this class from an information object.
void GetCellPoints(vtkIdType cellId, vtkIdType &npts, vtkIdType const *&pts)
A higher-performing variant of the virtual vtkDataSet::GetCellPoints() for unstructured grids.
void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) override
Standard vtkDataSet methods; see vtkDataSet.h for documentation.
int GetMaxSpatialDimension() override
Get the maximum spatial dimensionality of the data which is the maximum dimension of all cells.
void Squeeze() override
Squeeze all arrays in the grid to conserve memory.
vtkIdType GetCellSize(vtkIdType cellId) override
Get the size of the cell with given cellId.
static vtkUnstructuredGrid * GetData(vtkInformationVector *v, int i=0)
Retrieve an instance of this class from an information object.
int IsHomogeneous() override
Returns whether cells are all of the same type.
vtkUnsignedCharArray * GetCellTypesArray()
Get the array of all cell types in the grid.
void GetCellNeighbors(vtkIdType cellId, vtkIdType npts, const vtkIdType *ptIds, vtkIdList *cellIds)
A topological inquiry to retrieve all of the cells using list of points exclusive of the current cell...
void ResizeCellList(vtkIdType ptId, int size)
Use these methods only if the dataset has been specified as Editable.
bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
Pre-allocate memory in internal data structures.
bool IsCellBoundary(vtkIdType cellId, vtkIdType npts, const vtkIdType *ptIds, vtkIdType &neighborCellId)
A topological inquiry to determine whether a topological entity (e.g., point, edge,...
void GetCellBounds(vtkIdType cellId, double bounds[6]) override
Standard vtkDataSet methods; see vtkDataSet.h for documentation.
vtkGetSmartPointerMacro(Links, vtkAbstractCellLinks)
Set/Get the links that you created possibly without using BuildLinks.
vtkSetSmartPointerMacro(Links, vtkAbstractCellLinks)
Set/Get the links that you created possibly without using BuildLinks.
bool IsCellBoundary(vtkIdType cellId, vtkIdType npts, const vtkIdType *ptIds)
A topological inquiry to determine whether a topological entity (e.g., point, edge,...
vtkIdType InsertNextLinkedCell(int type, int npts, const vtkIdType pts[])
Use these methods only if the dataset has been specified as Editable.
vtkIdType GetNumberOfCells() override
Standard vtkDataSet methods; see vtkDataSet.h for documentation.
void Allocate(vtkIdType numCells=1000, int vtkNotUsed(extSize)=1000) override
Method allocates initial storage for the cell connectivity.
bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize)
Pre-allocate memory in internal data structures.
void Reset()
Standard vtkDataSet methods; see vtkDataSet.h for documentation.
void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) override
Standard vtkDataSet methods; see vtkDataSet.h for documentation.
void GetPointCells(vtkIdType ptId, vtkIdType &ncells, vtkIdType *&cells)
Special (efficient) operation to return the list of cells using the specified point ptId.
vtkUnsignedCharArray * GetDistinctCellTypesArray()
Get a list of types of cells in a dataset.
void RemoveGhostCells()
This method will remove any cell that is marked as ghost (has the vtkDataSetAttributes::DUPLICATECELL...
void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds, vtkIdList *cellIds) override
A topological inquiry to retrieve all of the cells using list of points exclusive of the current cell...
static vtkUnstructuredGrid * ExtendedNew()
void CopyStructure(vtkDataSet *ds) override
Standard vtkDataSet methods; see vtkDataSet.h for documentation.
void Initialize() override
Reset the grid to an empty state and free any memory.
int GetMaxCellSize() override
Get the size, in number of points, of the largest cell.
vtkCellIterator * NewCellIterator() override
Standard vtkDataSet methods; see vtkDataSet.h for documentation.
virtual int GetGhostLevel()
Get the ghost level.
int GetCellType(vtkIdType cellId) override
Get the type of the cell with the given cellId.
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for type information and printing.
void BuildLinks()
Build topological links from points to lists of cells that use each point.
void GetIdsOfCellsOfType(int type, vtkIdTypeArray *array) override
Fill vtkIdTypeArray container with list of cell Ids.
virtual int GetPiece()
Set / Get the piece and the number of pieces.
unsigned long GetActualMemorySize() override
Return the actual size of the data in kibibytes (1024 bytes).
virtual int GetNumberOfPieces()
Set / Get the piece and the number of pieces.
void AddReferenceToCell(vtkIdType ptId, vtkIdType cellId)
Use these methods only if the dataset has been specified as Editable.
static vtkUnstructuredGrid * New()
Standard instantiation method.
void GetCellPoints(vtkIdType cellId, vtkIdType &npts, vtkIdType const *&pts, vtkIdList *ptIds) override
A higher-performing variant of the virtual vtkDataSet::GetCellPoints() for unstructured grids.
void ShallowCopy(vtkDataObject *src) override
Shallow and Deep copy.
void DeepCopy(vtkDataObject *src) override
Shallow and Deep copy.
int GetDataObjectType() override
Standard vtkDataSet API methods.
VTKIOCATALYSTCONDUIT_EXPORT void SetPolyhedralCells(vtkUnstructuredGrid *grid, vtkCellArray *elements, vtkCellArray *subelements)
Create polyhedron in grid from elements and subelements.
@ info
Definition: vtkX3D.h:376
@ function
Definition: vtkX3D.h:249
@ type
Definition: vtkX3D.h:516
@ size
Definition: vtkX3D.h:253
#define VTK_DEPRECATED_IN_9_3_0(reason)
#define VTK_DEPRECATED_IN_9_4_0(reason)
int vtkIdType
Definition: vtkType.h:315
#define VTK_UNSTRUCTURED_GRID
Definition: vtkType.h:69
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:270
#define VTK_SIZEHINT(...)