Skip to content

Commit 4d99be7

Browse files
Merge pull request #71 from openalea/release2025
Complete weberpenn tutorials
2 parents 1255082 + 00e00d4 commit 4d99be7

30 files changed

Lines changed: 448 additions & 0 deletions

doc/user/beginner.rst

Lines changed: 320 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,320 @@
1+
==========================
2+
Using Visualea : Beginning
3+
==========================
4+
5+
Here is a tutorial in which you will see how to implement a simple modeling problem in *Visualea*
6+
7+
.. image:: ./images/beginner/intro.gif
8+
9+
Here is what you need for the following tutorial
10+
::
11+
conda create -n visualea_tuto -c openalea openalea.visualea openalea.components openalea.plantgl boost=1.66 -c openalea/label/unstable
12+
conda activate visualea_tuto
13+
14+
Once you installed and activated the OpenAlea environment (see `Installation <https://openaleadocs.readthedocs.io/en/latest/install.html>`_), execute this
15+
::
16+
17+
visualea
18+
19+
The Goal
20+
========
21+
22+
We measured some tree data and saved these in a tabbed editor (like Excel). The data has been exported in a CSV file. We want to have a simple 3D representation of the measured tree.
23+
24+
Here is the data :
25+
26+
.. csv-table::
27+
:header: "X", "Y", "crown_up", "crown_bot", "trunk_diameter"
28+
:widths: 15, 15, 20, 20, 20
29+
30+
0, 0, 10, 20, 2
31+
10, 12, 12, 18, 3
32+
20, 22, 8, 23, 3.4
33+
0, 18, 14, 22, 2.5
34+
35+
You may want to download the `CSV file <https://github.com/openalea/openalea.rtfd.io/blob/master/doc/_static/stand.csv>`_.
36+
37+
Step 1 : Create Your Own Package
38+
================================
39+
40+
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.
41+
42+
Create a package
43+
----------------
44+
45+
#. Select **Package Manager** -> **Add** -> **Package**
46+
#. Fill the form :
47+
48+
* **Name** : standbuilder
49+
* **Description** : build stand representation from measured data
50+
* **Version** : 0.1
51+
* **License** : Cecill-C
52+
* **Authors** : All collaborators and package writer
53+
* **Institutes** : …
54+
* **URL** : …
55+
* **Path** : /home/myhome/openalea_pkg (could be anywhere you want)
56+
57+
#. Click "OK"
58+
59+
60+
.. image:: ./images/beginner/step1.gif
61+
62+
Your new package should appear in the package manager.
63+
64+
.. tip::
65+
The path corresponds to the directory where the python file will be written.
66+
Choose it carefully in order to be able to find it later.
67+
68+
69+
Step 2 : Read CSV Data
70+
======================
71+
72+
Create a dataflow to read and view a file
73+
-----------------------------------------
74+
75+
.. tip::
76+
Leaving the cursor on any item in the Package Manager, or on nodes or ports in
77+
the dataflow view brings up a tooltip. Clicking on them also shows some documentation
78+
in the "Help" tab (bottom-left-hand corner).
79+
80+
#. In the Package Manager tab (left column), open the *openalea.file* folder. You should
81+
see a list of nodes.
82+
83+
.. note::
84+
You can search for a particuliar node in the Search tab.
85+
86+
#. In the Package Manager tab, drag the ``read`` node from the *openalea.file* package to the
87+
workspace. It should now appear on the canvas.
88+
#. In the workspace, right click on the ``read`` node and choose "Open Widget".
89+
Then browse for the "stand.csv" file (no need to validate anything,
90+
changes are automatically taken into account so you can simply close the window).
91+
#. In the package manager search the ``text`` in the **search tab**, then drag the ``text`` node from the *openalea.data structure.string* folder onto the workspace.
92+
#. Connect the output of the ``read`` node to the input of the ``text`` node.
93+
94+
95+
.. image:: ./images/beginner/step2.1.gif
96+
97+
98+
View the file contents
99+
----------------------
100+
101+
#. Right click on the ``text`` node and select "Run"
102+
#. Right click on the ``text`` node and select "Open Widget"
103+
104+
105+
Build a CSV object
106+
------------------
107+
108+
In order to manipulate the CSV data, we are going to build a CSV object.
109+
110+
#. Select the search tab in the package manager
111+
#. Type CSV
112+
#. Drag the ``read csv`` node on the workspace
113+
#. Do the same to create a ``getitem`` node (``openalea.python method.getitem``)
114+
#. Connect ``read``'s output to ``read csv``'s input
115+
#. Connect ``read csv``'s first output to ``getitem``'s first input
116+
#. Add an ``int`` node on the workspace, and connect its output to the second input of ``getitem``
117+
#. Execute the graph by selecting "Run" in the context menu of the ``getitem`` node
118+
#. Print the output in the shell : Right click on the output port, and select "Print"
119+
120+
121+
.. image:: ./images/beginner/step2.2.gif
122+
123+
124+
Save your work
125+
--------------
126+
127+
#. Select **File** -> **Save as composite node** (CTRL + S)
128+
#. In the selector dialog, click "New" Button
129+
#. In the new dialog
130+
131+
* Select the standbuilder package in the combo box
132+
* Enter the name : *readcsv_1*
133+
* Add a description : *Read data file*
134+
* Click "Ok"
135+
136+
#. In the selector, click "Ok" button
137+
#. The new graph should appear in the standbuilder package.
138+
139+
140+
.. image:: ./images/beginner/step2.3.gif
141+
142+
143+
Step 3 : Create a simple 3D representation of one tree
144+
======================================================
145+
146+
Before displaying the whole stand, we must rebuild a tree.
147+
In this tutorial we build a very simple tree representation composed by a
148+
sphere for the crown and a cylinder for the trunk.
149+
150+
Create a 3D object
151+
------------------
152+
153+
This simple dataflow shows how to display a scene object.
154+
155+
#. First step, we create a new workspace : Select **File** -> **New Empty Workspace** (CTRL+T)
156+
#. Create the following dataflow by using PlantGL nodes
157+
158+
* ``plantgl.objects.cylinder`` creates a cylinder
159+
* ``plantgl.objects.translated`` moves the input object
160+
* ``openalea.data structure.tuple.tuple3`` to set the translation vector
161+
* ``plantgl.visualization.plot3d`` to view the result
162+
* ``openalea.data structure.float`` to set the parameters of the tuple3 node
163+
164+
165+
.. image:: ./images/beginner/step3.1.PNG
166+
167+
Create a simple tree
168+
--------------------
169+
170+
To build our tree, we must construct a PlantGL scene containing a cylinder and a sphere.
171+
172+
#. Modify the previous dataflow as follow:
173+
174+
* Add a ``plantgl.objects.sphere`` object
175+
* Add a ``plantgl.objects.translated`` object
176+
* Add a ``plantgl.objects.scene`` object
177+
* Connect the 2 translated objects to a ``plantgl.objects.scene`` object
178+
179+
#. Save this dataflow in your standbuilder package as **simple_tree**
180+
181+
182+
.. image:: ./images/beginner/step3.2.PNG
183+
184+
185+
Step 4 : Create a Macro Node / Group Nodes
186+
==========================================
187+
188+
We will need to use the previous dataflow to build trees.
189+
To simplify this procedure, we would like to use a simple node and not a complex dataflow.
190+
For that we are going to embed the previous dataflow in a *composite node* (also named *macro node*).
191+
192+
Transform simple_tree to a reusable composite node
193+
--------------------------------------------------
194+
195+
#. Select **simple_tree** in the package manager
196+
#. Right click on the **simple_tree** graph, select "Properties" and click on the "Inputs / Outputs"
197+
button
198+
#. Add 5 inputs with the + button :
199+
200+
* X - IInt - 0 - X position
201+
* Y - IInt - 0 - Y position
202+
* crown_up - IFloat - 16.0 - Top of the crown
203+
* crown_bot - IFloat - 8.0 - Bottom of the crown
204+
* trunk_dia - IFloat - 3.0 - Trunk diameter
205+
206+
#. Add 1 output with the + button
207+
208+
* scene - None - PlanGL scene
209+
210+
.. image:: ./images/beginner/step4.1.PNG
211+
:width: 40%
212+
213+
#. Click "OK" and the buttons will appear in the workspace
214+
215+
#. Double click **simple_tree** and modify the graph as follow
216+
217+
* Connect input 0 and 1 to the X and Y nodes
218+
* Connect input 2 and 3 to a minus node ``openalea.math.-``, and connect the result
219+
to the crown radius
220+
* Connect input 5 to the trunk radius
221+
* Connect input 3 to the crown bottom
222+
223+
#. Save your work as a new composite node in standbuilder named **tree_scene**
224+
225+
226+
.. image:: ./images/beginner/step4.2.PNG
227+
:width: 70%
228+
229+
230+
Using the new composite node in a dataflow
231+
------------------------------------------
232+
233+
#. Open our first dataflow **readcsv_1** in the standbuilder package (doubleclick)
234+
#. Drag the node ``standbuilder.tree_scene`` on the new workspace
235+
#. Add 5x ``getitem`` and 5x ``string`` object
236+
#. Connect the nodes as the picture in order to retrieve to different object properties
237+
#. Add a ``plangl.visualization.plot3D`` object and connect it to the output of ``tree_scene``
238+
#. Run the dataflow several times and change the value of the first ``getitem`` (object index)
239+
#. Save the dataflow in the standbuilder package as **readcsv_2**
240+
241+
Create a composite node by grouping nodes
242+
-----------------------------------------
243+
244+
#. Select the 5 ``getitem`` and their associated ``string`` object
245+
#. Click on Menu **Workspace** -> **group** (CTRL+G)
246+
#. Run the dataflow
247+
#. Save it in the standbuilder package as **readcsv_3**
248+
249+
250+
.. image:: ./images/beginner/step4.3.PNG
251+
:width: 70%
252+
253+
.. image:: ./images/beginner/step4.4.PNG
254+
:width: 20%
255+
256+
257+
Step 5 : Get the spatial distribution of the trees
258+
==================================================
259+
260+
We want to extract from the csv object the X and Y properties and plot them in 2D.
261+
262+
Extract data
263+
------------
264+
265+
#. Create a new workspace (CTRL+T)
266+
#. Add a ``read`` node and a ``read csv`` node to read a csv file
267+
#. Set the file to read by opening the ``read`` widget (*Open Widget*)
268+
#. Run and display the output (output port context menu -> *Print* or *Tooltip*) : it's a list of obj
269+
#. Add a ``getitem`` node and an ``int`` node to select an object in the list
270+
#. Add an ``extract`` node and 2 ``string`` nodes to select properties in a particular object
271+
#. Set the 2 ``string`` objects to X and Y
272+
#. Run and display the output (output port context menu -> *print* or *tooltip*) : it's a
273+
list containing the X and the Y properties of the selected object.
274+
275+
.. image:: ./images/beginner/step5.1.PNG
276+
277+
Implement iterative process
278+
---------------------------
279+
280+
We want to do the same thing, but for all the CSV objects contained in the file.
281+
282+
#. Remove the ``getitem`` and the ``int`` nodes (with suppr)
283+
#. Add an ``openalea.function operator.map``
284+
#. Connect the output of ``extract`` to the first input of ``map``
285+
#. Connect the output of ``read csv`` to the second input of ``map``
286+
#. Add an ``openalea.flow control.X`` node and connect its output the first input of ``extract``
287+
#. Run the ``map`` object and display the result
288+
289+
.. image:: ./images/beginner/step5.2.PNG
290+
291+
.. note::
292+
293+
The X object represents a function variable. The map apply a
294+
function to each element received in its second input.
295+
296+
297+
Plot 2D
298+
-------
299+
300+
#. Add the nodes ``openalea.plottools.VS Plot`` and ``openalea.plottools.tuples2seq`` on the workspace
301+
#. Connect the ``map`` output the input of ``tuples2seq`` and the last output the ``VS Plot`` node.
302+
#. Run the dataflow
303+
#. Save it in the standbuilder package as **plot_csv**
304+
305+
306+
Step 6 : Apply the process to multiple trees
307+
============================================
308+
309+
In this step, we used the same method to build the entire stand
310+
311+
#. Open the ``readcsv_3`` dataflow
312+
#. Modify it in order to plot in 3D all the tree contained in the file and not only one
313+
#. Use a ``openalea.flow control.X`` node and a ``openalea.functional.map`` node
314+
#. Save this work in your standbuilder package as **plot_stand**
315+
316+
.. image:: ./images/beginner/step6.1.PNG
317+
:width: 45%
318+
.. image:: ./images/beginner/step6.2.PNG
319+
:width: 45%
320+

doc/user/images/beginner/intro.gif

1.93 MB
Loading

doc/user/images/beginner/step1.gif

1.06 MB
Loading
1.03 MB
Loading
1.26 MB
Loading
916 KB
Loading
14.4 KB
Loading
123 KB
Loading
15.5 KB
Loading
99.7 KB
Loading

0 commit comments

Comments
 (0)