VTK  9.7.1
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 
40 VTK_ABI_NAMESPACE_BEGIN
41 class vtkCellAttribute;
42 class vtkCellGridQuery;
44 class vtkCellMetadata;
47 
48 class VTKCOMMONDATAMODEL_EXPORT vtkCellGrid : public vtkDataObject
49 {
50 public:
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 
114  vtkDataSetAttributes* GetAttributes(int type) override;
116  vtkDataSetAttributes* FindAttributes(int type) const;
117  vtkDataSetAttributes* FindAttributes(vtkStringToken type) const;
118  const std::unordered_map<int, vtkSmartPointer<vtkDataSetAttributes>>& GetArrayGroups() const
119  {
120  return this->ArrayGroups;
121  }
122 
129  void MapArrayLocations(
130  std::unordered_map<vtkAbstractArray*, vtkStringToken>& arrayLocations) const;
132 
137  vtkUnsignedCharArray* GetGhostArray(int type) override;
138 
142  bool SupportsGhostArray(int type) override;
143 
149  int GetAttributeTypeForArray(vtkAbstractArray* arr) override;
150 
154  vtkIdType GetNumberOfElements(int type) override;
155 
157  vtkIdType GetNumberOfCells();
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 
201  vtkCellMetadata* AddCellMetadata(vtkCellMetadata* cellType);
202 
203  vtkCellMetadata* AddCellMetadata(vtkStringToken cellTypeName);
205 
207 
216  int AddAllCellMetadata();
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 
234  bool RemoveCellMetadata(vtkCellMetadata* meta);
236 
238 
244  int RemoveUnusedCellMetadata();
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  }
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 
347  vtkCellGridRangeQuery::CacheMap& GetRangeCache() const { return this->RangeCache; }
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 
374  vtkCellAttribute* GetCellAttribute(vtkStringToken::Hash hash);
376 
378 
389  vtkCellAttribute* GetCellAttributeById(int attributeId);
390  vtkCellAttribute* GetCellAttributeByName(const std::string& name);
392 
394 
406  vtkCellAttribute* GetShapeAttribute();
407  bool SetShapeAttribute(vtkCellAttribute* shape);
409 
411 
418  bool Query(vtkCellGridQuery* query);
420 
422  virtual void SetSchema(vtkStringToken name, vtkTypeUInt32 version);
423  vtkGetStringTokenMacro(SchemaName);
424  vtkGetMacro(SchemaVersion, vtkTypeUInt32);
425 
431  vtkSetMacro(ContentVersion, vtkTypeUInt32);
432  vtkGetMacro(ContentVersion, vtkTypeUInt32)
433 
434 
435 
439  static vtkCellGrid* GetData(vtkInformationVector* v, int i = 0);
441 
449  static vtkDataArray* CorrespondingArray(
450  vtkCellGrid* gridA, vtkDataArray* arrayA, vtkCellGrid* gridB);
451 
459  static vtkInformationIntegerVectorKey* ARRAY_GROUP_IDS();
460 
461 protected:
462  // Provide write access to this->NextAttribute:
463  friend class vtkCellGridCopyQuery;
464 
465  vtkCellGrid();
466  ~vtkCellGrid() override;
467 
468  bool ComputeBoundsInternal();
469  bool ComputeRangeInternal(vtkCellAttribute* attribute, int component, bool finiteRange) const;
470 
471  std::unordered_map<int, vtkSmartPointer<vtkDataSetAttributes>> ArrayGroups;
473  std::unordered_map<vtkStringToken::Hash, vtkSmartPointer<vtkCellAttribute>> Attributes;
474  int NextAttribute = 0;
475  vtkStringToken ShapeAttribute;
476  bool HaveShape{ false };
477 
483  vtkTypeUInt32 SchemaVersion{ 0 };
488  vtkTypeUInt32 ContentVersion{ 0 };
489 
490  mutable std::array<double, 6> CachedBounds;
492 
495 
496 private:
497  vtkCellGrid(const vtkCellGrid&) = delete;
498  void operator=(const vtkCellGrid&) = delete;
499 };
500 
501 VTK_ABI_NAMESPACE_END
502 #endif
virtual vtkUnsignedCharArray * GetGhostArray(int type)
Returns the ghost arrays of the data object of the specified attribute type.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void GetBounds(T a, double bds[6])
Perform an operation on cells in a vtkCellMetadata instance.
virtual vtkFieldData * GetAttributesAsFieldData(int type)
Returns the attributes of the data object as a vtkFieldData.
virtual vtkDataSetAttributes * GetAttributes(int type)
Returns the attributes of the data object of the specified attribute type.
vtkCellGridRangeQuery::CacheMap RangeCache
Cache for cell attribute component ranges.
Definition: vtkCellGrid.h:494
static vtkDataObject * New()
Store vtkAlgorithm input/output information.
CellType * GetCellsOfType()
Get a cell metadata object of the given type.
Definition: vtkCellGrid.h:262
Copy the cell metadata and attribute(s) of one cell-grid into another.
Abstract superclass for all arrays.
const std::unordered_map< int, vtkSmartPointer< vtkDataSetAttributes > > & GetArrayGroups() const
Fetch a partition of DOF arrays.
Definition: vtkCellGrid.h:118
record modification and/or execution time
Definition: vtkTimeStamp.h:24
vtkCellGridRangeQuery::CacheMap & GetRangeCache() const
Return the cache of cell-attribute range data.
Definition: vtkCellGrid.h:347
Metadata for a particular type of cell (finite element).
std::map< vtkCellAttribute *, std::vector< ComponentRange >> CacheMap
int GetDataObjectType() VTK_FUTURE_CONST override
Return class name of data type.
Definition: vtkCellGrid.h:67
virtual bool SupportsGhostArray(int type)
Returns if this type of data object support ghost array for specified type.
virtual void Initialize()
Restore data object to initial state,.
Hold a reference to a vtkObjectBase instance.
Definition: vtkMeta.h:23
int vtkIdType
Definition: vtkType.h:363
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
Visualization data composed of cells of arbitrary type.
Definition: vtkCellGrid.h:48
std::uint32_t Hash
VTKIOCATALYSTCONDUIT_EXPORT int GetCellType(const std::string &shape)
Get vtk cell type from conduit shape name throw a runtime_error on unsupported type.
a simple class to control print indentation
Definition: vtkIndent.h:28
A function defined over the physical domain of a vtkCellGrid.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
represent and manipulate attribute data in a dataset
Container CellTypes() const
Fill a container with all the cell types (as string tokens).
Definition: vtkCellGrid.h:286
Represent a string by its integer hash.
virtual unsigned long GetActualMemorySize()
Return the actual size of the data in kibibytes (1024 bytes).
CellType * AddCellMetadata()
Insert a cell type, if possible.
Definition: vtkCellGrid.h:181
vtkSmartPointer< vtkDataArray > GetData(const Ioss::GroupingEntity *entity, const std::string &fieldname, Ioss::Transform *transform=nullptr, Cache *cache=nullptr, const std::string &cachekey=std::string())
Returns a VTK array for a given field (fieldname) on the chosen block (or set) entity.
vtkStringToken SchemaName
A string specifying the schema which generated this cell-grid.
Definition: vtkCellGrid.h:479
dynamic, self-adjusting array of unsigned char
virtual int GetAttributeTypeForArray(vtkAbstractArray *arr)
Retrieves the attribute type that an array came from.
A cell specified by degrees of freedom held in arrays.
virtual vtkIdType GetNumberOfElements(int type)
Get the number of elements for a specific attribute type (POINT, CELL, etc.).
const CellType * GetCellsOfType() const
Get a cell metadata object of the given type.
Definition: vtkCellGrid.h:252
bool RemoveCellMetadata()
Definition: vtkCellGrid.h:224
Store zero or more vtkInformation instances.
vtkTimeStamp CachedBoundsTime
Definition: vtkCellGrid.h:491
general representation of visualization data
Definition: vtkDataObject.h:55
void CellTypes(Container &cellTypes) const
Fill a container with all the cell types (as string tokens).
Definition: vtkCellGrid.h:278
virtual void DeepCopy(vtkDataObject *src)
The goal of the method is to copy the complete data from src into this object.
virtual void ShallowCopy(vtkDataObject *src)
The goal of the method is to copy the data up to the array pointers only.
Represents and manipulates a collection of data arrays.
Definition: vtkFieldData.h:51
std::array< double, 6 > CachedBounds
Definition: vtkCellGrid.h:490