VTK  9.3.0
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 "vtkNew.h" // for queries
30#include "vtkObject.h"
31#include "vtkSmartPointer.h" // for constructor return values
32#include "vtkStringToken.h" // for vtkStringToken::Hash
33#include "vtkTypeName.h" // for vtk::TypeName<>()
34
35#include <functional>
36#include <set>
37#include <unordered_map>
38
39VTK_ABI_NAMESPACE_BEGIN
40class vtkCellGrid;
44
45class VTKCOMMONDATAMODEL_EXPORT vtkCellMetadata : public vtkObject
46{
47public:
50 using MetadataConstructor = std::function<vtkSmartPointer<vtkCellMetadata>(vtkCellGrid*)>;
51 using ConstructorMap = std::unordered_map<vtkStringToken, MetadataConstructor>;
52
53 vtkTypeMacro(vtkCellMetadata, vtkObject);
54 void PrintSelf(ostream& os, vtkIndent indent) override;
55
59 template <typename Subclass>
60 static bool RegisterType()
61 {
62 vtkStringToken name = vtk::TypeName<Subclass>();
63 auto status = vtkCellMetadata::Constructors.insert(std::make_pair(name, [](vtkCellGrid* grid) {
64 auto result = vtkSmartPointer<Subclass>::New();
65 if (result)
66 {
67 result->SetCellGrid(grid);
68 }
69 return result;
70 }));
71 return status.second; // true if insertion occurred.
72 }
73
74 template <typename Subclass>
76 {
77 vtkStringToken name = vtk::TypeName<Subclass>();
78 auto metadata = vtkCellMetadata::NewInstance(name, grid);
79 vtkSmartPointer<Subclass> result(Subclass::SafeDownCast(metadata));
80 return result;
81 }
82
84 vtkStringToken className, vtkCellGrid* grid = nullptr);
85
93
104 virtual bool SetCellGrid(vtkCellGrid* parent);
105
107 vtkGetObjectMacro(CellGrid, vtkCellGrid);
108
111 virtual vtkIdType GetNumberOfCells() { return 0; }
112
121
129 virtual void ShallowCopy(vtkCellMetadata* vtkNotUsed(other)) {}
130 virtual void DeepCopy(vtkCellMetadata* vtkNotUsed(other)) {}
131
134
135protected:
136 vtkCellMetadata() = default;
138
139 vtkCellGrid* CellGrid{ nullptr };
140
143
144private:
145 vtkCellMetadata(const vtkCellMetadata&) = delete;
146 void operator=(const vtkCellMetadata&) = delete;
147};
148
149VTK_ABI_NAMESPACE_END
150#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:42
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.
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
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 ConstructorMap Constructors
static vtkSmartPointer< vtkCellMetadata > NewInstance(vtkStringToken className, vtkCellGrid *grid=nullptr)
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.
static vtkNew< vtkCellGridResponders > Responders
represent and manipulate attribute data in a dataset
a simple class to control print indentation
Definition vtkIndent.h:29
Allocate and hold a VTK object.
Definition vtkNew.h:51
const char * GetClassName() const
Return the class name as a string.
abstract base class for most VTK objects
Definition vtkObject.h:49
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