VTK  9.4.20250206
vtkCellAttribute.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
17#ifndef vtkCellAttribute_h
18#define vtkCellAttribute_h
19
20#include "vtkCommonDataModelModule.h" // for export
21#include "vtkObject.h"
22#include "vtkScalarsToColors.h" // for colormap
23#include "vtkSmartPointer.h" // for maps
24#include "vtkStringToken.h" // for vtkStringToken::Hash
25
26#include <unordered_map>
27
28VTK_ABI_NAMESPACE_BEGIN
31class vtkCellGrid;
33
34class VTKCOMMONDATAMODEL_EXPORT vtkCellAttribute : public vtkObject
35{
36public:
38 using ArraysForCellType = std::unordered_map<vtkStringToken, vtkSmartPointer<vtkAbstractArray>>;
39
41 {
42 // The array-group name holding shared degree-of-freedom (DOF)
43 // data if the attribute is shared. This is invalid for
44 // discontinuous attributes
65 int Order;
71
73 template <typename ArrayType>
74 ArrayType* GetArrayForRoleAs(vtkStringToken role) const
75 {
76 auto it = this->ArraysByRole.find(role);
77 if (it == this->ArraysByRole.end())
78 {
79 return nullptr;
80 }
81 return ArrayType::SafeDownCast(it->second);
82 }
83
85 bool operator!=(const CellTypeInfo& other) const;
86
88 CellTypeInfo() = default;
89 CellTypeInfo(const CellTypeInfo& other) = default;
90 CellTypeInfo& operator=(const CellTypeInfo& other) = default;
91 };
92
93 using Arrays = std::unordered_map<vtkStringToken, CellTypeInfo>;
94
97 void PrintSelf(ostream& os, vtkIndent indent) override;
98
100 virtual vtkStringToken GetName() const { return this->Name; }
101
108 vtkGetMacro(Id, int);
109 vtkSetMacro(Id, int);
110
135 virtual vtkStringToken GetSpace() const { return this->Space; }
136
143 virtual int GetNumberOfComponents() const { return this->NumberOfComponents; }
144
152 virtual bool Initialize(vtkStringToken name, vtkStringToken space, int numberOfComponents);
153
160
166
173 vtkStringToken cellType, vtkStringToken arrayRole) const;
174
184 virtual bool SetCellTypeInfo(vtkStringToken cellType, const CellTypeInfo& cellTypeInfo);
185
187 vtkScalarsToColors* GetColormap() const { return this->Colormap; }
189
207 virtual void ShallowCopy(vtkCellAttribute* other, bool copyArrays = true);
208 virtual void DeepCopy(vtkCellAttribute* other,
209 const std::map<vtkAbstractArray*, vtkAbstractArray*>& arrayRewrites = {});
210
221 static bool DecodeSpace(
222 const std::string& space, std::string& base, double& exp, int& halfspace, bool quiet = false);
223
225 static std::string EncodeSpace(const std::string& base, unsigned int, int halfspace = 0);
226
227protected:
228 vtkCellAttribute() = default;
229 ~vtkCellAttribute() override = default;
230
233 int NumberOfComponents = 1;
235 int Id = -1;
237
238private:
239 vtkCellAttribute(const vtkCellAttribute&) = delete;
240 void operator=(const vtkCellAttribute&) = delete;
241};
242
243VTK_ABI_NAMESPACE_END
244#endif
Abstract superclass for all arrays.
A function defined over the physical domain of a vtkCellGrid.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void DeepCopy(vtkCellAttribute *other, const std::map< vtkAbstractArray *, vtkAbstractArray * > &arrayRewrites={})
virtual CellTypeInfo GetCellTypeInfo(vtkStringToken cellType) const
Return the arrays required to evaluate this attribute on cells of the given type.
virtual int GetNumberOfComponents() const
Return the number of components this function provides at each point in space.
virtual bool Initialize(vtkStringToken name, vtkStringToken space, int numberOfComponents)
Initialize an attribute.
vtkStringToken Space
~vtkCellAttribute() override=default
vtkCellAttribute()=default
vtkStringToken Name
static vtkCellAttribute * New()
virtual vtkStringToken GetSpace() const
Return a token identifying the space containing all field values.
virtual vtkStringToken::Hash GetHash() const
Hash this attribute so it can be inserted into unordered containers.
virtual bool SetCellTypeInfo(vtkStringToken cellType, const CellTypeInfo &cellTypeInfo)
Set the arrays required to evaluate this attribute on cells of the given type.
static std::string EncodeSpace(const std::string &base, unsigned int, int halfspace=0)
Return a space string given a description of it via base, exp, and halfspace.
virtual vtkStringToken GetName() const
Return the (user-presentable) name of this attribute.
bool SetColormap(vtkScalarsToColors *colormap)
vtkScalarsToColors * GetColormap() const
Return a default colormap associated with the attribute.
vtkSmartPointer< vtkScalarsToColors > Colormap
vtkAbstractArray * GetArrayForCellTypeAndRole(vtkStringToken cellType, vtkStringToken arrayRole) const
Return an array for the given cell type and role.
std::unordered_map< vtkStringToken, vtkSmartPointer< vtkAbstractArray > > ArraysForCellType
A dictionary of arrays indexed by their roles in interpolation.
static bool DecodeSpace(const std::string &space, std::string &base, double &exp, int &halfspace, bool quiet=false)
Given a space string (e.g., ℝ³⁻ or ℚ¹), decode the base (e.g., ℝ resp.
virtual void ShallowCopy(vtkCellAttribute *other, bool copyArrays=true)
Copy data from an other attribute instance into this instance.
std::unordered_map< vtkStringToken, CellTypeInfo > Arrays
Visualization data composed of cells of arbitrary type.
Definition vtkCellGrid.h:49
represent and manipulate attribute data in a dataset
a simple class to control print indentation
Definition vtkIndent.h:108
abstract base class for most VTK objects
Definition vtkObject.h:162
Superclass for mapping scalar values to colors.
Hold a reference to a vtkObjectBase instance.
Represent a string by its integer hash.
std::uint32_t Hash
ArraysForCellType ArraysByRole
A dictionary of arrays indexed by their roles in interpolation.
int Order
The interpolation order of the attribute on cells of the matching type.
vtkStringToken Basis
The interpolation scheme of the attribute on cells of the matching type.
bool operator!=(const CellTypeInfo &other) const
Comparator used to test inequality.
CellTypeInfo()=default
Explicitly include assignment and copy-construction.
ArrayType * GetArrayForRoleAs(vtkStringToken role) const
Return an array (or nullptr) given a role, cast to ArrayType.
vtkStringToken FunctionSpace
The function space used to interpolate values of the attribute on cells of the matching type.
CellTypeInfo(const CellTypeInfo &other)=default
CellTypeInfo & operator=(const CellTypeInfo &other)=default