A tree graph representing the connected structure of shapes can be constructed with the help of the NGraphBuilder and NShapeGraphAdapter classes. The following example creates a tree, which represents the connected component in which a shape resides:
C# |
Copy Code
|
---|---|
NGraphBuilder graphBuilder = new NGraphBuilder(new NShapeGraphAdapter(), new NGraphPartFactory()); NObjectGraphPartMap map; NTree tree = graphBuilder.BuildTree(shape, out map); |
Visual Basic |
Copy Code
|
---|---|
Dim graphBuilder As New NGraphBuilder(New NShapeGraphAdapter(), New NGraphPartFactory()) Dim map As NObjectGraphPartMap Dim tree As NTree = graphBuilder.BuildTree(shape, map) |
The output NObjectGraphPartMap instance is a bi-map of (object - to/from - graph part), which means that you can easily get the graph part, which represents a shape and vice versa:
C# |
Copy Code
|
---|---|
// get the graph part which represents a shape NGraphPart part = map.GetPartFromObject(shape); // get the shape which the part represents NShape shape = (NShape)map.GetObjectFromPart(part); |
Visual Basic |
Copy Code
|
---|---|
' get the graph part which represents a shape Dim part NGraphPart = map.GetPartFromObject(shape) ' get the shape which the part represents Dim shape NShape = map.GetObjectFromPart(part) |
The graph builder will create a tree rooted at the specified shape, which represents the depth first spanning tree of a directed graph, with the shape as start vertex. Alternatively you can obtain a spanning tree of a graph. See Graphs for more information.