VTK  9.1.0
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 =========================================================================*/
117 #ifndef vtkDataAssembly_h
118 #define vtkDataAssembly_h
119 
120 #include "vtkCommonDataModelModule.h" // for export macros
121 #include "vtkObject.h"
122 
123 #include <map> // for std::map
124 #include <memory> // for std::unique_ptr
125 #include <string> // for std::string
126 #include <vector> // for std::vector
127 
129 
130 class VTKCOMMONDATAMODEL_EXPORT vtkDataAssembly : public vtkObject
131 {
132 public:
133  static vtkDataAssembly* New();
134  vtkTypeMacro(vtkDataAssembly, vtkObject);
135  void PrintSelf(ostream& os, vtkIndent indent) override;
136 
142  void Initialize();
143 
145 
150  bool InitializeFromXML(const char* xmlcontents);
152 
154 
159 
164  static int GetRootNode() { return 0; }
165 
167 
170  void SetRootNodeName(const char* name) { this->SetNodeName(this->GetRootNode(), name); }
171  const char* GetRootNodeName() const { return this->GetNodeName(this->GetRootNode()); }
173 
182  int AddNode(const char* name, int parent = 0);
183 
191  std::vector<int> AddNodes(const std::vector<std::string>& names, int parent = 0);
192 
197  int AddSubtree(int parent, vtkDataAssembly* other, int otherParent = 0);
198 
208  bool RemoveNode(int id);
209 
211 
218  void SetNodeName(int id, const char* name);
219  const char* GetNodeName(int id) const;
221 
225  std::string GetNodePath(int id) const;
226 
230  int GetFirstNodeByPath(const char* path) const;
231 
242  bool AddDataSetIndex(int id, unsigned int dataset_index);
243 
250  bool AddDataSetIndices(int id, const std::vector<unsigned int>& dataset_indices);
251 
258  bool AddDataSetIndexRange(int id, unsigned int index_start, int count);
259 
265  bool RemoveDataSetIndex(int id, unsigned int dataset_index);
266 
275  bool RemoveAllDataSetIndices(int id, bool traverse_subtree = true);
276 
278  {
279  DepthFirst = 0,
280  BreadthFirst
281  };
282 
290  const char* name, int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
291 
296  std::vector<int> FindNodesWithName(
297  const char* name, int sort_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
298 
309  std::vector<int> GetChildNodes(int parent, bool traverse_subtree = true,
310  int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
311 
318  int GetNumberOfChildren(int parent) const;
319 
323  int GetChild(int parent, int index) const;
324 
328  int GetChildIndex(int parent, int child) const;
329 
334  int GetParent(int id) const;
335 
340  bool HasAttribute(int id, const char* name) const;
341 
343 
347  void SetAttribute(int id, const char* name, const char* value);
348  void SetAttribute(int id, const char* name, int value);
349  void SetAttribute(int id, const char* name, unsigned int value);
350 #if VTK_ID_TYPE_IMPL != VTK_INT
351  void SetAttribute(int id, const char* name, vtkIdType value);
352 #endif
353 
356 
359  bool GetAttribute(int id, const char* name, const char*& value) const;
360  bool GetAttribute(int id, const char* name, int& value) const;
361  bool GetAttribute(int id, const char* name, unsigned int& value) const;
362 #if VTK_ID_TYPE_IMPL != VTK_INT
363  bool GetAttribute(int id, const char* name, vtkIdType& value) const;
364 #endif
365 
368 
372  const char* GetAttributeOrDefault(int id, const char* name, const char* default_value) const;
373  int GetAttributeOrDefault(int id, const char* name, int default_value) const;
374  unsigned int GetAttributeOrDefault(int id, const char* name, unsigned int default_value) const;
375 #if VTK_ID_TYPE_IMPL != VTK_INT
376  vtkIdType GetAttributeOrDefault(int id, const char* name, vtkIdType default_value) const;
377 #endif
378 
381 
386  int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const
387  {
388  this->Visit(0, visitor, traversal_order);
389  }
390  void Visit(int id, vtkDataAssemblyVisitor* visitor,
391  int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
393 
395 
407  std::vector<unsigned int> GetDataSetIndices(int id, bool traverse_subtree = true,
408  int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
409  std::vector<unsigned int> GetDataSetIndices(const std::vector<int>& ids,
410  bool traverse_subtree = true,
411  int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
413 
423  std::vector<int> SelectNodes(const std::vector<std::string>& path_queries,
424  int traversal_order = vtkDataAssembly::TraversalOrder::DepthFirst) const;
425 
432  const std::map<unsigned int, unsigned int>& mapping, bool remove_unmapped);
433 
440  void SubsetCopy(vtkDataAssembly* other, const std::vector<int>& selected_branches);
441 
445  void DeepCopy(vtkDataAssembly* other);
446 
450  static bool IsNodeNameValid(const char* name);
451 
458  static std::string MakeValidNodeName(const char* name);
459 
463  static bool IsNodeNameReserved(const char* name);
464 
465 protected:
467  ~vtkDataAssembly() override;
468 
469 private:
470  vtkDataAssembly(const vtkDataAssembly&) = delete;
471  void operator=(const vtkDataAssembly&) = delete;
472 
473  class vtkInternals;
474  std::unique_ptr<vtkInternals> Internals;
475 };
476 
477 #endif
vtkDataAssembly
hierarchical representation to use with vtkPartitionedDataSetCollection
Definition: vtkDataAssembly.h:131
vtkDataAssembly::HasAttribute
bool HasAttribute(int id, const char *name) const
Returns true if attribute with the given name is present on the chosen node.
vtkDataAssembly::SetAttribute
void SetAttribute(int id, const char *name, const char *value)
Set an attribute.
vtkDataAssembly::GetChild
int GetChild(int parent, int index) const
Returns the id for a child not at the given index, if valid, otherwise -1.
vtkDataAssembly::GetParent
int GetParent(int id) const
Returns the id for the parent node, if any.
vtkDataAssembly::RemoveAllDataSetIndices
bool RemoveAllDataSetIndices(int id, bool traverse_subtree=true)
Clears all dataset indices from the node.
vtkDataAssembly::GetRootNode
static int GetRootNode()
Returns the ID for the root node.
Definition: vtkDataAssembly.h:164
vtkDataAssembly::AddNodes
std::vector< int > AddNodes(const std::vector< std::string > &names, int parent=0)
Same as AddNode except allows adding multiple nodes in one go.
vtkDataAssembly::SelectNodes
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.
vtkX3D::value
@ value
Definition: vtkX3D.h:226
vtkDataAssemblyVisitor
visitor API for vtkDataAssembly
Definition: vtkDataAssemblyVisitor.h:60
vtkDataAssembly::FindNodesWithName
std::vector< int > FindNodesWithName(const char *name, int sort_order=vtkDataAssembly::TraversalOrder::DepthFirst) const
Finds all nodes with the given name.
vtkIdType
int vtkIdType
Definition: vtkType.h:332
vtkDataAssembly::RemapDataSetIndices
bool RemapDataSetIndices(const std::map< unsigned int, unsigned int > &mapping, bool remove_unmapped)
Remap dataset indices.
vtkDataAssembly::GetAttribute
bool GetAttribute(int id, const char *name, const char *&value) const
Get an attribute value.
vtkDataAssembly::AddNode
int AddNode(const char *name, int parent=0)
Adds a node to the assembly with the given name and returns its id.
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:82
vtkDataAssembly::AddDataSetIndices
bool AddDataSetIndices(int id, const std::vector< unsigned int > &dataset_indices)
Same as AddDataSetIndex except supports adding multiple dataset indices in one go.
vtkDataAssembly::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkDataAssembly::AddDataSetIndexRange
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...
vtkDataAssembly::IsNodeNameValid
static bool IsNodeNameValid(const char *name)
Validates a node name.
vtkDataAssembly::MakeValidNodeName
static std::string MakeValidNodeName(const char *name)
Converts any string to a string that is a valid node name.
vtkDataAssembly::SerializeToXML
std::string SerializeToXML(vtkIndent indent) const
Saves the data-assembly as a XML.
vtkDataAssembly::SetRootNodeName
void SetRootNodeName(const char *name)
Get/Set root node name.
Definition: vtkDataAssembly.h:170
vtkDataAssembly::SubsetCopy
void SubsetCopy(vtkDataAssembly *other, const std::vector< int > &selected_branches)
Create a deep-copy of other by only passing the chosen branches.
vtkDataAssembly::GetChildIndex
int GetChildIndex(int parent, int child) const
Returns the index for a child under a given.
vtkDataAssembly::GetAttributeOrDefault
int GetAttributeOrDefault(int id, const char *name, int default_value) const
Get an attribute value.
vtkDataAssembly::RemoveDataSetIndex
bool RemoveDataSetIndex(int id, unsigned int dataset_index)
Removes a dataset index from a node.
vtkDataAssembly::GetDataSetIndices
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.
vtkDataAssembly::GetAttributeOrDefault
const char * GetAttributeOrDefault(int id, const char *name, const char *default_value) const
Get an attribute value.
vtkDataAssembly::GetChildNodes
std::vector< int > GetChildNodes(int parent, bool traverse_subtree=true, int traversal_order=vtkDataAssembly::TraversalOrder::DepthFirst) const
Returns ids for all child nodes.
vtkDataAssembly::vtkDataAssembly
vtkDataAssembly()
vtkDataAssembly::InitializeFromXML
bool InitializeFromXML(const char *xmlcontents)
Initializes a data-assembly using an XML representation of the assembly.
vtkDataAssembly::GetAttribute
bool GetAttribute(int id, const char *name, int &value) const
Get an attribute value.
vtkDataAssembly::AddSubtree
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.
vtkDataAssembly::GetNodePath
std::string GetNodePath(int id) const
Returns the path for a node.
vtkDataAssembly::DeepCopy
void DeepCopy(vtkDataAssembly *other)
Deep copy the other.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkDataAssembly::GetDataSetIndices
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.
vtkDataAssembly::SetAttribute
void SetAttribute(int id, const char *name, unsigned int value)
Set an attribute.
vtkDataAssembly::GetNodeName
const char * GetNodeName(int id) const
Get/Set a node's name.
vtkX3D::name
@ name
Definition: vtkX3D.h:225
vtkDataAssembly::GetAttributeOrDefault
unsigned int GetAttributeOrDefault(int id, const char *name, unsigned int default_value) const
Get an attribute value.
vtkObject.h
vtkDataAssembly::RemoveNode
bool RemoveNode(int id)
Removes a node from the assembly.
vtkDataAssembly::Visit
void Visit(int id, vtkDataAssemblyVisitor *visitor, int traversal_order=vtkDataAssembly::TraversalOrder::DepthFirst) const
Visit each node in the assembly for processing.
vtkX3D::string
@ string
Definition: vtkX3D.h:496
vtkDataAssembly::Visit
void Visit(vtkDataAssemblyVisitor *visitor, int traversal_order=vtkDataAssembly::TraversalOrder::DepthFirst) const
Visit each node in the assembly for processing.
Definition: vtkDataAssembly.h:385
vtkDataAssembly::GetFirstNodeByPath
int GetFirstNodeByPath(const char *path) const
Return a node id given the path.
vtkDataAssembly::GetAttribute
bool GetAttribute(int id, const char *name, unsigned int &value) const
Get an attribute value.
vtkDataAssembly::Initialize
void Initialize()
Initializes the data-assembly.
vtkDataAssembly::FindFirstNodeWithName
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...
vtkDataAssembly::~vtkDataAssembly
~vtkDataAssembly() override
vtkDataAssembly::IsNodeNameReserved
static bool IsNodeNameReserved(const char *name)
Returns true for node names that are reserved.
vtkDataAssembly::SetNodeName
void SetNodeName(int id, const char *name)
Get/Set a node's name.
vtkDataAssembly::AddDataSetIndex
bool AddDataSetIndex(int id, unsigned int dataset_index)
Add a dataset index to a node.
vtkDataAssembly::GetNumberOfChildren
int GetNumberOfChildren(int parent) const
Returns the number of child nodes.
vtkX3D::index
@ index
Definition: vtkX3D.h:252
vtkDataAssembly::New
static vtkDataAssembly * New()
vtkDataAssembly::TraversalOrder
TraversalOrder
Definition: vtkDataAssembly.h:278
vtkDataAssembly::SetAttribute
void SetAttribute(int id, const char *name, int value)
Set an attribute.
vtkDataAssembly::GetRootNodeName
const char * GetRootNodeName() const
Get/Set root node name.
Definition: vtkDataAssembly.h:171