VTK  9.4.20241218
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
143#ifndef vtkSelection_h
144#define vtkSelection_h
145
146#include "vtkCommonDataModelModule.h" // For export macro
147#include "vtkDataObject.h"
148#include "vtkSmartPointer.h" // for vtkSmartPointer.
149
150#include <array> // for array.
151#include <string> // for string.
152#include <vector> // for vector.
153
154VTK_ABI_NAMESPACE_BEGIN
155class vtkSelectionNode;
157
158class VTKCOMMONDATAMODEL_EXPORT vtkSelection : public vtkDataObject
159{
160public:
162 void PrintSelf(ostream& os, vtkIndent indent) override;
163 static vtkSelection* New();
164
168 void Initialize() override;
169
173 int GetDataObjectType() override { return VTK_SELECTION; }
174
179 unsigned int GetNumberOfNodes() const;
180
185 virtual vtkSelectionNode* GetNode(unsigned int idx) const;
186
190 virtual vtkSelectionNode* GetNode(const std::string& name) const;
191
197 virtual std::string AddNode(vtkSelectionNode*);
198
204 virtual void SetNode(const std::string& name, vtkSelectionNode*);
205
209 virtual std::string GetNodeNameAtIndex(unsigned int idx) const;
210
212
215 virtual void RemoveNode(unsigned int idx);
216 virtual void RemoveNode(const std::string& name);
219
223 virtual void RemoveAllNodes();
224
226
237 vtkSetMacro(Expression, std::string);
238 vtkGetMacro(Expression, std::string);
240
244 void DeepCopy(vtkDataObject* src) override;
245
251 void ShallowCopy(vtkDataObject* src) override;
252
258 virtual void Union(vtkSelection* selection);
259
265 virtual void Union(vtkSelectionNode* node);
266
271 virtual void Subtract(vtkSelection* selection);
272
277 virtual void Subtract(vtkSelectionNode* node);
278
283
285
288 virtual void Dump();
289 virtual void Dump(ostream& os);
291
293
299
301
308 vtkSignedCharArray* const* values, unsigned int num_values) const
309 {
310 std::array<signed char, 2> range;
311 return this->Evaluate(values, num_values, range);
312 }
314 unsigned int num_values, std::array<signed char, 2>& range) const;
316
318
322 template <typename MapType>
323 vtkSmartPointer<vtkSignedCharArray> Evaluate(const MapType& values_map) const
324 {
325 std::array<signed char, 2> range;
326 return this->Evaluate(values_map, range);
327 }
328 template <typename MapType>
330 const MapType& values_map, std::array<signed char, 2>& range) const;
332
333protected:
335 ~vtkSelection() override;
336
337 std::string Expression;
338
339private:
340 vtkSelection(const vtkSelection&) = delete;
341 void operator=(const vtkSelection&) = delete;
342
343 class vtkInternals;
344 vtkInternals* Internals;
345 struct EvaluateFunctor;
346};
347
348//----------------------------------------------------------------------------
349template <typename MapType>
351 const MapType& values_map, std::array<signed char, 2>& range) const
352{
353 const unsigned int num_nodes = this->GetNumberOfNodes();
354 std::vector<vtkSignedCharArray*> values(num_nodes, nullptr);
355 for (unsigned int cc = 0; cc < num_nodes; ++cc)
356 {
357 auto iter = values_map.find(this->GetNodeNameAtIndex(cc));
358 values[cc] = iter != values_map.end() ? iter->second : nullptr;
359 }
360 return this->Evaluate(values.data(), num_nodes, range);
361}
362
363VTK_ABI_NAMESPACE_END
364#endif
general representation of visualization data
a simple class to control print indentation
Definition vtkIndent.h:108
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.
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 and extracts the range.
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.
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.
vtkSmartPointer< vtkSignedCharArray > Evaluate(const MapType &values_map) const
Convenience method to pass a map of vtkSignedCharArray ptrs (or vtkSmartPointers) and range.
dynamic, self-adjusting array of signed char
Hold a reference to a vtkObjectBase instance.
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:270
#define VTK_SELECTION
Definition vtkType.h:87