tree

iniTreeStructure (iniTree with vertices output)

LukeNeo's picture

Some days ago I posted iniTree plugin, that allow to draw recursive ternary trees. Gtoledo suggested to rewrite the plugin as a provider. Asking the community what is the best way to output a structure from a QCplugin, I used the method suggested by dust, and the implemented iniTreeStructure, which is a iniTree plugin witch outputs vertices positions.

Inputs:

  • numDiv (1-3): how many branches will have your tree.
  • growDelay: how much time the tree branches will spend in growing/shrinking.
  • aperture: tree aperture.
  • add/remove level: add/remove tree level.

Outputs:

  • vertices: tree vertices positions. They are ordered so as to be rendered using GL_LINES, so if you attach this output to GL line structure and use line type Line segments, the output will be right.

iniTree - draw your own recursion tree

LukeNeo's picture

Hello there, I just want to share with you a simple that draws a ternary tree. The algorithm is very simple and uses recursion. Here is what it does in pseudocode (for n-ary tree):

  1. main{
  2. max_levels = 10 //the max num of levels
  3. tree(initLenght, 1);
  4. }
  5.  
  6. tree(length, level){
  7. if(level<max_levels){ //is the end of the recursion?
  8. n = 3 //it is a ternary tree
  9. for(x=0; x<n; <++){
  10. pushMatrix()
  11. rotate ((360 / n)*x) along y axis
  12. rotate (aperture) along z axis
  13. drawLine(0,0,0, 0,length,0) //from 0,0,0 to 0,length,0
  14. translate(0,length,0)
  15. tree(lenght/2, level+1) //recursive call
  16. popMatrix()
  17. }
  18. }
  19. }

As you can see, I used glRotate/glTranslate and glBegin(GL_LINES)/glEnd() calls, in old OpenGL style. Maybe this is the reason why with more than 8/9 levels I don't obtain good performance. Using vbo will result in better performance, but I'm still not sure about how to do that.

It is a very simple plugin, but if used in audio-reaction compositions I think it can produce interesting results. So let me know if someone use it in some cool way! :)

Download(plugin and example composition)