Grasshopper

algorithmic modeling for Rhino

Breadth-first iteration over GH DataTree while still knowing the path?

Hey all,

I am working on a leaf venation script in python, in which a vein grows by adding nodes off of existing nodes. 

I am trying to convert the script to store the nodes in a datatree (which has the same structure of the vein - i.e. each node along the length of a branch in the vein is a child of the node before it in the datatree, and where the vein branches, a datatree node has two children.

So, I need to iterate over all existing nodes, and I need to keep track of each node's path within the NodeTree in order to add the child node in the right place. 

This is the structure of the loop I came up with:

NodeTree initially contains the roots, so if you have two roots, they are at {0,0}, and {0,1}

for i in range(0, NodeTree.BranchCount):
--CurrPath = NodeTree.Path(i)
--NodeList = NodeTree.Branch(CurrPath) 
--for Node in NodeList:
----//make new node

----//find first unoccupied child of CurrPath (if there is already a child, then we are
        forming a second branch from our current location)

----//place new node in that location in the datatree

The problem is that now my tree grows in a depth-first manner, so the second tree will not begin growing until the first tree has stopped growing. 

Is there a better way for me to traverse the NodeTree? One that would give me breadth-first growth, and make the trees grow simultaneously?

Thanks,

Harrison

I think this is how i want to travel the tree:

Views: 539

Attachments:

Replies to This Discussion

Hallo Harrison,

Don't know if this helps but SpiderWeb provides a .NET library (don't know if you can use it) for graphs, including BFS / DFS.

Richard

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service