VTK  9.2.6
vtkDataAssembly.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkDataAssembly.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 =========================================================================*/
120 #ifndef vtkDataAssembly_h
121 #define vtkDataAssembly_h
122 
123 #include "vtkCommonDataModelModule.h" // for export macros
124 #include "vtkObject.h"
125 
126 #include <map> // for std::map
127 #include <memory> // for std::unique_ptr
128 #include <string> // for std::string
129 #include <vector> // for std::vector
130 
132 
133 class VTKCOMMONDATAMODEL_EXPORT vtkDataAssembly : public vtkObject
134 {
135 public:
136  static vtkDataAssembly* New();
137  vtkTypeMacro(vtkDataAssembly, vtkObject);
138  void PrintSelf(ostream& os, vtkIndent indent) override;
139 
145  void Initialize();
146 
148 
153  bool InitializeFromXML(const char* xmlcontents);
155 
157 
160  std::string SerializeToXML(vtkIndent indent) const;
162 
167  static int GetRootNode() { return 0; }
168 
170 
173  void SetRootNodeName(const char* name) { this->SetNodeName(this->GetRootNode(), name); }
174  const char* GetRootNodeName() const { return this->GetNodeName(this->GetRootNode()); }
176 
185  int AddNode(const char* name, int parent = 0);
186 
194  std::vector<int> AddNodes(const std::vector<std::string>& names, int parent = 0);
195 
200  int AddSubtree(int parent, vtkDataAssembly* other, int otherParent = 0);
201 
211  bool RemoveNode(int id);
212 
214 
221  void SetNodeName(int id, const char* name);
222  const char* GetNodeName(int id) const;
224 
228  std::string GetNodePath(int id) const;
229 
233  int GetFirstNodeByPath(const char* path) const;
234 
245  bool AddDataSetIndex(int id, unsigned int dataset_index);
246 
253  bool AddDataSetIndices(int id, const std::vector<unsigned int>& dataset_indices);
254 
261  bool AddDataSetIndexRange(int id, unsigned int index_start, int count);
262 
268  bool RemoveDataSetIndex(int id, unsigned int dataset_index);
269 
278  bool RemoveAllDataSetIndices(int id, bool traverse_subtree = true);
279 
281  {
282  DepthFirst = 0,
283  BreadthFirst
284  };
285 
292  int FindFirstNodeWithName(
293  const char* name, int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
294 
299  std::vector<int> FindNodesWithName(
300  const char* name, int sort_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
301 
312  std::vector<int> GetChildNodes(int parent, bool traverse_subtree = true,
313  int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
314 
321  int GetNumberOfChildren(int parent) const;
322 
326  int GetChild(int parent, int index) const;
327 
331  int GetChildIndex(int parent, int child) const;
332 
337  int GetParent(int id) const;
338 
343  bool HasAttribute(int id, const char* name) const;
344 
346 
350  void SetAttribute(int id, const char* name, const char* value);
351  void SetAttribute(int id, const char* name, int value);
352  void SetAttribute(int id, const char* name, unsigned int value);
353 #if VTK_ID_TYPE_IMPL != VTK_INT
354  void SetAttribute(int id, const char* name, vtkIdType value);
355 #endif
356 
359 
362  bool GetAttribute(int id, const char* name, const char*& value) const;
363  bool GetAttribute(int id, const char* name, int& value) const;
364  bool GetAttribute(int id, const char* name, unsigned int& value) const;
365 #if VTK_ID_TYPE_IMPL != VTK_INT
366  bool GetAttribute(int id, const char* name, vtkIdType& value) const;
367 #endif
368 
371 
375  const char* GetAttributeOrDefault(int id, const char* name, const char* default_value) const;
376  int GetAttributeOrDefault(int id, const char* name, int default_value) const;
377  unsigned int GetAttributeOrDefault(int id, const char* name, unsigned int default_value) const;
378 #if VTK_ID_TYPE_IMPL != VTK_INT
379  vtkIdType GetAttributeOrDefault(int id, const char* name, vtkIdType default_value) const;
380 #endif
381 
384 
389  int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const
390  {
391  this->Visit(0, visitor, traversal_order);
392  }
393  void Visit(int id, vtkDataAssemblyVisitor* visitor,
394  int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
396 
398 
410  std::vector<unsigned int> GetDataSetIndices(int id, bool traverse_subtree = true,
411  int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
412  std::vector<unsigned int> GetDataSetIndices(const std::vector<int>& ids,
413  bool traverse_subtree = true,
414  int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
416 
426  std::vector<int> SelectNodes(const std::vector<std::string>& path_queries,
427  int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
428 
434  bool RemapDataSetIndices(
435  const std::map<unsigned int, unsigned int>& mapping, bool remove_unmapped);
436 
443  void SubsetCopy(vtkDataAssembly* other, const std::vector<int>& selected_branches);
444 
448  void DeepCopy(vtkDataAssembly* other);
449 
453  static bool IsNodeNameValid(const char* name);
454 
461  static std::string MakeValidNodeName(const char* name);
462 
466  static bool IsNodeNameReserved(const char* name);
467 
468 protected:
469  vtkDataAssembly();
470  ~vtkDataAssembly() override;
471 
472 private:
473  vtkDataAssembly(const vtkDataAssembly&) = delete;
474  void operator=(const vtkDataAssembly&) = delete;
475 
476  class vtkInternals;
477  std::unique_ptr<vtkInternals> Internals;
478 };
479 
480 #endif
const char * GetRootNodeName() const
Get/Set root node name.
abstract base class for most VTK objects
Definition: vtkObject.h:62
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:332
a simple class to control print indentation
Definition: vtkIndent.h:39
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.