OK, so if I have a list of tree (of type GH_Structure<GH_Point>) and want to add them into another tree, is that possible? I’ve tried defining nested structures, but that doesn’t seem to work, kind of like so:
var deep_tree = new GH_Structure<GH_Structure<GH_Point>>();
for (var i = 0; i < small_tree.Count; i++)
{
deep_tree.Append( small_tree[i], new GH_Path(i) );
}
… but this doesn’t work, and if I use deep_tree.AppendRange(arr, path), then the tree doesn’t separate the added “small_trees” into different branches.
Do I really have to unpack the samllest items and put them into an entirely new tree structure to get a “deep_tree” structure?
(for now I did just that, but it means I have to “redo” trees that already exist)
Hm. Yes, that compiles and runs, but it flattens the added “small trees”, so I end up with the added trees as “flat” branches.
The trees which I add (or in this case, merge) into the main tree are created in this way:
public static GH_Structure<GH_Point> Point2DArrayToTree(Point3d[][] arr)
{
var tree = new GH_Structure<GH_Point>();
for (var i = 0; i < arr.Length; i++)
{
var path = new GH_Path(0, i);
for (var j = 0; j < arr[i].Length; j++)
{
// Append only valid points, break at first occurence
if (arr[i][j] == Point3d.Unset)
{
break;
}
tree.Append(new GH_Point(arr[i][j]), path);
}
}
return tree;
}
The main tree was merged together like so:
// using RILGeometry.Meshes;
var tree = new GH_Structure<GH_Point>();
for (var i = 0; i < indexes.Count; i++)
{
// collects "vertice stars" around index[i]
var arr = Meshes.ConnectedTopologyVertices(mesh, indexes[i]);
tree.MergeStructure(Meshes.Point2DArrayToTree(arr));
}
DA.SetDataTree(OUT_Tree, tree);
… but the added “small trees” appear as “flattened lists” in the screenshot above.
Now one last Q; When I have the datatree on the canvas, how do I merge the second path (after I have picked the first item in each branch, which are the red balls pictured)
I changed my mind about that, in actual trees branches give way to yet more branches. It’s twigs that eventually provide you with leaves. The nomenclature in gh2 will be; tree, path, twig, item, leaf, pair, and meta. I admit that it gives me a sense of satisfaction that they are all four letter words.
A pair is an item plus its meta-data, a leaf is a pair plus its location within the tree. Sadly a location is a five letter word; “locus” and it consists of a path plus an index.