VTK  9.7.20260912
vtkDataAssembly.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
107
108#ifndef vtkDataAssembly_h
109#define vtkDataAssembly_h
110
111#include "vtkCommonDataModelModule.h" // for export macros
112#include "vtkObject.h"
113
114#include <map> // for std::map
115#include <memory> // for std::unique_ptr
116#include <string> // for std::string
117#include <vector> // for std::vector
118
119VTK_ABI_NAMESPACE_BEGIN
121
122class VTKCOMMONDATAMODEL_EXPORT vtkDataAssembly : public vtkObject
123{
124public:
127 void PrintSelf(ostream& os, vtkIndent indent) override;
128
135
137
142 bool InitializeFromXML(const char* xmlcontents);
144
146
149 std::string SerializeToXML(vtkIndent indent) const;
151
156 static int GetRootNode() { return 0; }
157
159
162 void SetRootNodeName(const char* name)
163 {
165 }
166 const char* GetRootNodeName() const { return this->GetNodeName(vtkDataAssembly::GetRootNode()); }
168
177 int AddNode(const char* name, int parent = 0);
178
186 std::vector<int> AddNodes(const std::vector<std::string>& names, int parent = 0);
187
192 int AddSubtree(int parent, vtkDataAssembly* other, int otherParent = 0);
193
203 bool RemoveNode(int id);
204
206
213 void SetNodeName(int id, const char* name);
214 const char* GetNodeName(int id) const;
216
238 std::string GetNodePath(int id) const;
239
243 int GetFirstNodeByPath(const char* path) const;
244
253 int FindOrCreateNodeAtPath(const char* path, int parent = 0);
254
265 bool AddDataSetIndex(int id, unsigned int dataset_index);
266
273 bool AddDataSetIndices(int id, const std::vector<unsigned int>& dataset_indices);
274
281 bool AddDataSetIndexRange(int id, unsigned int index_start, int count);
282
288 bool RemoveDataSetIndex(int id, unsigned int dataset_index);
289
298 bool RemoveAllDataSetIndices(int id, bool traverse_subtree = true);
299
305
313 const char* name, int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
314
319 std::vector<int> FindNodesWithName(
320 const char* name, int sort_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
321
332 std::vector<int> GetChildNodes(int parent, bool traverse_subtree = true,
333 int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
334
341 int GetNumberOfChildren(int parent) const;
342
347 int GetChild(int parent, int index) const;
348
353 int GetChild(int parent, const char* name) const;
354
359 int GetChildIndex(int parent, int child) const;
360
365 int GetParent(int id) const;
366
371 bool HasAttribute(int id, const char* name) const;
372
374
378 void SetAttribute(int id, const char* name, const char* value);
379 void SetAttribute(int id, const char* name, int value);
380 void SetAttribute(int id, const char* name, unsigned int value);
381#if VTK_ID_TYPE_IMPL != VTK_INT
382 void SetAttribute(int id, const char* name, vtkIdType value);
383#endif
385
387
390 bool GetAttribute(int id, const char* name, const char*& value) const;
391 bool GetAttribute(int id, const char* name, int& value) const;
392 bool GetAttribute(int id, const char* name, unsigned int& value) const;
393#if VTK_ID_TYPE_IMPL != VTK_INT
394 bool GetAttribute(int id, const char* name, vtkIdType& value) const;
395#endif
397
399
403 const char* GetAttributeOrDefault(int id, const char* name, const char* default_value) const;
404 int GetAttributeOrDefault(int id, const char* name, int default_value) const;
405 unsigned int GetAttributeOrDefault(int id, const char* name, unsigned int default_value) const;
406#if VTK_ID_TYPE_IMPL != VTK_INT
407 vtkIdType GetAttributeOrDefault(int id, const char* name, vtkIdType default_value) const;
408#endif
410
412
417 int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const
418 {
419 this->Visit(0, visitor, traversal_order);
420 }
421 void Visit(int id, vtkDataAssemblyVisitor* visitor,
422 int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
424
426
438 std::vector<unsigned int> GetDataSetIndices(int id, bool traverse_subtree = true,
439 int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
440 std::vector<unsigned int> GetDataSetIndices(const std::vector<int>& ids,
441 bool traverse_subtree = true,
442 int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
444
454 std::vector<int> SelectNodes(const std::vector<std::string>& path_queries,
455 int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
456
463 const std::map<unsigned int, unsigned int>& mapping, bool remove_unmapped);
464
471 void SubsetCopy(vtkDataAssembly* other, const std::vector<int>& selected_branches);
472
477
481 static bool IsNodeNameValid(const char* name);
482
489 static std::string MakeValidNodeName(const char* name);
490
498 static bool IsNodeNameReserved(const char* name);
499
500protected:
503
504private:
505 vtkDataAssembly(const vtkDataAssembly&) = delete;
506 void operator=(const vtkDataAssembly&) = delete;
507
508 class vtkInternals;
509 std::unique_ptr<vtkInternals> Internals;
510};
511
512VTK_ABI_NAMESPACE_END
513#endif
visitor API for vtkDataAssembly
int GetParent(int id) const
Returns the id for the parent node, if any.
static int GetRootNode()
Returns the ID for the root node.
std::vector< int > GetChildNodes(int parent, bool traverse_subtree=true, int traversal_order=vtkDataAssembly::TraversalOrder::DepthFirst) const
Returns ids for all child nodes.
std::vector< int > FindNodesWithName(const char *name, int sort_order=vtkDataAssembly::TraversalOrder::DepthFirst) const
Finds all nodes with the given name.
bool GetAttribute(int id, const char *name, const char *&value) const
Get an attribute value.
bool InitializeFromXML(const char *xmlcontents)
Initializes a data-assembly using an XML representation of the assembly.
void SetAttribute(int id, const char *name, unsigned int value)
Set an attribute.
void DeepCopy(vtkDataAssembly *other)
Deep copy the other.
static bool IsNodeNameValid(const char *name)
Validates a node name.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void Visit(int id, vtkDataAssemblyVisitor *visitor, int traversal_order=vtkDataAssembly::TraversalOrder::DepthFirst) const
Visit each node in the assembly for processing.
int FindOrCreateNodeAtPath(const char *path, int parent=0)
Given a simple path (node names between separators, not a path query), return the matching node.
bool AddDataSetIndexRange(int id, unsigned int index_start, int count)
Same as AddDataSetIndices except this supports adding a contiguous range of dataset indices in one go...
bool GetAttribute(int id, const char *name, int &value) const
Get an attribute value.
bool AddDataSetIndex(int id, unsigned int dataset_index)
Add a dataset index to a node.
int GetNumberOfChildren(int parent) const
Returns the number of child nodes.
~vtkDataAssembly() override
static vtkDataAssembly * New()
std::vector< int > SelectNodes(const std::vector< std::string > &path_queries, int traversal_order=vtkDataAssembly::TraversalOrder::DepthFirst) const
Returns ids for nodes matching the path_queries.
static std::string MakeValidNodeName(const char *name)
Converts any string to a string that is a valid node name.
const char * GetNodeName(int id) const
Get/Set a node's name.
std::vector< unsigned int > GetDataSetIndices(int id, bool traverse_subtree=true, int traversal_order=vtkDataAssembly::TraversalOrder::DepthFirst) const
Returns the dataset indices associated with the node.
int FindFirstNodeWithName(const char *name, int traversal_order=vtkDataAssembly::TraversalOrder::DepthFirst) const
Finds first node that is encountered in a breadth first traversal of the assembly with the given name...
int GetChildIndex(int parent, int child) const
Returns the local index (position) of a specific child node under a given parent.
std::string SerializeToXML(vtkIndent indent) const
Saves the data-assembly as a XML.
void SubsetCopy(vtkDataAssembly *other, const std::vector< int > &selected_branches)
Create a deep-copy of other by only passing the chosen branches.
const char * GetRootNodeName() const
Get/Set root node name.
int AddNode(const char *name, int parent=0)
Adds a node to the assembly with the given name and returns its id.
bool AddDataSetIndices(int id, const std::vector< unsigned int > &dataset_indices)
Same as AddDataSetIndex except supports adding multiple dataset indices in one go.
std::vector< unsigned int > GetDataSetIndices(const std::vector< int > &ids, bool traverse_subtree=true, int traversal_order=vtkDataAssembly::TraversalOrder::DepthFirst) const
Returns the dataset indices associated with the node.
bool GetAttribute(int id, const char *name, unsigned int &value) const
Get an attribute value.
void SetAttribute(int id, const char *name, int value)
Set an attribute.
void SetNodeName(int id, const char *name)
Get/Set a node's name.
int GetFirstNodeByPath(const char *path) const
Return a node id given the path.
void Visit(vtkDataAssemblyVisitor *visitor, int traversal_order=vtkDataAssembly::TraversalOrder::DepthFirst) const
Visit each node in the assembly for processing.
const char * GetAttributeOrDefault(int id, const char *name, const char *default_value) const
Get an attribute value.
bool HasAttribute(int id, const char *name) const
Returns true if attribute with the given name is present on the chosen node.
bool RemapDataSetIndices(const std::map< unsigned int, unsigned int > &mapping, bool remove_unmapped)
Remap dataset indices.
void Initialize()
Initializes the data-assembly.
int GetAttributeOrDefault(int id, const char *name, int default_value) const
Get an attribute value.
void SetRootNodeName(const char *name)
Get/Set root node name.
int AddSubtree(int parent, vtkDataAssembly *other, int otherParent=0)
Add a subtree by copy the nodes from another tree starting with the specified parent index.
bool RemoveDataSetIndex(int id, unsigned int dataset_index)
Removes a dataset index from a node.
int GetChild(int parent, int index) const
Returns the unique ID of the child at the specified index under the given parent.
std::vector< int > AddNodes(const std::vector< std::string > &names, int parent=0)
Same as AddNode except allows adding multiple nodes in one go.
static bool IsNodeNameReserved(const char *name)
Returns true for node names that are reserved.
bool RemoveAllDataSetIndices(int id, bool traverse_subtree=true)
Clears all dataset indices from the node.
void SetAttribute(int id, const char *name, const char *value)
Set an attribute.
bool RemoveNode(int id)
Removes a node from the assembly.
unsigned int GetAttributeOrDefault(int id, const char *name, unsigned int default_value) const
Get an attribute value.
int GetChild(int parent, const char *name) const
Returns the unique ID of the first child with the specified name under the given parent.
std::string GetNodePath(int id) const
Returns the path for a node, suitable for use as a selector.
a simple class to control print indentation
Definition vtkIndent.h:108
int vtkIdType
Definition vtkType.h:363