VTK  9.6.20260617
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
25
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() VTK_FUTURE_CONST 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
118 const std::unordered_map<int, vtkSmartPointer<vtkDataSetAttributes>>& GetArrayGroups() const
119 {
120 return this->ArrayGroups;
121 }
122
130 std::unordered_map<vtkAbstractArray*, vtkStringToken>& arrayLocations) const;
132
138
142 bool SupportsGhostArray(int type) override;
143
150
154 vtkIdType GetNumberOfElements(int type) override;
155
158
167 void GetBounds(double bounds[6]);
168
170
180 template <typename CellType>
181 CellType* AddCellMetadata()
182 {
183 CellType* result = this->GetCellsOfType<CellType>();
184 if (result)
185 {
186 return result;
187 }
188 auto metadata = vtkSmartPointer<CellType>::New();
189 if (metadata->SetCellGrid(this))
190 {
191 auto ok = this->Cells.insert(
192 std::make_pair(vtkStringToken(vtk::TypeName<CellType>()).GetId(), metadata));
193 if (ok.second)
194 {
195 result = dynamic_cast<CellType*>(ok.first->second.GetPointer());
196 }
197 }
198 return result;
199 }
200
202
205
207
218
223 template <typename CellType>
225 {
226 CellType* meta = this->GetCellsOfType<CellType>();
227 if (!meta)
228 {
229 return false;
230 }
231 return this->RemoveCellMetadata(meta);
232 }
233
236
238
246
248
251 template <typename CellType>
252 const CellType* GetCellsOfType() const
253 {
254 auto it = this->Cells.find(vtkStringToken(vtk::TypeName<CellType>()).GetId());
255 if (it == this->Cells.end())
256 {
257 return nullptr;
258 }
259 return static_cast<const CellType*>(it->second.GetPointer());
260 }
261 template <typename CellType>
262 CellType* GetCellsOfType()
263 {
264 auto it = this->Cells.find(vtkStringToken(vtk::TypeName<CellType>()).GetId());
265 if (it == this->Cells.end())
266 {
267 return nullptr;
268 }
269 return static_cast<CellType*>(it->second.GetPointer());
270 }
271
272
274
277 template <typename Container>
278 void CellTypes(Container& cellTypes) const
279 {
280 for (const auto& entry : this->Cells)
281 {
282 cellTypes.insert(cellTypes.end(), entry.first);
283 }
284 }
285 template <typename Container>
286 Container CellTypes() const
287 {
288 Container cellTypes;
289 this->CellTypes(cellTypes);
290 return cellTypes;
291 }
292 std::vector<vtkStringToken> CellTypeArray() const;
293 std::vector<std::string> GetCellTypes() const;
295
297
300 const vtkCellMetadata* GetCellType(vtkStringToken cellTypeName) const;
303
305
314 virtual bool AddCellAttribute(vtkCellAttribute* attribute);
316
318
324 virtual bool RemoveCellAttribute(vtkCellAttribute* attribute);
326
342 virtual bool GetCellAttributeRange(vtkCellAttribute* attribute, int componentIndex,
343 double range[2], bool finiteRange = false) const;
344
348
354 void ClearRangeCache(const std::string& attributeName = std::string());
355
359 std::set<int> GetCellAttributeIds() const;
360 std::vector<int> GetUnorderedCellAttributeIds() const;
361
365 std::vector<vtkSmartPointer<vtkCellAttribute>> GetCellAttributeList() const;
366
368
376
378
390 vtkCellAttribute* GetCellAttributeByName(const std::string& name);
392
394
409
411
420
422 virtual void SetSchema(vtkStringToken name, vtkTypeUInt32 version);
424 vtkGetMacro(SchemaVersion, vtkTypeUInt32);
425
431 vtkSetMacro(ContentVersion, vtkTypeUInt32);
432 vtkGetMacro(ContentVersion, vtkTypeUInt32)
433
434
441
450 vtkCellGrid* gridA, vtkDataArray* arrayA, vtkCellGrid* gridB);
451
460
461protected:
462 // Provide write access to this->NextAttribute:
464
466 ~vtkCellGrid() override;
467
469 bool ComputeRangeInternal(vtkCellAttribute* attribute, int component, bool finiteRange) const;
470
476 bool HaveShape{ false };
477
483 vtkTypeUInt32 SchemaVersion{ 0 };
488 vtkTypeUInt32 ContentVersion{ 0 };
489
490 mutable std::array<double, 6> CachedBounds;
492
495
496private:
497 vtkCellGrid(const vtkCellGrid&) = delete;
498 void operator=(const vtkCellGrid&) = delete;
499};
500
501VTK_ABI_NAMESPACE_END
502#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
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.
friend class vtkCellGridCopyQuery
vtkIdType GetNumberOfCells()
Return the number of cells (of all types).
bool ComputeBoundsInternal()
vtkTypeUInt32 ContentVersion
A user-provided version number for the grid's data.
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.
std::unordered_map< int, vtkSmartPointer< vtkDataSetAttributes > > ArrayGroups
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.
int GetDataObjectType() VTK_FUTURE_CONST override
Return class name of data type.
Definition vtkCellGrid.h:67
static vtkInformationIntegerVectorKey * ARRAY_GROUP_IDS()
This information key is used to mark arrays with the string token(s) of their owning vtkDataSetAttrib...
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
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.
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 ComputeRangeInternal(vtkCellAttribute *attribute, int component, bool finiteRange) const
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.
static vtkCellGrid * GetData(vtkInformation *info)
Retrieve an instance of this class from an information object.
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()
std::unordered_map< vtkStringToken::Hash, vtkSmartPointer< vtkCellAttribute > > Attributes
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()
vtkFieldData * GetAttributesAsFieldData(int type) override
Fetch a partition of DOF arrays.
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.
static vtkDataArray * CorrespondingArray(vtkCellGrid *gridA, vtkDataArray *arrayA, vtkCellGrid *gridB)
Identify a correspondence between arrays in two cell grid objects.
vtkStringToken ShapeAttribute
std::unordered_map< CellTypeId, vtkSmartPointer< vtkCellMetadata > > Cells
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.
vtkStringToken CellTypeId
Definition vtkCellGrid.h:51
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.
vtkTypeUInt32 SchemaVersion
The monotonically-increasing version number associated with SchemaName.
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).
represent and manipulate attribute data in a dataset
Represents and manipulates a collection of data arrays.
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
std::string TypeName()
Return the demangled type-name of the provided ObjectType.
#define vtkDataArray
int vtkIdType
Definition vtkType.h:363
@ VTK_CELL_GRID
Definition vtkType.h:158