VTK  9.7.1
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 
28 VTK_ABI_NAMESPACE_BEGIN
29 class vtkAbstractArray;
30 class vtkCellAttribute;
31 class vtkCellGrid;
33 
34 class VTKCOMMONDATAMODEL_EXPORT vtkCellAttribute : public vtkObject
35 {
36 public:
38  using ArraysForCellType = std::unordered_map<vtkStringToken, vtkSmartPointer<vtkAbstractArray>>;
39 
40  struct CellTypeInfo
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 
95  vtkTypeMacro(vtkCellAttribute, vtkObject);
96  static vtkCellAttribute* New();
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 
159  virtual vtkStringToken::Hash GetHash() const;
160 
165  virtual CellTypeInfo GetCellTypeInfo(vtkStringToken cellType) const;
166 
172  vtkAbstractArray* GetArrayForCellTypeAndRole(
173  vtkStringToken cellType, vtkStringToken arrayRole) const;
174 
184  virtual bool SetCellTypeInfo(vtkStringToken cellType, const CellTypeInfo& cellTypeInfo);
185 
187  vtkScalarsToColors* GetColormap() const { return this->Colormap; }
188  bool SetColormap(vtkScalarsToColors* 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 
227 protected:
228  vtkCellAttribute() = default;
229  ~vtkCellAttribute() override = default;
230 
233  int NumberOfComponents = 1;
235  int Id = -1;
237 
238 private:
239  vtkCellAttribute(const vtkCellAttribute&) = delete;
240  void operator=(const vtkCellAttribute&) = delete;
241 };
242 
243 VTK_ABI_NAMESPACE_END
244 #endif
virtual vtkStringToken GetName() const
Return the (user-presentable) name of this attribute.
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.
std::unordered_map< vtkStringToken, vtkSmartPointer< vtkAbstractArray >> ArraysForCellType
A dictionary of arrays indexed by their roles in interpolation.
vtkSmartPointer< vtkScalarsToColors > Colormap
Abstract superclass for all arrays.
virtual int GetNumberOfComponents() const
Return the number of components this function provides at each point in space.
std::unordered_map< vtkStringToken, CellTypeInfo > Arrays
virtual vtkStringToken GetSpace() const
Return a token identifying the space containing all field values.
Superclass for mapping scalar values to colors.
vtkStringToken FunctionSpace
The function space used to interpolate values of the attribute on cells of the matching type...
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
A function defined over the physical domain of a vtkCellGrid.
bool VTKCOMMONCORE_EXPORT operator!=(const std::string &a, const vtkStringToken &b)
vtkStringToken Name
vtkStringToken Basis
The interpolation scheme of the attribute on cells of the matching type.
represent and manipulate attribute data in a dataset
Represent a string by its integer hash.
ArrayType * GetArrayForRoleAs(vtkStringToken role) const
Return an array (or nullptr) given a role, cast to ArrayType.
vtkScalarsToColors * GetColormap() const
Return a default colormap associated with the attribute.
int Order
The interpolation order of the attribute on cells of the matching type.
vtkStringToken Space
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
ArraysForCellType ArraysByRole
A dictionary of arrays indexed by their roles in interpolation.