VTK  9.7.1
vtkCellMetadata.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
27 #ifndef vtkCellMetadata_h
28 #define vtkCellMetadata_h
29 
30 #include "vtkCellGridResponders.h" // For ivar.
31 #include "vtkCommonDataModelModule.h" // for export macro
32 #include "vtkInherits.h" // for vtk::Inherits<>()
33 #include "vtkNew.h" // for queries
34 #include "vtkObject.h"
35 #include "vtkSmartPointer.h" // for constructor return values
36 #include "vtkStringToken.h" // for vtkStringToken::Hash
37 #include "vtkTypeName.h" // for vtk::TypeName<>()
38 
39 #include <token/Singletons.h> // Increment Schwarz counter for initialization.
40 
41 #include <functional>
42 #include <set>
43 #include <unordered_map>
44 #include <unordered_set>
45 
46 VTK_ABI_NAMESPACE_BEGIN
47 class vtkCellGrid;
48 class vtkCellGridQuery;
50 class vtkCellAttribute;
51 
52 class VTKCOMMONDATAMODEL_EXPORT vtkCellMetadata : public vtkObject
53 {
54 public:
57  using MetadataConstructor = std::function<vtkSmartPointer<vtkCellMetadata>(vtkCellGrid*)>;
58  using ConstructorMap = std::unordered_map<vtkStringToken, MetadataConstructor>;
59 
60  vtkTypeMacro(vtkCellMetadata, vtkObject);
62  void PrintSelf(ostream& os, vtkIndent indent) override;
63 
67  template <typename Subclass>
68  static bool RegisterType()
69  {
70  vtkStringToken name = vtk::TypeName<Subclass>();
71  auto status = vtkCellMetadata::Constructors().insert(std::make_pair(name,
72  [](vtkCellGrid* grid)
73  {
74  auto result = vtkSmartPointer<Subclass>::New();
75  if (result)
76  {
77  result->SetCellGrid(grid);
78  }
79  return result;
80  }));
81  return status.second; // true if insertion occurred.
82  }
83 
84  template <typename Subclass>
86  {
87  vtkStringToken name = vtk::TypeName<Subclass>();
88  auto metadata = vtkCellMetadata::NewInstance(name, grid);
89  vtkSmartPointer<Subclass> result(Subclass::SafeDownCast(metadata));
90  return result;
91  }
92 
93  static vtkSmartPointer<vtkCellMetadata> NewInstance(
94  vtkStringToken className, vtkCellGrid* grid = nullptr);
95 
96  static std::unordered_set<vtkStringToken> CellTypes();
97 
105 
116  virtual bool SetCellGrid(vtkCellGrid* parent);
117 
119  vtkGetObjectMacro(CellGrid, vtkCellGrid);
120 
123  virtual vtkIdType GetNumberOfCells() { return 0; }
124 
132  bool Query(vtkCellGridQuery* query);
133 
141  virtual void ShallowCopy(vtkCellMetadata* vtkNotUsed(other)) {}
142  virtual void DeepCopy(vtkCellMetadata* vtkNotUsed(other)) {}
143 
145  static vtkCellGridResponders* GetResponders();
146 
148  static void ClearResponders();
149 
157  vtkCellGridResponders* GetCaches();
158 
159 protected:
160  vtkCellMetadata() = default;
161  ~vtkCellMetadata() override;
162 
163  vtkCellGrid* CellGrid{ nullptr };
164 
165  static ConstructorMap& Constructors();
166 
167 private:
168  vtkCellMetadata(const vtkCellMetadata&) = delete;
169  void operator=(const vtkCellMetadata&) = delete;
170 };
171 
172 VTK_ABI_NAMESPACE_END
173 #endif
Perform an operation on cells in a vtkCellMetadata instance.
vtkStringToken::Hash CellTypeId
abstract base class for most VTK objects
Definition: vtkObject.h:52
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
#define vtkInheritanceHierarchyBaseMacro(thisClass)
Use these macros to add an "InheritanceHierarchy()" method to a VTK class.
Definition: vtkInherits.h:23
vtkCellMetadata * NewInstance() const
Metadata for a particular type of cell (finite element).
virtual vtkIdType GetNumberOfCells()
Return the number of cells of this type in the parent cell-grid object.
static ConstructorMap & Constructors()
Hold a reference to a vtkObjectBase instance.
Definition: vtkMeta.h:23
int vtkIdType
Definition: vtkType.h:363
A container that holds objects able to respond to queries specialized for particular vtkCellMetadata ...
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
Hash GetId() const
Return the token's ID (usually its hash but possibly not in the case of collisions).
virtual void DeepCopy(vtkCellMetadata *other)
Visualization data composed of cells of arbitrary type.
Definition: vtkCellGrid.h:48
std::uint32_t Hash
a simple class to control print indentation
Definition: vtkIndent.h:28
const char * GetClassName() const
Return the class name as a string.
A function defined over the physical domain of a vtkCellGrid.
represent and manipulate attribute data in a dataset
Represent a string by its integer hash.
static bool RegisterType()
Register a subclass of vtkCellMetadata.
static vtkSmartPointer< Subclass > NewInstance(vtkCellGrid *grid=nullptr)
std::unordered_map< vtkStringToken, MetadataConstructor > ConstructorMap
CellTypeId Hash()
Return a hash of the cell type.
virtual void ShallowCopy(vtkCellMetadata *other)
Copy other into this instance (which must be of the same type).
std::function< vtkSmartPointer< vtkCellMetadata >(vtkCellGrid *)> MetadataConstructor