VTK  9.4.20250302
vtkCellGrid.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
26#ifndef vtkCellGrid_h
27#define vtkCellGrid_h
28
29#include "vtkCellGridRangeQuery.h" // For RangeCache ivar.
30#include "vtkCompiler.h" // for VTK_COMPILER_MSVC
31#include "vtkDataObject.h"
32#include "vtkSmartPointer.h" // For ivars.
33#include "vtkStringToken.h" // For ivars.
34#include "vtkTypeName.h" // For vtk::TypeName<>().
35
36#include <array> // For ivars.
37#include <set> // For ivars.
38#include <unordered_map> // For ivars.
39
40VTK_ABI_NAMESPACE_BEGIN
44class vtkCellMetadata;
47
48class VTKCOMMONDATAMODEL_EXPORT vtkCellGrid : public vtkDataObject
49{
50public:
52
53 static vtkCellGrid* New();
54
55 vtkTypeMacro(vtkCellGrid, vtkDataObject);
56 void PrintSelf(ostream& os, vtkIndent indent) override;
57
61 void Initialize() override;
62
67 int GetDataObjectType() override { return VTK_CELL_GRID; }
68
76 unsigned long GetActualMemorySize() override;
77
84 void ShallowCopy(vtkDataObject* baseSrc) override;
85
90 void DeepCopy(vtkDataObject* baseSrc) override;
91
96 bool CopyStructure(vtkCellGrid* other, bool byReference = true);
98
107
117 const std::unordered_map<int, vtkSmartPointer<vtkDataSetAttributes>>& GetArrayGroups() const
118 {
119 return this->ArrayGroups;
120 }
121
129 std::unordered_map<vtkAbstractArray*, vtkStringToken>& arrayLocations) const;
131
137
141 bool SupportsGhostArray(int type) override;
142
149
153 vtkIdType GetNumberOfElements(int type) override;
154
157
166 void GetBounds(double bounds[6]);
167
169
179 template <typename CellType>
180 CellType* AddCellMetadata()
181 {
182 CellType* result = this->GetCellsOfType<CellType>();
183 if (result)
184 {
185 return result;
186 }
187 auto metadata = vtkSmartPointer<CellType>::New();
188 if (metadata->SetCellGrid(this))
189 {
190 auto ok = this->Cells.insert(
191 std::make_pair(vtkStringToken(vtk::TypeName<CellType>()).GetId(), metadata));
192 if (ok.second)
193 {
194 result = dynamic_cast<CellType*>(ok.first->second.GetPointer());
195 }
196 }
197 return result;
198 }
199
201
204
206
217
222 template <typename CellType>
224 {
225 CellType* meta = this->GetCellsOfType<CellType>();
226 if (!meta)
227 {
228 return false;
229 }
230 return this->RemoveCellMetadata(meta);
231 }
232
235
237
245
247
250 template <typename CellType>
251 const CellType* GetCellsOfType() const
252 {
253 auto it = this->Cells.find(vtkStringToken(vtk::TypeName<CellType>()).GetId());
254 if (it == this->Cells.end())
255 {
256 return nullptr;
257 }
258 return static_cast<const CellType*>(it->second.GetPointer());
259 }
260 template <typename CellType>
261 CellType* GetCellsOfType()
262 {
263 auto it = this->Cells.find(vtkStringToken(vtk::TypeName<CellType>()).GetId());
264 if (it == this->Cells.end())
265 {
266 return nullptr;
267 }
268 return static_cast<CellType*>(it->second.GetPointer());
269 }
271
273
276 template <typename Container>
277 void CellTypes(Container& cellTypes) const
278 {
279 for (const auto& entry : this->Cells)
280 {
281 cellTypes.insert(cellTypes.end(), entry.first);
282 }
283 }
284 template <typename Container>
285 Container CellTypes() const
286 {
287 Container cellTypes;
288 this->CellTypes(cellTypes);
289 return cellTypes;
290 }
291 std::vector<vtkStringToken> CellTypeArray() const;
292 std::vector<std::string> GetCellTypes() const;
294
296
299 const vtkCellMetadata* GetCellType(vtkStringToken cellTypeName) const;
302
304
313 virtual bool AddCellAttribute(vtkCellAttribute* attribute);
315
317
323 virtual bool RemoveCellAttribute(vtkCellAttribute* attribute);
325
341 virtual bool GetCellAttributeRange(vtkCellAttribute* attribute, int componentIndex,
342 double range[2], bool finiteRange = false) const;
343
346 vtkCellGridRangeQuery::CacheMap& GetRangeCache() const { return this->RangeCache; }
347
353 void ClearRangeCache(const std::string& attributeName = std::string());
354
358 std::set<int> GetCellAttributeIds() const;
359 std::vector<int> GetUnorderedCellAttributeIds() const;
360
364 std::vector<vtkSmartPointer<vtkCellAttribute>> GetCellAttributeList() const;
365
367
375
377
389 vtkCellAttribute* GetCellAttributeByName(const std::string& name);
391
393
408
410
419
421 virtual void SetSchema(vtkStringToken name, vtkTypeUInt32 version);
423 vtkGetMacro(SchemaVersion, vtkTypeUInt32);
424
430 vtkSetMacro(ContentVersion, vtkTypeUInt32);
431 vtkGetMacro(ContentVersion, vtkTypeUInt32)
432
433
437 static vtkCellGrid* GetData(vtkInformation* info);
438 static vtkCellGrid* GetData(vtkInformationVector* v, int i = 0);
440
448 static vtkDataArray* CorrespondingArray(
449 vtkCellGrid* gridA, vtkDataArray* arrayA, vtkCellGrid* gridB);
450
458 static vtkInformationIntegerVectorKey* ARRAY_GROUP_IDS();
459
460protected:
461 // Provide write access to this->NextAttribute:
463
465 ~vtkCellGrid() override;
466
467 bool ComputeBoundsInternal();
468 bool ComputeRangeInternal(vtkCellAttribute* attribute, int component, bool finiteRange) const;
469
470 std::unordered_map<int, vtkSmartPointer<vtkDataSetAttributes>> ArrayGroups;
472 std::unordered_map<vtkStringToken::Hash, vtkSmartPointer<vtkCellAttribute>> Attributes;
473 int NextAttribute = 0;
474 vtkStringToken ShapeAttribute;
475 bool HaveShape{ false };
476
482 vtkTypeUInt32 SchemaVersion{ 0 };
487 vtkTypeUInt32 ContentVersion{ 0 };
488
489 mutable std::array<double, 6> CachedBounds;
491
494
495private:
496 vtkCellGrid(const vtkCellGrid&) = delete;
497 void operator=(const vtkCellGrid&) = delete;
498};
499
500VTK_ABI_NAMESPACE_END
501#endif
Abstract superclass for all arrays.
A function defined over the physical domain of a vtkCellGrid.
Copy the cell metadata and attribute(s) of one cell-grid into another.
Perform an operation on cells in a vtkCellMetadata instance.
std::map< vtkCellAttribute *, std::vector< ComponentRange > > CacheMap
Visualization data composed of cells of arbitrary type.
Definition vtkCellGrid.h:49
void Initialize() override
Restore data object to initial state,.
vtkDataSetAttributes * GetAttributes(vtkStringToken type)
Fetch a partition of DOF arrays.
vtkIdType GetNumberOfElements(int type) override
Get the number of elements for a specific attribute type (POINT, CELL, etc.).
int GetAttributeTypeForArray(vtkAbstractArray *arr) override
Retrieves the attribute type that an array came from.
vtkCellMetadata * AddCellMetadata(vtkStringToken cellTypeName)
Insert a cell type, if possible.
vtkIdType GetNumberOfCells()
Return the number of cells (of all types).
void DeepCopy(vtkDataObject *baseSrc) override
Copy baseSrc by value (which must be a vtkCellGrid) into this object.
unsigned long GetActualMemorySize() override
Return the actual size of the data in kibibytes (1024 bytes).
void ClearRangeCache(const std::string &attributeName=std::string())
Clear the cache of cell-attribute range data.
CellType * GetCellsOfType()
Get a cell metadata object of the given type.
vtkDataSetAttributes * FindAttributes(int type) const
Fetch a partition of DOF arrays.
std::vector< vtkStringToken > CellTypeArray() const
Fill a container with all the cell types (as string tokens).
std::vector< std::string > GetCellTypes() const
Fill a container with all the cell types (as string tokens).
vtkCellGridRangeQuery::CacheMap & GetRangeCache() const
Return the cache of cell-attribute range data.
virtual void SetSchema(vtkStringToken name, vtkTypeUInt32 version)
Set the schema name and version number that generated this object.
vtkCellMetadata * GetCellType(vtkStringToken cellTypeName)
Return an object that can operate on this vtkCellGrid's cells of the given type.
bool SetShapeAttribute(vtkCellAttribute *shape)
Set/get the "shape attribute" (i.e., a vector-valued cell-attribute that maps from reference to world...
void ShallowCopy(vtkDataObject *baseSrc) override
Copy baseSrc by value (which must be a vtkCellGrid) into this object.
vtkCellAttribute * GetCellAttributeByName(const std::string &name)
Return an attribute given its name or identifier.
virtual bool AddCellAttribute(vtkCellAttribute *attribute)
Add a cell-attribute to the dataset.
vtkCellAttribute * GetCellAttribute(vtkStringToken::Hash hash)
Return an attribute given its hash.
virtual bool RemoveCellAttribute(vtkCellAttribute *attribute)
Remove a cell-attribute from the dataset.
vtkDataSetAttributes * FindAttributes(vtkStringToken type) const
Fetch a partition of DOF arrays.
CellType * AddCellMetadata()
Insert a cell type, if possible.
const CellType * GetCellsOfType() const
Get a cell metadata object of the given type.
int GetDataObjectType() override
Return class name of data type.
Definition vtkCellGrid.h:67
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
bool CopyStructure(vtkCellGrid *other, bool byReference=true)
Copy the geometric and topological data from other, but not any attributes.
vtkGetStringTokenMacro(SchemaName)
bool Query(vtkCellGridQuery *query)
Perform a query on all the cells in this instance.
void CellTypes(Container &cellTypes) const
Fill a container with all the cell types (as string tokens).
std::vector< int > GetUnorderedCellAttributeIds() const
virtual bool GetCellAttributeRange(vtkCellAttribute *attribute, int componentIndex, double range[2], bool finiteRange=false) const
Return information on the range of values taken on by a component of an attribute.
void MapArrayLocations(std::unordered_map< vtkAbstractArray *, vtkStringToken > &arrayLocations) const
This method populates the map you pass with pointers to all arrays in this cell-grid's vtkDataSetAttr...
std::array< double, 6 > CachedBounds
const std::unordered_map< int, vtkSmartPointer< vtkDataSetAttributes > > & GetArrayGroups() const
Fetch a partition of DOF arrays.
bool RemoveCellMetadata()
vtkTimeStamp CachedBoundsTime
vtkCellMetadata * AddCellMetadata(vtkCellMetadata *cellType)
Insert a cell type, if possible.
int AddAllCellMetadata()
Add every registered cell type to this grid.
static vtkCellGrid * New()
vtkStringToken SchemaName
A string specifying the schema which generated this cell-grid.
std::vector< vtkSmartPointer< vtkCellAttribute > > GetCellAttributeList() const
Return a vector of all this grid's cell-attributes.
vtkCellAttribute * GetCellAttributeById(int attributeId)
Return an attribute given its name or identifier.
bool SupportsGhostArray(int type) override
Returns true if type is CELL, false otherwise.
vtkCellAttribute * GetShapeAttribute()
Set/get the "shape attribute" (i.e., a vector-valued cell-attribute that maps from reference to world...
int RemoveUnusedCellMetadata()
Remove every registered cell type in this grid which has no cells.
vtkCellGridRangeQuery::CacheMap RangeCache
Cache for cell attribute component ranges.
void GetBounds(double bounds[6])
Fill the provided bounding box with the bounds of all the cells present in the grid.
Container CellTypes() const
Fill a container with all the cell types (as string tokens).
std::set< int > GetCellAttributeIds() const
Return the set of cell attribute IDs.
vtkUnsignedCharArray * GetGhostArray(int type) override
Returns the ghost arrays of the data object of the specified attribute type.
const vtkCellMetadata * GetCellType(vtkStringToken cellTypeName) const
Return an object that can operate on this vtkCellGrid's cells of the given type.
bool RemoveCellMetadata(vtkCellMetadata *meta)
vtkDataSetAttributes * GetAttributes(int type) override
Fetch a partition of DOF arrays.
Metadata for a particular type of cell (finite element).
abstract superclass for arrays of numeric data
general representation of visualization data
represent and manipulate attribute data in a dataset
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.
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
Represent a string by its integer hash.
std::uint32_t Hash
record modification and/or execution time
dynamic, self-adjusting array of unsigned char
@ Cells
A cell specified by degrees of freedom held in arrays.
int vtkIdType
Definition vtkType.h:332
@ VTK_CELL_GRID
Definition vtkType.h:130