VTK  9.2.6
vtkSelection.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkSelection.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm 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 =========================================================================*/
46 #ifndef vtkSelection_h
47 #define vtkSelection_h
48 
49 #include "vtkCommonDataModelModule.h" // For export macro
50 #include "vtkDataObject.h"
51 #include "vtkSmartPointer.h" // for vtkSmartPointer.
52 
53 #include <memory> // for unique_ptr.
54 #include <string> // for string.
55 
56 class vtkSelectionNode;
57 class vtkSignedCharArray;
58 
59 class VTKCOMMONDATAMODEL_EXPORT vtkSelection : public vtkDataObject
60 {
61 public:
62  vtkTypeMacro(vtkSelection, vtkDataObject);
63  void PrintSelf(ostream& os, vtkIndent indent) override;
64  static vtkSelection* New();
65 
69  void Initialize() override;
70 
74  int GetDataObjectType() override { return VTK_SELECTION; }
75 
80  unsigned int GetNumberOfNodes() const;
81 
86  virtual vtkSelectionNode* GetNode(unsigned int idx) const;
87 
91  virtual vtkSelectionNode* GetNode(const std::string& name) const;
92 
98  virtual std::string AddNode(vtkSelectionNode*);
99 
105  virtual void SetNode(const std::string& name, vtkSelectionNode*);
106 
110  virtual std::string GetNodeNameAtIndex(unsigned int idx) const;
111 
113 
116  virtual void RemoveNode(unsigned int idx);
117  virtual void RemoveNode(const std::string& name);
118  virtual void RemoveNode(vtkSelectionNode*);
120 
124  virtual void RemoveAllNodes();
125 
127 
138  vtkSetMacro(Expression, std::string);
139  vtkGetMacro(Expression, std::string);
141 
145  void DeepCopy(vtkDataObject* src) override;
146 
152  void ShallowCopy(vtkDataObject* src) override;
153 
159  virtual void Union(vtkSelection* selection);
160 
166  virtual void Union(vtkSelectionNode* node);
167 
172  virtual void Subtract(vtkSelection* selection);
173 
178  virtual void Subtract(vtkSelectionNode* node);
179 
183  vtkMTimeType GetMTime() override;
184 
186 
189  virtual void Dump();
190  virtual void Dump(ostream& os);
192 
194 
198  static vtkSelection* GetData(vtkInformationVector* v, int i = 0);
200 
208  vtkSignedCharArray* const* values, unsigned int num_values) const;
209 
214  template <typename MapType>
215  vtkSmartPointer<vtkSignedCharArray> Evaluate(const MapType& values_map) const;
216 
217 protected:
218  vtkSelection();
219  ~vtkSelection() override;
220 
222 
223 private:
224  vtkSelection(const vtkSelection&) = delete;
225  void operator=(const vtkSelection&) = delete;
226 
227  class vtkInternals;
228  vtkInternals* Internals;
229 };
230 
231 //----------------------------------------------------------------------------
232 template <typename MapType>
233 inline vtkSmartPointer<vtkSignedCharArray> vtkSelection::Evaluate(const MapType& values_map) const
234 {
235  const unsigned int num_nodes = this->GetNumberOfNodes();
236  std::unique_ptr<vtkSignedCharArray*[]> values(new vtkSignedCharArray*[num_nodes]);
237  for (unsigned int cc = 0; cc < num_nodes; ++cc)
238  {
239  auto iter = values_map.find(this->GetNodeNameAtIndex(cc));
240  values[cc] = iter != values_map.end() ? iter->second : nullptr;
241  }
242  return this->Evaluate(&values[0], num_nodes);
243 }
244 
245 #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:287
data object that represents a "selection" in VTK.
Definition: vtkSelection.h:59
std::string Expression
Definition: vtkSelection.h:221
virtual void Initialize()
Restore data object to initial state,.
vtkSmartPointer< vtkSignedCharArray > Evaluate(vtkSignedCharArray *const *values, unsigned int num_values) const
Evaluates the expression for each element in the values.
int GetDataObjectType() override
Returns VTK_SELECTION enumeration value.
Definition: vtkSelection.h:74
#define VTK_SELECTION
Definition: vtkType.h:99
a simple class to control print indentation
Definition: vtkIndent.h:39
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.
general representation of visualization data
Definition: vtkDataObject.h:65
virtual void DeepCopy(vtkDataObject *src)
Shallow and Deep copy.
virtual void ShallowCopy(vtkDataObject *src)
Shallow and Deep copy.