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 =========================================================================*/
155 #ifndef vtkSelection_h
156 #define vtkSelection_h
157 
158 #include "vtkCommonDataModelModule.h" // For export macro
159 #include "vtkDataObject.h"
160 #include "vtkSmartPointer.h" // for vtkSmartPointer.
161 
162 #include <memory> // for unique_ptr.
163 #include <string> // for string.
164 
165 class vtkSelectionNode;
166 class vtkSignedCharArray;
167 
168 class VTKCOMMONDATAMODEL_EXPORT vtkSelection : public vtkDataObject
169 {
170 public:
171  vtkTypeMacro(vtkSelection, vtkDataObject);
172  void PrintSelf(ostream& os, vtkIndent indent) override;
173  static vtkSelection* New();
174 
178  void Initialize() override;
179 
183  int GetDataObjectType() override { return VTK_SELECTION; }
184 
189  unsigned int GetNumberOfNodes() const;
190 
195  virtual vtkSelectionNode* GetNode(unsigned int idx) const;
196 
200  virtual vtkSelectionNode* GetNode(const std::string& name) const;
201 
208 
214  virtual void SetNode(const std::string& name, vtkSelectionNode*);
215 
219  virtual std::string GetNodeNameAtIndex(unsigned int idx) const;
220 
222 
225  virtual void RemoveNode(unsigned int idx);
226  virtual void RemoveNode(const std::string& name);
227  virtual void RemoveNode(vtkSelectionNode*);
229 
233  virtual void RemoveAllNodes();
234 
236 
247  vtkSetMacro(Expression, std::string);
248  vtkGetMacro(Expression, std::string);
250 
254  void DeepCopy(vtkDataObject* src) override;
255 
261  void ShallowCopy(vtkDataObject* src) override;
262 
268  virtual void Union(vtkSelection* selection);
269 
275  virtual void Union(vtkSelectionNode* node);
276 
281  virtual void Subtract(vtkSelection* selection);
282 
287  virtual void Subtract(vtkSelectionNode* node);
288 
292  vtkMTimeType GetMTime() override;
293 
295 
298  virtual void Dump();
299  virtual void Dump(ostream& os);
301 
303 
307  static vtkSelection* GetData(vtkInformationVector* v, int i = 0);
309 
317  vtkSignedCharArray* const* values, unsigned int num_values) const;
318 
323  template <typename MapType>
324  vtkSmartPointer<vtkSignedCharArray> Evaluate(const MapType& values_map) const;
325 
326 protected:
328  ~vtkSelection() override;
329 
331 
332 private:
333  vtkSelection(const vtkSelection&) = delete;
334  void operator=(const vtkSelection&) = delete;
335 
336  class vtkInternals;
337  vtkInternals* Internals;
338 };
339 
340 //----------------------------------------------------------------------------
341 template <typename MapType>
342 inline vtkSmartPointer<vtkSignedCharArray> vtkSelection::Evaluate(const MapType& values_map) const
343 {
344  const unsigned int num_nodes = this->GetNumberOfNodes();
345  std::unique_ptr<vtkSignedCharArray*[]> values(new vtkSignedCharArray*[num_nodes]);
346  for (unsigned int cc = 0; cc < num_nodes; ++cc)
347  {
348  auto iter = values_map.find(this->GetNodeNameAtIndex(cc));
349  values[cc] = iter != values_map.end() ? iter->second : nullptr;
350  }
351  return this->Evaluate(&values[0], num_nodes);
352 }
353 
354 #endif
general representation of visualization data
a simple class to control print indentation
Definition: vtkIndent.h:119
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:169
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.
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.
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.
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:330
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:183
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:382
@ name
Definition: vtkX3D.h:225
@ string
Definition: vtkX3D.h:496
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287
#define VTK_SELECTION
Definition: vtkType.h:99