VTK  9.4.20250127
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 {
293#if defined(_MSC_VER) && _MSC_VER >= 1930 && _MSC_VER < 1940 /*17.4+*/
294 // MSVC 2022 bombs when an exported method uses thread_local in its implementation.
295 // See https://github.com/pytorch/pytorch/issues/87957 for more. We omit the
296 // thread_local here, which makes this method non-threadsafe on Windows, which
297 // should be OK in most cases.
298 static std::vector<vtkStringToken> cellTypes;
299#else
300 static thread_local std::vector<vtkStringToken> cellTypes;
301#endif
302 cellTypes.clear();
303 this->CellTypes(cellTypes);
304 return cellTypes;
305 }
306 std::vector<std::string> GetCellTypes() const
307 {
308 auto cta = this->CellTypeArray();
309 std::vector<std::string> result;
310 result.reserve(cta.size());
311 for (const auto& cellTypeToken : cta)
312 {
313 result.push_back(cellTypeToken.Data());
314 }
315 return result;
316 }
318
320
323 const vtkCellMetadata* GetCellType(vtkStringToken cellTypeName) const;
326
328
337 virtual bool AddCellAttribute(vtkCellAttribute* attribute);
339
341
347 virtual bool RemoveCellAttribute(vtkCellAttribute* attribute);
349
365 virtual bool GetCellAttributeRange(vtkCellAttribute* attribute, int componentIndex,
366 double range[2], bool finiteRange = false) const;
367
370 vtkCellGridRangeQuery::CacheMap& GetRangeCache() const { return this->RangeCache; }
371
377 void ClearRangeCache(const std::string& attributeName = std::string());
378
382 std::set<int> GetCellAttributeIds() const;
383 std::vector<int> GetUnorderedCellAttributeIds() const;
384
388 std::vector<vtkSmartPointer<vtkCellAttribute>> GetCellAttributeList() const;
389
391
399
401
413 vtkCellAttribute* GetCellAttributeByName(const std::string& name);
415
417
432
434
443
445 virtual void SetSchema(vtkStringToken name, vtkTypeUInt32 version);
447 vtkGetMacro(SchemaVersion, vtkTypeUInt32);
448
454 vtkSetMacro(ContentVersion, vtkTypeUInt32);
455 vtkGetMacro(ContentVersion, vtkTypeUInt32)
456
457
461 static vtkCellGrid* GetData(vtkInformation* info);
462 static vtkCellGrid* GetData(vtkInformationVector* v, int i = 0);
464
472 static vtkDataArray* CorrespondingArray(
473 vtkCellGrid* gridA, vtkDataArray* arrayA, vtkCellGrid* gridB);
474
482 static vtkInformationIntegerVectorKey* ARRAY_GROUP_IDS();
483
484protected:
485 // Provide write access to this->NextAttribute:
487
489 ~vtkCellGrid() override;
490
491 bool ComputeBoundsInternal();
492 bool ComputeRangeInternal(vtkCellAttribute* attribute, int component, bool finiteRange) const;
493
494 std::unordered_map<int, vtkSmartPointer<vtkDataSetAttributes>> ArrayGroups;
496 std::unordered_map<vtkStringToken::Hash, vtkSmartPointer<vtkCellAttribute>> Attributes;
497 int NextAttribute = 0;
498 vtkStringToken ShapeAttribute;
499 bool HaveShape{ false };
500
506 vtkTypeUInt32 SchemaVersion{ 0 };
511 vtkTypeUInt32 ContentVersion{ 0 };
512
513 mutable std::array<double, 6> CachedBounds;
515
518
519private:
520 vtkCellGrid(const vtkCellGrid&) = delete;
521 void operator=(const vtkCellGrid&) = delete;
522};
523
524VTK_ABI_NAMESPACE_END
525#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:315
#define VTK_CELL_GRID
Definition vtkType.h:114