Reputation: 21
I found that one can dive into deeper levels by tracking the Childs property of an ILGroup node (or find parent nodes via the Parent property on any ILNode object). The enumerator on ILScene gives a "flattened" version of the whole scene graph. Thus, enumerating the ILScene and using the Childs property on group nodes gives indeed a tree-like scene graph, but many nodes are referenced more than once. Of course, one could track the nodes already visited to prevent them from appearing again. But I though there must be some 'official' way for hierarchical scene graph traversal.
Upvotes: 2
Views: 283
Reputation: 376
Traversal can easily be done by utilizing the Find<T>()
function. It allows the definition of a predicate function which is called for every node in the scene, matching the given type parameter T.
Let's take the following scene, showing a simple line plot (http://ilnumerics.net/ilcc.php?ilc=ia5d62c):
var scene = new ILScene {
new ILPlotCube {
new ILLinePlot(ILMath.array<float>(
new float[] { 1, 3, 5, 2, 7}, 1, 5))
}
};
//scene;
scene.Find<ILGroup>(predicate: n => {
// this predicate is called once for every node
Console.Out.WriteLine(n.ToString());
return false;
});
This gives the following output:
ILGroup #20 '--' Childs:[4]
Camera: #21 - Polar r:10 f:0° ?:0° - Pos X:0 Y:0 Z:10 - Lookat X:0 Y:0 Z:0 - Top X:0 Y:1 Z:0
ILGroup #22 'Screen' Childs:[1]
ILGroup #23 'Light0Group' Childs:[1]
ILPlotCube #26 'PlotCube' Childs:[2]
ILPlotCubeScaleGroup #27 'PlotCubeScale' Childs:[3]
ILPlotCubeDataGroup #28 'PlotsData' Childs:[1]
ILLinePlot #57 'LinePlot' Childs:[2]
ILMarker #59 'Marker' Childs:[2]
ILAxisCollection #30 'AxisCollection' Childs:[3]
ILAxis #31 'AxisGroup' Childs:[5]
ILTickCollection #32 'TicksCollectionGroup' Childs:[1]
ILAxis #39 'AxisGroup' Childs:[5]
ILTickCollection #40 'TicksCollectionGroup' Childs:[1]
ILAxis #47 'AxisGroup' Childs:[5]
ILTickCollection #48 'TicksCollectionGroup' Childs:[1]
ILSelectionRectangle #55 'SelectionRectangle' Childs:[1]
Note that the generic type T in Find<T>
determines the type of nodes to consider for output. Here, only group nodes are considered. In order to recognize ALL nodes within the scene, one may use Find<ILNode>()
instead.
Upvotes: 1