Section: Visualization Toolkit Filtering Classes
vtkTree is a read-only data structure. To construct a tree, create an instance of vtkMutableDirectedGraph. Add vertices and edges with AddVertex() and AddEdge(). You may alternately start by adding a single vertex as the root then call graph->AddChild(parent) which adds a new vertex and connects the parent to the child. The tree MUST have all edges in the proper direction, from parent to child. After building the tree, call tree->CheckedShallowCopy(graph) to copy the structure into a vtkTree. This method will return false if the graph is an invalid tree.
vtkTree provides some convenience methods for obtaining the parent and children of a vertex, for finding the root, and determining if a vertex is a leaf (a vertex with no children).
To create an instance of class vtkTree, simply invoke its constructor as follows
obj = vtkTree
obj
is an instance of the vtkTree class.
string = obj.GetClassName ()
int = obj.IsA (string name)
vtkTree = obj.NewInstance ()
vtkTree = obj.SafeDownCast (vtkObject o)
int = obj.GetDataObjectType ()
- Get the root vertex of the tree.
vtkIdType = obj.GetRoot ()
- Get the root vertex of the tree.
vtkIdType = obj.GetNumberOfChildren (vtkIdType v)
- Get the i-th child of a parent vertex.
vtkIdType = obj.GetChild (vtkIdType v, vtkIdType i)
- Get the i-th child of a parent vertex.
obj.GetChildren (vtkIdType v, vtkAdjacentVertexIterator it)
- Get the parent of a vertex.
vtkIdType = obj.GetParent (vtkIdType v)
- Get the parent of a vertex.
vtkIdType = obj.GetLevel (vtkIdType v)
- Get the level of the vertex in the tree. The root vertex has level 0.
Returns -1 if the vertex id is < 0 or greater than the number of vertices
in the tree.
bool = obj.IsLeaf (vtkIdType vertex)
- Return whether the vertex is a leaf (i.e. it has no children).
obj.ReorderChildren (vtkIdType parent, vtkIdTypeArray children)
- Reorder the children of a parent vertex.
The children array must contain all the children of parent,
just in a different order.
This does not change the topology of the tree.