VTK  9.3.20240916
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
24#ifndef vtkCellMetadata_h
25#define vtkCellMetadata_h
26
27#include "vtkCellGridResponders.h" // For ivar.
28#include "vtkCommonDataModelModule.h" // for export macro
29#include "vtkInherits.h" // for vtk::Inherits<>()
30#include "vtkNew.h" // for queries
31#include "vtkObject.h"
32#include "vtkSmartPointer.h" // for constructor return values
33#include "vtkStringToken.h" // for vtkStringToken::Hash
34#include "vtkTypeName.h" // for vtk::TypeName<>()
35
36#include <functional>
37#include <set>
38#include <unordered_map>
39#include <unordered_set>
40
41VTK_ABI_NAMESPACE_BEGIN
42class vtkCellGrid;
46
47class VTKCOMMONDATAMODEL_EXPORT vtkCellMetadata : public vtkObject
48{
49public:
52 using MetadataConstructor = std::function<vtkSmartPointer<vtkCellMetadata>(vtkCellGrid*)>;
53 using ConstructorMap = std::unordered_map<vtkStringToken, MetadataConstructor>;
54
55 vtkTypeMacro(vtkCellMetadata, vtkObject);
57 void PrintSelf(ostream& os, vtkIndent indent) override;
58
62 template <typename Subclass>
63 static bool RegisterType()
64 {
65 vtkStringToken name = vtk::TypeName<Subclass>();
66 auto status =
67 vtkCellMetadata::Constructors().insert(std::make_pair(name, [](vtkCellGrid* grid) {
68 auto result = vtkSmartPointer<Subclass>::New();
69 if (result)
70 {
71 result->SetCellGrid(grid);
72 }
73 return result;
74 }));
75 return status.second; // true if insertion occurred.
76 }
77
78 template <typename Subclass>
80 {
81 vtkStringToken name = vtk::TypeName<Subclass>();
82 auto metadata = vtkCellMetadata::NewInstance(name, grid);
83 vtkSmartPointer<Subclass> result(Subclass::SafeDownCast(metadata));
84 return result;
85 }
86
88 vtkStringToken className, vtkCellGrid* grid = nullptr);
89
90 static std::unordered_set<vtkStringToken> CellTypes();
91
99
110 virtual bool SetCellGrid(vtkCellGrid* parent);
111
113 vtkGetObjectMacro(CellGrid, vtkCellGrid);
114
117 virtual vtkIdType GetNumberOfCells() { return 0; }
118
127
135 virtual void ShallowCopy(vtkCellMetadata* vtkNotUsed(other)) {}
136 virtual void DeepCopy(vtkCellMetadata* vtkNotUsed(other)) {}
137
140
142 static void ClearResponders();
143
152
153protected:
154 vtkCellMetadata() = default;
156
157 vtkCellGrid* CellGrid{ nullptr };
158
160
161private:
162 vtkCellMetadata(const vtkCellMetadata&) = delete;
163 void operator=(const vtkCellMetadata&) = delete;
164};
165
166VTK_ABI_NAMESPACE_END
167#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:46
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