Download & Install OpenAlea : download
[prompt ~]$visualeaThis video shows:
In this tutorial, we will see how to implement a simple modeling problem in Visualea.
We measured some tree data, saved in a tabbed editor (like excel). These data have been exported in a CSV file.
⇒ We want to have a simple 3D representation of the measured tree.
The CSV data are :
X Y crown_up crown_bot trunk_diameter 0 0 10 20 2 10 12 12 18 3 20 22 8 23 3,4 0 18 14 22 2,5
You need to intall on your system the following openalea packages :
Use OpenAlea installer to install these packages.
You will need also standard scientific python packages :
Use OpenAlea installer / Install Other Egg to install these packages
First of all, we need to create a package where to put your work (dataflow, node definition, data, …). A package is in fact a simple directory containing python files.
Your new package should appear in the package manager.
Nota : the path correspond to directory where the python file will be written. Choose it carefully in order to be able to find it later.
read or filenamefilename node to the workspace (the white page on the right)filename box is on the workspace. It has one input and one output (yellow circle)read node from the package openalea.file to the workspacefilename output to the read input : drag the mouse pointer from a port to the other.openalea.data structure.text on the workspaceread nodefilename and select Open Widgettext node, and select Runtext node, and select Open WidgetIn order to manipulate the CSV data, we are going to build a CSV object.
read csv node on the workspacegetitem object (catalog.python.getitem)read output to the read csv input, and its output to the getitem first inputint object on the workspace, and connect its output the second input of getitemgetitem nodestandbuilder package in the combo boxreadcsv_1OkOk buttonstandbuilder package.Before displaying the whole stand, we must rebuild a tree. In this tutorial we build a very simple tree representation composed by a sphere for the crown and a cylinder for the trunk.
This simple dataflow shows how to display a scene object.
plantgl.objects.cylinder creates a cylinderplantgl.objects.translated moves the input objectcatalog.data.tuple3 to set the translation vectorplantgl.visualization.plot3d to view the resultTo build our tree, we must construct a PlantGL scene containing a cylinder and a sphere.
plantgl.objects.sphere objectplantgl.objects.translated objectplantgl.objects.scene objecttranslated objects to a plantgl.objects.scene objectstandbuilder package as simple_treeWe will need to use the previous dataflow to build trees. To simplify this procedure, we would like to use a simple node and not a complex dataflow. For that we are going to embed the previous dataflow in a composite node (also named macro node).
simple_tree in a new workspace (double click in the package manager on the simple_tree graph)+ button :+ buttonOKcatalog.math.-, and connect the result to the crown radiusstandbuilder named tree_scenereadcsv_1 in the standbuilder package (doucke click)standbuilder.tree_scene on the new workspacegetitem and 5x string objectplangl.visualization.plot3D object and connect it to the output of tree_scenegetitem (object index)standbuilder package as readcsv_2string objectstandbuilder package as readcsv_3We want to extract from the csv object the X and Y properties and plot them in 2D.
read node and a csv2objs node to read a csv file.read widget (open widget)getitem node and a int node to select an object in the listextract node and 2 strings node to select properties in a particular object.We want to do the same thing, but for all the CSV objects contained in the file.
getitem and the int nodes (with suppr)catalog.functioanl.mapextract to the first input of mapcsv2objs to the second input of mapsystem.X node and connect its output the first input of extractmap object and display the result
Nota : The X object represents a function variable. The map apply a function to each element received in its second input.
plottools.VS Plot and plottools.tuples2seq on the workspacemap output the input of tuples2seq and the last output the VS Plot node.standbuilder package as plot_csvIn this step, we used the same method to build the entire stand
readcsv_3 dataflowsystem.X node and a catalog.functional.map nodestandbuilder package as plot_standWe want to generate an image of the 3D scene. Unfortunately there is no PlantGL node to achieve this task. We need to implement our own python function to do that.
standbuilderscene writerfrom openalea.plantgl.all import Viewer class scene_writer(object): """ Write a plantgl scene to a PNG file """ def __call__(self, *inputs): scene = inputs[0] fname = inputs[1] Viewer.display(scene) Viewer.camera.lookAt((0,0,300),(0,0,0)) Viewer.frameGL.saveImage(fname) return fname
plot_stand dataflow (double click in the package tree)scene writer from the package manager to the workspace.Scene output to the first input of scene_writer catalog.file.filename node to the second input of scene_writerscene_writerplot_stant (overwrite existing one)Now we want to modify the code of the node. For instance, we want to change the camera position.
standbuilder package in the tree view, and click Reload : this action reload all python modules in the package, but doesn't affect the nodes in the workspace.plot_stand dataflowplot_stand_funcfilenamescene_writer output the dataflow output (out)) catalog.string.join node and connect it to the scene_writer second inputjoin widget, and delete the join character (by default, it is a 'space')catalog.data.string node, set its value to '.png' and connect it to the first input of joincatalog.file.globcatalog.file.joinpathcatalog.file.dirnamecatalog.data.stringstring to *.csvdirname to directory to scanglob and print the resultplot_stand_func nodecatalog.functional.map and a system.X plot_stand_func node for each file (see picture)standbuilder package as gen_images