openalea.plantconvert.opf#
openalea.plantconvert.opf.const module#
Functions to read .opf files#
- class openalea.plantconvert.opf.reader.Opf(OpfPath, verbose=False)[source]#
Bases:
objectClass 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.
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