FreeMat

- Main Page
- Related Pages

vtkTree

Section: Visualization Toolkit Filtering Classes

# Usage

vtkTree is a connected directed graph with no cycles. A tree is a type of directed graph, so works with all graph algorithms.

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

# Methods

The class vtkTree has several methods that can be used. They are listed below. Note that the documentation is translated automatically from the VTK sources, and may not be completely intelligible. When in doubt, consult the VTK website. In the methods listed below, `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.