VTK  9.0.1
vtkSelection.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: vtkSelection.h
5 
6  Copyright (c) Kitware, Inc.
7  All rights reserved.
8  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
44 #ifndef vtkSelection_h
45 #define vtkSelection_h
46 
47 #include "vtkCommonDataModelModule.h" // For export macro
48 #include "vtkDataObject.h"
49 #include "vtkSmartPointer.h" // for vtkSmartPointer.
50 
51 #include <memory> // for unique_ptr.
52 #include <string> // for string.
53 
54 class vtkSelectionNode;
55 class vtkSignedCharArray;
56 
57 class VTKCOMMONDATAMODEL_EXPORT vtkSelection : public vtkDataObject
58 {
59 public:
60  vtkTypeMacro(vtkSelection, vtkDataObject);
61  void PrintSelf(ostream& os, vtkIndent indent) override;
62  static vtkSelection* New();
63 
67  void Initialize() override;
68 
72  int GetDataObjectType() override { return VTK_SELECTION; }
73 
78  unsigned int GetNumberOfNodes() const;
79 
84  virtual vtkSelectionNode* GetNode(unsigned int idx) const;
85 
89  virtual vtkSelectionNode* GetNode(const std::string& name) const;
90 
96  virtual std::string AddNode(vtkSelectionNode*);
97 
103  virtual void SetNode(const std::string& name, vtkSelectionNode*);
104 
108  virtual std::string GetNodeNameAtIndex(unsigned int idx) const;
109 
111 
114  virtual void RemoveNode(unsigned int idx);
115  virtual void RemoveNode(const std::string& name);
116  virtual void RemoveNode(vtkSelectionNode*);
118 
122  virtual void RemoveAllNodes();
123 
125 
136  vtkSetMacro(Expression, std::string);
137  vtkGetMacro(Expression, std::string);
139 
143  void DeepCopy(vtkDataObject* src) override;
144 
150  void ShallowCopy(vtkDataObject* src) override;
151 
157  virtual void Union(vtkSelection* selection);
158 
164  virtual void Union(vtkSelectionNode* node);
165 
170  virtual void Subtract(vtkSelection* selection);
171 
176  virtual void Subtract(vtkSelectionNode* node);
177 
181  vtkMTimeType GetMTime() override;
182 
184 
187  virtual void Dump();
188  virtual void Dump(ostream& os);
190 
192 
196  static vtkSelection* GetData(vtkInformationVector* v, int i = 0);
198 
206  vtkSignedCharArray* const* values, unsigned int num_values) const;
207 
212  template <typename MapType>
213  vtkSmartPointer<vtkSignedCharArray> Evaluate(const MapType& values_map) const;
214 
215 protected:
216  vtkSelection();
217  ~vtkSelection() override;
218 
220 
221 private:
222  vtkSelection(const vtkSelection&) = delete;
223  void operator=(const vtkSelection&) = delete;
224 
225  class vtkInternals;
226  vtkInternals* Internals;
227 };
228 
229 //----------------------------------------------------------------------------
230 template <typename MapType>
231 inline vtkSmartPointer<vtkSignedCharArray> vtkSelection::Evaluate(const MapType& values_map) const
232 {
233  const unsigned int num_nodes = this->GetNumberOfNodes();
234  std::unique_ptr<vtkSignedCharArray*[]> values(new vtkSignedCharArray*[num_nodes]);
235  for (unsigned int cc = 0; cc < num_nodes; ++cc)
236  {
237  auto iter = values_map.find(this->GetNodeNameAtIndex(cc));
238  values[cc] = iter != values_map.end() ? iter->second : nullptr;
239  }
240  return this->Evaluate(&values[0], num_nodes);
241 }
242 
243 #endif
A node in a selection tree.
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.
virtual std::string GetNodeNameAtIndex(unsigned int idx) const
Returns the name for a node at the given index.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:293
unsigned int GetNumberOfNodes() const
Returns the number of nodes in this selection.
data object that represents a "selection" in VTK.
Definition: vtkSelection.h:57
std::string Expression
Definition: vtkSelection.h:219
virtual void Initialize()
Restore data object to initial state,.
Hold a reference to a vtkObjectBase instance.
Definition: vtkMeta.h:32
int GetDataObjectType() override
Returns VTK_SELECTION enumeration value.
Definition: vtkSelection.h:72
#define VTK_SELECTION
Definition: vtkType.h:107
a simple class to control print indentation
Definition: vtkIndent.h:33
dynamic, self-adjusting array of signed char
vtkSmartPointer< vtkSignedCharArray > Evaluate(vtkSignedCharArray *const *values, unsigned int num_values) const
Evaluates the expression for each element in the values.
Store zero or more vtkInformation instances.
vtkMTimeType GetMTime() override
Data objects are composite objects and need to check each part for MTime.
general representation of visualization data
Definition: vtkDataObject.h:59
virtual void DeepCopy(vtkDataObject *src)
Shallow and Deep copy.
virtual void ShallowCopy(vtkDataObject *src)
Shallow and Deep copy.