1. Quick Start to manipulate MTGs

1.1. Reading an MTG file and activate it

A plant architecture described in a coding file can be loaded in openalea.mtg.aml as follows:

>>> from openalea.mtg.aml import MTG
>>> g1 = MTG('user/agraf.mtg')          # some errors may occur while loading the MTG
ERROR: Missing component for vertex 2532


In order to reproduce the example, download agraf MTG file and the agraf DRF file. Other files that may be required are also available in the same directory (*smb files) but are not compulsary.

The MTG function attempts to read a valid MTG description and parses the coding file. If errors are detected during the parsing, they are displayed on the screen and the parsing fails. In this case, no MTG is built and the user should make corrections to the coding file. If the parsing succeeds, this function creates an internal representation of the plant (or a set of plants) encoded as a MTG. In this example, the MTG object is stored in variable g1 for further use. Note that a MTG should always be stored in a variable otherwise it is destroyed immediately after its building. The last built MTG is considered as the “active” MTG. It is used as an implicit argument by all the functions of the MTG module.

It is possible to change the active MTG using Activate()

g1 = MTG("filename1") # g1 is the current MTG
g2 = MTG("filename2") # g2 becomes the current MTG
Activate(g1)          # g1 is now again the current MTG


the notion of activation is very important. Each call to a function in the package MTG will look at the active MTG.

1.2. Plotting


PlantFrame is still in development and not all MTG files can be plotted with the current code, especially the files that have no information about positions

The following examples shows how to plot the contents of a MTG given that a dressing data file (DRF) is available. See the File syntax section for more information about the MTG and DRF syntax. Note that the following code should be simplified in the future.

 1from openalea.mtg.aml import MTG
 2from openalea.mtg.dresser import dressing_data_from_file
 3from openalea.mtg.plantframe import PlantFrame, compute_axes, build_scene
 4g = MTG('agraf.mtg')
 5dressing_data = dressing_data_from_file('agraf.drf')
 6topdia = lambda x:  g.property('TopDia').get(x)
 7pf = PlantFrame(g, TopDiameter=topdia,    DressingData = dressing_data)
 8axes = compute_axes(g, 3, pf.points, pf.origin)
 9diameters = pf.algo_diameter()
10scene = build_scene(pf.g, pf.origin, axes, pf.points, diameters, 10000)
11from  vplants.plantgl.all import Viewer

Figure 3.5 An apple tree plotted with the python script shown above