VTK  9.7.1
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
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 
119 VTK_ABI_NAMESPACE_BEGIN
121 
122 class VTKCOMMONDATAMODEL_EXPORT vtkDataAssembly : public vtkObject
123 {
124 public:
125  static vtkDataAssembly* New();
126  vtkTypeMacro(vtkDataAssembly, vtkObject);
127  void PrintSelf(ostream& os, vtkIndent indent) override;
128 
134  void Initialize();
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  {
164  this->SetNodeName(vtkDataAssembly::GetRootNode(), name);
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 
220  std::string GetNodePath(int id) const;
221 
225  int GetFirstNodeByPath(const char* path) const;
226 
235  int FindOrCreateNodeAtPath(const char* path, int parent = 0);
236 
247  bool AddDataSetIndex(int id, unsigned int dataset_index);
248 
255  bool AddDataSetIndices(int id, const std::vector<unsigned int>& dataset_indices);
256 
263  bool AddDataSetIndexRange(int id, unsigned int index_start, int count);
264 
270  bool RemoveDataSetIndex(int id, unsigned int dataset_index);
271 
280  bool RemoveAllDataSetIndices(int id, bool traverse_subtree = true);
281 
283  {
284  DepthFirst = 0,
285  BreadthFirst
286  };
287 
294  int FindFirstNodeWithName(
295  const char* name, int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
296 
301  std::vector<int> FindNodesWithName(
302  const char* name, int sort_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
303 
314  std::vector<int> GetChildNodes(int parent, bool traverse_subtree = true,
315  int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
316 
323  int GetNumberOfChildren(int parent) const;
324 
329  int GetChild(int parent, int index) const;
330 
335  int GetChild(int parent, const char* name) const;
336 
341  int GetChildIndex(int parent, int child) const;
342 
347  int GetParent(int id) const;
348 
353  bool HasAttribute(int id, const char* name) const;
354 
356 
360  void SetAttribute(int id, const char* name, const char* value);
361  void SetAttribute(int id, const char* name, int value);
362  void SetAttribute(int id, const char* name, unsigned int value);
363 #if VTK_ID_TYPE_IMPL != VTK_INT
364  void SetAttribute(int id, const char* name, vtkIdType value);
365 #endif
366 
369 
372  bool GetAttribute(int id, const char* name, const char*& value) const;
373  bool GetAttribute(int id, const char* name, int& value) const;
374  bool GetAttribute(int id, const char* name, unsigned int& value) const;
375 #if VTK_ID_TYPE_IMPL != VTK_INT
376  bool GetAttribute(int id, const char* name, vtkIdType& value) const;
377 #endif
378 
381 
385  const char* GetAttributeOrDefault(int id, const char* name, const char* default_value) const;
386  int GetAttributeOrDefault(int id, const char* name, int default_value) const;
387  unsigned int GetAttributeOrDefault(int id, const char* name, unsigned int default_value) const;
388 #if VTK_ID_TYPE_IMPL != VTK_INT
389  vtkIdType GetAttributeOrDefault(int id, const char* name, vtkIdType default_value) const;
390 #endif
391 
394 
399  int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const
400  {
401  this->Visit(0, visitor, traversal_order);
402  }
403  void Visit(int id, vtkDataAssemblyVisitor* visitor,
404  int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
406 
408 
420  std::vector<unsigned int> GetDataSetIndices(int id, bool traverse_subtree = true,
421  int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
422  std::vector<unsigned int> GetDataSetIndices(const std::vector<int>& ids,
423  bool traverse_subtree = true,
424  int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
426 
436  std::vector<int> SelectNodes(const std::vector<std::string>& path_queries,
437  int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
438 
444  bool RemapDataSetIndices(
445  const std::map<unsigned int, unsigned int>& mapping, bool remove_unmapped);
446 
453  void SubsetCopy(vtkDataAssembly* other, const std::vector<int>& selected_branches);
454 
458  void DeepCopy(vtkDataAssembly* other);
459 
463  static bool IsNodeNameValid(const char* name);
464 
471  static std::string MakeValidNodeName(const char* name);
472 
480  static bool IsNodeNameReserved(const char* name);
481 
482 protected:
483  vtkDataAssembly();
484  ~vtkDataAssembly() override;
485 
486 private:
487  vtkDataAssembly(const vtkDataAssembly&) = delete;
488  void operator=(const vtkDataAssembly&) = delete;
489 
490  class vtkInternals;
491  std::unique_ptr<vtkInternals> Internals;
492 };
493 
494 VTK_ABI_NAMESPACE_END
495 #endif
const char * GetRootNodeName() const
Get/Set root node name.
abstract base class for most VTK objects
Definition: vtkObject.h:52
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
visitor API for vtkDataAssembly
void Visit(vtkDataAssemblyVisitor *visitor, int traversal_order=vtkDataAssembly::TraversalOrder::DepthFirst) const
Visit each node in the assembly for processing.
int vtkIdType
Definition: vtkType.h:363
VTKIOHDF_EXPORT bool GetAttribute(hid_t group, const char *attributeName, size_t numberOfElements, T *value)
Reads an attribute from the group passed to it.
a simple class to control print indentation
Definition: vtkIndent.h:28
static int GetRootNode()
Returns the ID for the root node.
hierarchical representation to use with vtkPartitionedDataSetCollection
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
void SetRootNodeName(const char *name)
Get/Set root node name.