VTK  9.7.1
vtkSelection.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
34 #ifndef vtkSelection_h
35 #define vtkSelection_h
36 
37 #include "vtkCommonDataModelModule.h" // For export macro
38 #include "vtkDataObject.h"
39 #include "vtkSmartPointer.h" // for vtkSmartPointer.
40 
41 #include <array> // for array.
42 #include <string> // for string.
43 #include <vector> // for vector.
44 
45 VTK_ABI_NAMESPACE_BEGIN
46 class vtkSelectionNode;
47 class vtkSignedCharArray;
48 
49 class VTKCOMMONDATAMODEL_EXPORT vtkSelection : public vtkDataObject
50 {
51 public:
52  vtkTypeMacro(vtkSelection, vtkDataObject);
53  void PrintSelf(ostream& os, vtkIndent indent) override;
54  static vtkSelection* New();
55 
59  void Initialize() override;
60 
64  int GetDataObjectType() VTK_FUTURE_CONST override { return VTK_SELECTION; }
65 
70  unsigned int GetNumberOfNodes() const;
71 
76  virtual vtkSelectionNode* GetNode(unsigned int idx) const;
77 
81  virtual vtkSelectionNode* GetNode(const std::string& name) const;
82 
88  virtual std::string AddNode(vtkSelectionNode*);
89 
95  virtual void SetNode(const std::string& name, vtkSelectionNode*);
96 
100  virtual std::string GetNodeNameAtIndex(unsigned int idx) const;
101 
103 
106  virtual void RemoveNode(unsigned int idx);
107  virtual void RemoveNode(const std::string& name);
108  virtual void RemoveNode(vtkSelectionNode*);
110 
114  virtual void RemoveAllNodes();
115 
117 
128  vtkSetMacro(Expression, std::string);
129  vtkGetMacro(Expression, std::string);
131 
135  void DeepCopy(vtkDataObject* src) override;
136 
142  void ShallowCopy(vtkDataObject* src) override;
143 
149  virtual void Union(vtkSelection* selection);
150 
156  virtual void Union(vtkSelectionNode* node);
157 
162  virtual void Subtract(vtkSelection* selection);
163 
168  virtual void Subtract(vtkSelectionNode* node);
169 
173  vtkMTimeType GetMTime() override;
174 
176 
179  virtual void Dump();
180  virtual void Dump(ostream& os);
182 
184 
188  static vtkSelection* GetData(vtkInformationVector* v, int i = 0);
190 
192 
199  vtkSignedCharArray* const* values, unsigned int num_values) const
200  {
201  std::array<signed char, 2> range;
202  return this->Evaluate(values, num_values, range);
203  }
205  unsigned int num_values, std::array<signed char, 2>& range) const;
207 
209 
213  template <typename MapType>
214  vtkSmartPointer<vtkSignedCharArray> Evaluate(const MapType& values_map) const
215  {
216  std::array<signed char, 2> range;
217  return this->Evaluate(values_map, range);
218  }
219  template <typename MapType>
221  const MapType& values_map, std::array<signed char, 2>& range) const;
223 
224 protected:
225  vtkSelection();
226  ~vtkSelection() override;
227 
229 
230 private:
231  vtkSelection(const vtkSelection&) = delete;
232  void operator=(const vtkSelection&) = delete;
233 
234  class vtkInternals;
235  vtkInternals* Internals;
236  struct EvaluateFunctor;
237 };
238 
239 //----------------------------------------------------------------------------
240 template <typename MapType>
242  const MapType& values_map, std::array<signed char, 2>& range) const
243 {
244  const unsigned int num_nodes = this->GetNumberOfNodes();
245  std::vector<vtkSignedCharArray*> values(num_nodes, nullptr);
246  for (unsigned int cc = 0; cc < num_nodes; ++cc)
247  {
248  auto iter = values_map.find(this->GetNodeNameAtIndex(cc));
249  values[cc] = iter != values_map.end() ? iter->second : nullptr;
250  }
251  return this->Evaluate(values.data(), num_nodes, range);
252 }
253 
254 VTK_ABI_NAMESPACE_END
255 #endif
a node in a vtkSelection the defines the selection criteria.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static vtkDataObject * GetData(vtkInformation *info)
Retrieve an instance of this class from an information object.
static vtkDataObject * New()
Store vtkAlgorithm input/output information.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:318
data object that represents a "selection" in VTK.
Definition: vtkSelection.h:49
std::string Expression
Definition: vtkSelection.h:228
virtual void Initialize()
Restore data object to initial state,.
Hold a reference to a vtkObjectBase instance.
Definition: vtkMeta.h:23
vtkSmartPointer< vtkSignedCharArray > Evaluate(vtkSignedCharArray *const *values, unsigned int num_values) const
Evaluates the expression for each element in the values and extracts the range.
Definition: vtkSelection.h:198
a simple class to control print indentation
Definition: vtkIndent.h:28
dynamic, self-adjusting array of signed char
unsigned int GetNumberOfNodes() const
Returns the number of nodes in this selection.
virtual std::string GetNodeNameAtIndex(unsigned int idx) const
Returns the name for a node at the given index.
Store zero or more vtkInformation instances.
vtkMTimeType GetMTime() override
Data objects are composite objects and need to check each part for MTime.
int GetDataObjectType() VTK_FUTURE_CONST override
Returns VTK_SELECTION enumeration value.
Definition: vtkSelection.h:64
general representation of visualization data
Definition: vtkDataObject.h:55
virtual void DeepCopy(vtkDataObject *src)
The goal of the method is to copy the complete data from src into this object.
vtkSmartPointer< vtkSignedCharArray > Evaluate(const MapType &values_map) const
Convenience method to pass a map of vtkSignedCharArray ptrs (or vtkSmartPointers) and range...
Definition: vtkSelection.h:214
virtual void ShallowCopy(vtkDataObject *src)
The goal of the method is to copy the data up to the array pointers only.