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=========================================================================*/
45
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
58
59class VTKCOMMONDATAMODEL_EXPORT vtkSelection : public vtkDataObject
60{
61public:
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);
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
184
186
189 virtual void Dump();
190 virtual void Dump(ostream& os);
192
194
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
217protected:
219 ~vtkSelection() override;
220
221 std::string Expression;
222
223private:
224 vtkSelection(const vtkSelection&) = delete;
225 void operator=(const vtkSelection&) = delete;
226
227 class vtkInternals;
228 vtkInternals* Internals;
229};
230
231//----------------------------------------------------------------------------
232template <typename MapType>
233inline 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 simple class to control print indentation
Definition vtkIndent.h:40
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
a node in a vtkSelection the defines the selection criteria.
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.
static vtkSelection * GetData(vtkInformationVector *v, int i=0)
Retrieve a vtkSelection stored inside an invormation object.
virtual vtkSelectionNode * GetNode(unsigned int idx) const
Returns a node given it's index.
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.
virtual void Union(vtkSelection *selection)
Union this selection with the specified selection.
virtual void RemoveNode(const std::string &name)
Removes a selection node.
virtual vtkSelectionNode * GetNode(const std::string &name) const
Returns a node with the given name, if present, else nullptr is returned.
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.
static vtkSelection * New()
void ShallowCopy(vtkDataObject *src) override
Copy selection nodes of the input.
~vtkSelection() override
virtual void Subtract(vtkSelectionNode *node)
Remove the nodes from the specified selection from this selection.
void Initialize() override
Restore data object to initial state,.
std::string Expression
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.
virtual void Dump(ostream &os)
Dumps the contents of the selection, giving basic information only.
virtual std::string AddNode(vtkSelectionNode *)
Adds a selection node.
vtkSmartPointer< vtkSignedCharArray > Evaluate(vtkSignedCharArray *const *values, unsigned int num_values) const
Evaluates the expression for each element in the values.
static vtkSelection * GetData(vtkInformation *info)
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
Hold a reference to a vtkObjectBase instance.
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:287
#define VTK_SELECTION
Definition vtkType.h:99