VTK  9.4.20241221
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
46VTK_ABI_NAMESPACE_BEGIN
47class vtkCellGrid;
51
52class VTKCOMMONDATAMODEL_EXPORT vtkCellMetadata : public vtkObject
53{
54public:
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
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
133
141 virtual void ShallowCopy(vtkCellMetadata* vtkNotUsed(other)) {}
142 virtual void DeepCopy(vtkCellMetadata* vtkNotUsed(other)) {}
143
146
148 static void ClearResponders();
149
158
159protected:
160 vtkCellMetadata() = default;
162
163 vtkCellGrid* CellGrid{ nullptr };
164
166
167private:
168 vtkCellMetadata(const vtkCellMetadata&) = delete;
169 void operator=(const vtkCellMetadata&) = delete;
170};
171
172VTK_ABI_NAMESPACE_END
173#endif
A function defined over the physical domain of a vtkCellGrid.
Perform an operation on cells in a vtkCellMetadata instance.
A container that holds objects able to respond to queries specialized for particular vtkCellMetadata ...
Visualization data composed of cells of arbitrary type.
Definition vtkCellGrid.h:49
Metadata for a particular type of cell (finite element).
static vtkSmartPointer< Subclass > NewInstance(vtkCellGrid *grid=nullptr)
virtual bool SetCellGrid(vtkCellGrid *parent)
Set the vtkCellGrid holding DOF arrays required by this cell.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
bool Query(vtkCellGridQuery *query)
Respond to a query on cells of this type.
~vtkCellMetadata() override
static bool RegisterType()
Register a subclass of vtkCellMetadata.
static ConstructorMap & Constructors()
vtkStringToken::Hash CellTypeId
virtual void DeepCopy(vtkCellMetadata *vtkNotUsed(other))
vtkCellMetadata * NewInstance() const
static vtkCellGridResponders * GetResponders()
Return the set of registered responder types.
std::function< vtkSmartPointer< vtkCellMetadata >(vtkCellGrid *)> MetadataConstructor
static void ClearResponders()
Clear all of the registered responders.
vtkCellGridResponders * GetCaches()
Return the set of registered responder types.
vtkCellMetadata()=default
std::unordered_map< vtkStringToken, MetadataConstructor > ConstructorMap
virtual void ShallowCopy(vtkCellMetadata *vtkNotUsed(other))
Copy other into this instance (which must be of the same type).
static vtkSmartPointer< vtkCellMetadata > NewInstance(vtkStringToken className, vtkCellGrid *grid=nullptr)
static std::unordered_set< vtkStringToken > CellTypes()
virtual vtkIdType GetNumberOfCells()
Return the number of cells of this type in the parent cell-grid object.
CellTypeId Hash()
Return a hash of the cell type.
vtkInheritanceHierarchyBaseMacro(vtkCellMetadata)
represent and manipulate attribute data in a dataset
a simple class to control print indentation
Definition vtkIndent.h:108
const char * GetClassName() const
Return the class name as a string.
abstract base class for most VTK objects
Definition vtkObject.h:162
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
Hash GetId() const
Return the token's ID (usually its hash but possibly not in the case of collisions).
int vtkIdType
Definition vtkType.h:315