VTK  9.3.0
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 
89  const std::unordered_map<int, vtkSmartPointer<vtkDataSetAttributes>>& GetArrayGroups() const
90  {
91  return this->ArrayGroups;
92  }
94 
100 
107 
112 
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 
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 
258 
260 
275 
277 
284  bool Query(vtkCellGridQuery* query);
286 
288 
292  static vtkCellGrid* GetData(vtkInformationVector* v, int i = 0);
294 
295 protected:
297  ~vtkCellGrid() override;
298 
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
Abstract superclass for all arrays.
A function defined over the physical domain of a vtkCellGrid.
Perform an operation on cells in a vtkCellMetadata instance.
Visualization data composed of cells of arbitrary type.
Definition: vtkCellGrid.h:42
CellType * GetCellsOfType()
Get a cell metadata object of the given type.
Definition: vtkCellGrid.h:176
vtkCellMetadata * GetCellType(vtkStringToken cellTypeName)
Return an object that can operate on this vtkCellGrid's cells of the given type.
void Initialize() override
Restore data object to initial state,.
std::vector< vtkStringToken > CellTypeArray() const
Fill a container with all the cell types (as string tokens).
Definition: vtkCellGrid.h:206
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(vtkCellMetadata *cellType)
Insert a cell type, if possible.
const CellType * GetCellsOfType() const
Get a cell metadata object of the given type.
Definition: vtkCellGrid.h:166
vtkIdType GetNumberOfCells()
Return the number of cells (of all types).
bool ComputeBoundsInternal()
void DeepCopy(vtkDataObject *baseSrc) override
Shallow and Deep copy.
vtkCellAttribute * GetCellAttributeById(int attributeId)
Return an attribute given its name or identifier.
unsigned long GetActualMemorySize() override
Return the actual size of the data in kibibytes (1024 bytes).
std::unordered_map< int, vtkSmartPointer< vtkDataSetAttributes > > ArrayGroups
Definition: vtkCellGrid.h:301
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
Shallow and Deep copy.
virtual bool AddCellAttribute(vtkCellAttribute *attribute)
Add a cell-attribute to the dataset.
int GetDataObjectType() override
Return class name of data type.
Definition: vtkCellGrid.h:60
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
~vtkCellGrid() override
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).
Definition: vtkCellGrid.h:192
const vtkCellMetadata * GetCellType(vtkStringToken cellTypeName) const
Return an object that can operate on this vtkCellGrid's cells of the given type.
std::array< double, 6 > CachedBounds
Definition: vtkCellGrid.h:308
std::unordered_map< vtkStringToken::Hash, vtkSmartPointer< vtkCellAttribute > > Attributes
Definition: vtkCellGrid.h:303
static vtkCellGrid * GetData(vtkInformation *info)
Retrieve an instance of this class from an information object.
vtkTimeStamp CachedBoundsTime
Definition: vtkCellGrid.h:309
const std::unordered_map< int, vtkSmartPointer< vtkDataSetAttributes > > & GetArrayGroups() const
Fetch a partition of DOF arrays.
Definition: vtkCellGrid.h:89
vtkCellAttribute * GetShapeAttribute()
Set/get the "shape attribute" (i.e., a vector-valued cell-attribute that maps from reference to world...
vtkStringToken ShapeAttribute
Definition: vtkCellGrid.h:305
std::unordered_map< CellTypeId, vtkSmartPointer< vtkCellMetadata > > Cells
Definition: vtkCellGrid.h:302
vtkDataSetAttributes * FindAttributes(int type) const
Fetch a partition of DOF arrays.
vtkDataSetAttributes * GetAttributes(int type) override
Fetch a partition of DOF arrays.
vtkDataSetAttributes * GetAttributes(vtkStringToken type)
Fetch a partition of DOF arrays.
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).
Definition: vtkCellGrid.h:200
vtkCellAttribute * GetCellAttributeByName(const std::string &name)
Return an attribute given its name or identifier.
vtkUnsignedCharArray * GetGhostArray(int type) override
Returns the ghost arrays of the data object of the specified attribute type.
static vtkCellGrid * New()
static vtkCellGrid * GetData(vtkInformationVector *v, int i=0)
Retrieve an instance of this class from an information object.
CellType * AddCellMetadata()
Insert a cell type, if possible.
Definition: vtkCellGrid.h:138
Metadata for a particular type of cell (finite element).
general representation of visualization data
Definition: vtkDataObject.h:64
represent and manipulate attribute data in a dataset
a simple class to control print indentation
Definition: vtkIndent.h:38
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
Represent a string by its integer hash.
record modification and/or execution time
Definition: vtkTimeStamp.h:34
dynamic, self-adjusting array of unsigned char
@ info
Definition: vtkX3D.h:376
@ type
Definition: vtkX3D.h:516
@ name
Definition: vtkX3D.h:219
@ string
Definition: vtkX3D.h:490
int vtkIdType
Definition: vtkType.h:315
#define VTK_CELL_GRID
Definition: vtkType.h:114