algorithmic modeling for Rhino
I'm trying to understand data structures in GH better, to be better Grasshopper wrangler. As an exercise, I'm trying to simplify a massive definition that has 6 separate, identical paths, making it hard to maintain (every change needs to be made 6 times).
My initial thought was "I'll just make a tree with 6 branches, and pass that through, doing the operations on each branch, then parse the results out at the end." Unfortunately, there's a wrinkle: there may or may not be data in each of the 6 initial data sets. Is that a killer? It seems it shouldn't be.
I've found out (through previous questions) how to create trees with empty branches, but of course those branches aren't necessarily preserved through components. (For instance the CCX component, I've just discovered, changes the tree structure in mysterious ways if there's not a curve to intersect, or if there is no intersection.)
I'm looking for some "fundamentals" advice here. Knowing I want a 6-branched path through a bunch of calculations, with all 6 branches preserved right to the end (even when empty or null or even becoming that way on their journey), what's the best approach?
One approach might be to "pre-screen" the data and thus start out with a clean, populated tree, and use the PathMapper (a tool from heaven) to "rebuild" the tree every time it gets messed with by a component. But even that seems messy.
(Another, of course, is to just write it in C# and be done with it, but that's cheating :-)
Any insights would be appreciated...
Tags:
I learned much over the weekend, here's some of it in case it helps others:
1) Trees with null branches just pass right on through, maintaining the tree structure. (Many components complain loudly about the presence of nulls, but they keep working on the valid branches anyway.) This is very useful for processing parallel streams that may or may not contain anything.
2) Although many components alter the tree structure, it's fairly simple to "restore" it with PathMapper afterward. (Example: CCX adds a new layer for each found intersection, which makes good sense, but leaves the tree in a state that I don't want.) For instance, let's say I have this tree:
{0;0} 1 item: null
{0;1} 3 items: curves
{0;2} 1 item: curve
After the curve-curve intersection (intersecting with another 3-branch tree), I might have:
{0:0} 1 item: null
{0;1;0} 1 item: point
{0;1;1} 1 item: point
{0;1;2} 1 item: point
{0;2;0} 1 item: point
With the PathMapper I can do {A;B}->{A;B} and {A;B;C}->{A;B}(C) to collapse it back to what I want:
{0;0} 1 item: null
{0;1} 3 items: points
{0;2} 1 item: point
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by