openalea.plantconvert.opf#

openalea.plantconvert.opf.const module#

Functions to read .opf files#

class openalea.plantconvert.opf.reader.Opf(OpfPath, verbose=False)[source]#

Bases: object

Class to read and write topological and geometrical opf format to OpenAlea (mtg and PlantGL).

The object contains as properties :

OpfInfo : opf file’s information

Meshesa list of reference meshes. Each mesh is represented by a dictionary
(use keys function to get the exact keys) and contains :

id : the id of the mesh points : a list of all nodes coordinates in 3D faces : the connectivity table of the mesh normal : the normal vectors at each node of the mesh textureCoords (optional) : the texture coordinates plantgl_obj : the PlantGL object that represents the mesh (TriangleSet)

Materialsa list of materials. Each material is represented by a dictionary and contains :

id : the id of the material emission : a color represented in RGBA format (the first 3 components are float value

bounded between 0,1 and should be converted to 0,255 (integer) if required)

ambient : the same as emission diffuse : the same as emission specular : the same as emission shininess : float bounded between 0 to 128 plantgl_obj : the PlantGL object that represents the material (Material)

Shapesa list of shapes. Each shape is represented by a dictionary and contains :

id : the id of the shape meshIndex : the id of the mesh to create this shape materialIndex : the id of the material to create this shape

Attributesa dictionary of attributes used to describe each organe of the plant. The keys of

this dictionary correspond to the name of the attribute while the associated value is a lambda function that convert the data to the correct type

Mtgan openalea object that reads the topology structure of the plant. The attributes of

the mtg are those read previously and geometry that is given by a shape.

Usage:

parser = Opf("simple_plant.opf")
parser.build()
parser.write_mtg("simple_plant.mtg")
print(parser.Mtg)
Parameters:
  • OpfPath (string) – path to the opf file that you want to parse

  • verbose (bool) – if True, more information will be printed on the sreen while parsing the file. The default value is False.

read_opf()[source]#

Once initialized, use this method to perform parsing.

Note: This method should be launched at most 1 time. :return: mtg object with opf information stored in its attributes. :rtype: openalea.mtg

exception openalea.plantconvert.opf.reader.Unknown_edge_type[source]#

Bases: Exception

openalea.plantconvert.opf.reader.all_empty(last_indices)[source]#

Test if all the stacks are empty.

Parameters:

last_indices (dict) – a dictionary of stacks

Returns:

True if all the stacks are empty.

Functions to write .opf files#

openalea.plantconvert.opf.writer.apply_scene(g, scene)[source]#

Add a scene to the mtg.

The scene should support the method : scene.todict() which will return a dictionary with vid as keys and the vertex’s geometry as value. In order to allow this behavior, when you define your scene from a mtg, for each shape of the scene, you should set id to be vid : shape.id = vid and then you combine the shapes to create your scene.

This function will also try to extract reference meshes and materials from the given scene (implementation is not complete yet !). But it works when each mtg node has exactly one geometric object associated if it has.

Parameters:
  • g (MTG.mtg) – an mtg object

  • scene (plantgl.Scene) – a plantgl object

openalea.plantconvert.opf.writer.write_opf(g, filename, features=None)[source]#

Write the opf file from a given MTG object.

Parameters:
  • g (MTG.mtg) – an mtg object, either read from a file or generated by a simulator

  • filename (str) – the file to write the .opf file.

  • features (dict, optional) – additional attributes to write in the “attributeBDD” section of the .opf file, at the root node level.