VTK  9.3.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
23 #ifndef vtkCellGrid_h
24 #define vtkCellGrid_h
25 
26 #include "vtkCompiler.h" // for VTK_COMPILER_MSVC
27 #include "vtkDataObject.h"
28 #include "vtkSmartPointer.h" // For ivars.
29 #include "vtkStringToken.h" // For ivars.
30 #include "vtkTypeName.h" // For vtk::TypeName<>().
31 
32 #include <array> // For ivars.
33 #include <unordered_map> // For ivars.
34 
35 VTK_ABI_NAMESPACE_BEGIN
36 class vtkCellAttribute;
37 class vtkCellGridQuery;
38 class vtkCellMetadata;
40 
41 class VTKCOMMONDATAMODEL_EXPORT vtkCellGrid : public vtkDataObject
42 {
43 public:
45 
46  static vtkCellGrid* New();
47 
48  vtkTypeMacro(vtkCellGrid, vtkDataObject);
49  void PrintSelf(ostream& os, vtkIndent indent) override;
50 
54  void Initialize() override;
55 
60  int GetDataObjectType() override { return VTK_CELL_GRID; }
61 
69  unsigned long GetActualMemorySize() override;
70 
72 
75  void ShallowCopy(vtkDataObject* baseSrc) override;
76  void DeepCopy(vtkDataObject* baseSrc) override;
78 
80 
88  vtkDataSetAttributes* FindAttributes(int type) const;
89  const std::unordered_map<int, vtkSmartPointer<vtkDataSetAttributes>>& GetArrayGroups() const
90  {
91  return this->ArrayGroups;
92  }
94 
100 
106  int GetAttributeTypeForArray(vtkAbstractArray* arr) override;
107 
111  vtkIdType GetNumberOfElements(int type) override;
112 
114  vtkIdType GetNumberOfCells();
115 
124  void GetBounds(double bounds[6]);
125 
127 
137  template <typename CellType>
138  CellType* AddCellMetadata()
139  {
140  CellType* result = this->GetCellsOfType<CellType>();
141  if (result)
142  {
143  return result;
144  }
145  auto metadata = vtkSmartPointer<CellType>::New();
146  if (metadata->SetCellGrid(this))
147  {
148  auto ok = this->Cells.insert(
149  std::make_pair(vtkStringToken(vtk::TypeName<CellType>()).GetId(), metadata));
150  if (ok.second)
151  {
152  result = ok.first.GetPointer();
153  }
154  }
155  return result;
156  }
157 
158  vtkCellMetadata* AddCellMetadata(vtkCellMetadata* cellType);
160 
162 
165  template <typename CellType>
166  const CellType* GetCellsOfType() const
167  {
168  auto it = this->Cells.find(vtkStringToken(vtk::TypeName<CellType>()).GetId());
169  if (it == this->Cells.end())
170  {
171  return nullptr;
172  }
173  return static_cast<const CellType*>(it->second);
174  }
175  template <typename CellType>
176  CellType* GetCellsOfType()
177  {
178  auto it = this->Cells.find(vtkStringToken(vtk::TypeName<CellType>()).GetId());
179  if (it == this->Cells.end())
180  {
181  return nullptr;
182  }
183  return static_cast<CellType*>(it->second);
184  }
186 
188 
191  template <typename Container>
192  void CellTypes(Container& cellTypes) const
193  {
194  for (const auto& entry : this->Cells)
195  {
196  cellTypes.insert(cellTypes.end(), entry.first);
197  }
198  }
199  template <typename Container>
200  Container CellTypes() const
201  {
202  Container cellTypes;
203  this->CellTypes(cellTypes);
204  return cellTypes;
205  }
206  std::vector<vtkStringToken> CellTypeArray() const
207  {
208 #if defined(_MSC_VER) && _MSC_VER >= 1930 && _MSC_VER < 1940 /*17.4+*/
209  // MSVC 2022 bombs when an exported method uses thread_local in its implementation.
210  // See https://github.com/pytorch/pytorch/issues/87957 for more. We omit the
211  // thread_local here, which makes this method non-threadsafe on Windows, which
212  // should be OK in most cases.
213  static std::vector<vtkStringToken> cellTypes;
214 #else
215  static thread_local std::vector<vtkStringToken> cellTypes;
216 #endif
217  this->CellTypes(cellTypes);
218  return cellTypes;
219  }
221 
223 
226  const vtkCellMetadata* GetCellType(vtkStringToken cellTypeName) const;
229 
231 
240  virtual bool AddCellAttribute(vtkCellAttribute* attribute);
242 
244 
255  vtkCellAttribute* GetCellAttributeById(int attributeId);
256  vtkCellAttribute* GetCellAttributeByName(const std::string& name);
258 
260 
272  vtkCellAttribute* GetShapeAttribute();
273  bool SetShapeAttribute(vtkCellAttribute* shape);
275 
277 
284  bool Query(vtkCellGridQuery* query);
286 
288 
292  static vtkCellGrid* GetData(vtkInformationVector* v, int i = 0);
294 
295 protected:
296  vtkCellGrid();
297  ~vtkCellGrid() override;
298 
299  bool ComputeBoundsInternal();
300 
301  std::unordered_map<int, vtkSmartPointer<vtkDataSetAttributes>> ArrayGroups;
302  std::unordered_map<CellTypeId, vtkSmartPointer<vtkCellMetadata>> Cells;
303  std::unordered_map<vtkStringToken::Hash, vtkSmartPointer<vtkCellAttribute>> Attributes;
304  int NextAttribute = 0;
306  bool HaveShape{ false };
307 
308  mutable std::array<double, 6> CachedBounds;
310 
311 private:
312  vtkCellGrid(const vtkCellGrid&) = delete;
313  void operator=(const vtkCellGrid&) = delete;
314 };
315 
316 VTK_ABI_NAMESPACE_END
317 #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.
static vtkDataObject * GetData(vtkInformation *info)
Retrieve an instance of this class from an information object.
void GetBounds(T a, double bds[6])
Perform an operation on cells in a vtkCellMetadata instance.
virtual vtkDataSetAttributes * GetAttributes(int type)
Returns the attributes of the data object of the specified attribute type.
static vtkDataObject * New()
Store vtkAlgorithm input/output information.
CellType * GetCellsOfType()
Get a cell metadata object of the given type.
Definition: vtkCellGrid.h:176
std::unordered_map< CellTypeId, vtkSmartPointer< vtkCellMetadata > > Cells
Definition: vtkCellGrid.h:302
Abstract superclass for all arrays.
const std::unordered_map< int, vtkSmartPointer< vtkDataSetAttributes > > & GetArrayGroups() const
Fetch a partition of DOF arrays.
Definition: vtkCellGrid.h:89
int GetDataObjectType() override
Return class name of data type.
Definition: vtkCellGrid.h:60
std::unordered_map< vtkStringToken::Hash, vtkSmartPointer< vtkCellAttribute > > Attributes
Definition: vtkCellGrid.h:303
record modification and/or execution time
Definition: vtkTimeStamp.h:24
Metadata for a particular type of cell (finite element).
virtual void Initialize()
Restore data object to initial state,.
int vtkIdType
Definition: vtkType.h:315
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
std::unordered_map< int, vtkSmartPointer< vtkDataSetAttributes > > ArrayGroups
Definition: vtkCellGrid.h:301
Visualization data composed of cells of arbitrary type.
Definition: vtkCellGrid.h:41
a simple class to control print indentation
Definition: vtkIndent.h:28
std::vector< vtkStringToken > CellTypeArray() const
Fill a container with all the cell types (as string tokens).
Definition: vtkCellGrid.h:206
A function defined over the physical domain of a vtkCellGrid.
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:200
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:138
int GetCellType(const Ioss::ElementTopology *topology)
Returns VTK celltype for a Ioss topology element.
dynamic, self-adjusting array of unsigned char
virtual int GetAttributeTypeForArray(vtkAbstractArray *arr)
Retrieves the attribute type that an array came from.
virtual vtkIdType GetNumberOfElements(int type)
Get the number of elements for a specific attribute type (POINT, CELL, etc.).
vtkStringToken ShapeAttribute
Definition: vtkCellGrid.h:305
const CellType * GetCellsOfType() const
Get a cell metadata object of the given type.
Definition: vtkCellGrid.h:166
Store zero or more vtkInformation instances.
vtkTimeStamp CachedBoundsTime
Definition: vtkCellGrid.h:309
#define VTK_CELL_GRID
Definition: vtkType.h:114
general representation of visualization data
Definition: vtkDataObject.h:54
void CellTypes(Container &cellTypes) const
Fill a container with all the cell types (as string tokens).
Definition: vtkCellGrid.h:192
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.
std::array< double, 6 > CachedBounds
Definition: vtkCellGrid.h:308