VTK  9.3.0
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
43 #ifndef vtkSelection_h
44 #define vtkSelection_h
45 
46 #include "vtkCommonDataModelModule.h" // For export macro
47 #include "vtkDataObject.h"
48 #include "vtkSmartPointer.h" // for vtkSmartPointer.
49 
50 #include <array> // for array.
51 #include <string> // for string.
52 #include <vector> // for vector.
53 
54 VTK_ABI_NAMESPACE_BEGIN
55 class vtkSelectionNode;
56 class vtkSignedCharArray;
57 
58 class VTKCOMMONDATAMODEL_EXPORT vtkSelection : public vtkDataObject
59 {
60 public:
61  vtkTypeMacro(vtkSelection, vtkDataObject);
62  void PrintSelf(ostream& os, vtkIndent indent) override;
63  static vtkSelection* New();
64 
68  void Initialize() override;
69 
73  int GetDataObjectType() override { return VTK_SELECTION; }
74 
79  unsigned int GetNumberOfNodes() const;
80 
85  virtual vtkSelectionNode* GetNode(unsigned int idx) const;
86 
90  virtual vtkSelectionNode* GetNode(const std::string& name) const;
91 
98 
104  virtual void SetNode(const std::string& name, vtkSelectionNode*);
105 
109  virtual std::string GetNodeNameAtIndex(unsigned int idx) const;
110 
112 
115  virtual void RemoveNode(unsigned int idx);
116  virtual void RemoveNode(const std::string& name);
117  virtual void RemoveNode(vtkSelectionNode*);
119 
123  virtual void RemoveAllNodes();
124 
126 
137  vtkSetMacro(Expression, std::string);
138  vtkGetMacro(Expression, std::string);
140 
144  void DeepCopy(vtkDataObject* src) override;
145 
151  void ShallowCopy(vtkDataObject* src) override;
152 
158  virtual void Union(vtkSelection* selection);
159 
165  virtual void Union(vtkSelectionNode* node);
166 
171  virtual void Subtract(vtkSelection* selection);
172 
177  virtual void Subtract(vtkSelectionNode* node);
178 
182  vtkMTimeType GetMTime() override;
183 
185 
188  virtual void Dump();
189  virtual void Dump(ostream& os);
191 
193 
197  static vtkSelection* GetData(vtkInformationVector* v, int i = 0);
199 
201 
208  vtkSignedCharArray* const* values, unsigned int num_values) const
209  {
210  std::array<signed char, 2> range;
211  return this->Evaluate(values, num_values, range);
212  }
214  unsigned int num_values, std::array<signed char, 2>& range) const;
216 
218 
222  template <typename MapType>
223  vtkSmartPointer<vtkSignedCharArray> Evaluate(const MapType& values_map) const
224  {
225  std::array<signed char, 2> range;
226  return this->Evaluate(values_map, range);
227  }
228  template <typename MapType>
230  const MapType& values_map, std::array<signed char, 2>& range) const;
232 
233 protected:
235  ~vtkSelection() override;
236 
238 
239 private:
240  vtkSelection(const vtkSelection&) = delete;
241  void operator=(const vtkSelection&) = delete;
242 
243  class vtkInternals;
244  vtkInternals* Internals;
245  struct EvaluateFunctor;
246 };
247 
248 //----------------------------------------------------------------------------
249 template <typename MapType>
251  const MapType& values_map, std::array<signed char, 2>& range) const
252 {
253  const unsigned int num_nodes = this->GetNumberOfNodes();
254  std::vector<vtkSignedCharArray*> values(num_nodes, nullptr);
255  for (unsigned int cc = 0; cc < num_nodes; ++cc)
256  {
257  auto iter = values_map.find(this->GetNodeNameAtIndex(cc));
258  values[cc] = iter != values_map.end() ? iter->second : nullptr;
259  }
260  return this->Evaluate(values.data(), num_nodes, range);
261 }
262 
263 VTK_ABI_NAMESPACE_END
264 #endif
general representation of visualization data
Definition: vtkDataObject.h:64
a simple class to control print indentation
Definition: vtkIndent.h:38
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
a node in a vtkSelection the defines the selection criteria.
data object that represents a "selection" in VTK.
Definition: vtkSelection.h:59
virtual void RemoveNode(unsigned int idx)
Removes a selection node.
vtkMTimeType GetMTime() override
Return the MTime taking into account changes to the properties.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
unsigned int GetNumberOfNodes() const
Returns the number of nodes in this selection.
virtual void SetNode(const std::string &name, vtkSelectionNode *)
Adds a vtkSelectionNode and assigns it the specified name.
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:207
virtual void Union(vtkSelection *selection)
Union this selection with the specified selection.
virtual void RemoveNode(const std::string &name)
Removes a selection node.
static vtkSelection * GetData(vtkInformation *info)
Retrieve a vtkSelection stored inside an invormation 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:223
void DeepCopy(vtkDataObject *src) override
Copy selection nodes of the input.
virtual void Subtract(vtkSelection *selection)
Remove the nodes from the specified selection from this selection.
virtual void Union(vtkSelectionNode *node)
Union this selection with the specified selection node.
vtkSmartPointer< vtkSignedCharArray > Evaluate(vtkSignedCharArray *const *values, unsigned int num_values, std::array< signed char, 2 > &range) const
Evaluates the expression for each element in the values and extracts the range.
void ShallowCopy(vtkDataObject *src) override
Copy selection nodes of the input.
virtual vtkSelectionNode * GetNode(unsigned int idx) const
Returns a node given it's index.
~vtkSelection() override
virtual void Subtract(vtkSelectionNode *node)
Remove the nodes from the specified selection from this selection.
virtual vtkSelectionNode * GetNode(const std::string &name) const
Returns a node with the given name, if present, else nullptr is returned.
void Initialize() override
Restore data object to initial state,.
std::string Expression
Definition: vtkSelection.h:237
virtual std::string GetNodeNameAtIndex(unsigned int idx) const
Returns the name for a node at the given index.
virtual void Dump()
Dumps the contents of the selection, giving basic information only.
int GetDataObjectType() override
Returns VTK_SELECTION enumeration value.
Definition: vtkSelection.h:73
virtual void Dump(ostream &os)
Dumps the contents of the selection, giving basic information only.
virtual std::string AddNode(vtkSelectionNode *)
Adds a selection node.
static vtkSelection * New()
static vtkSelection * GetData(vtkInformationVector *v, int i=0)
Retrieve a vtkSelection stored inside an invormation object.
virtual void RemoveAllNodes()
Removes all selection nodes.
virtual void RemoveNode(vtkSelectionNode *)
Removes a selection node.
dynamic, self-adjusting array of signed char
@ info
Definition: vtkX3D.h:376
@ range
Definition: vtkX3D.h:238
@ name
Definition: vtkX3D.h:219
@ string
Definition: vtkX3D.h:490
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:270
#define VTK_SELECTION
Definition: vtkType.h:87