openalea.plantconvert#
Generic interface to handle a plant object#
- class openalea.plantconvert.plant.Plant(file: str = 'None', ignored_attrs=[], verbose=False)[source]#
Bases:
objectGeneral interface for plantconvert.
This class allows to read from different file types and to export other file types.
- The supported types are :
.mtg .opf .vtk .gltf
- Parameters:
file (str, optional) – name of the file to read using the read method. Defaults to None.
ignored_attrs (list of string, optional) – a list of attributes that will not appear in the final exported file in addition to attributes from RESERVED_NAMES. Defaults set to empty list.
verbose (bool, optional) – verbose mode, more information will be printed on the screen if you activate it. Defaults to False.
- openalea.plantconvert.plant.plant_from_mtg(g: MTG) Plant[source]#
Generate a plant object from an mtg.MTG object.
Note: This can be usefull if we couple this package to another openalea package and want to save to another format.
- Parameters:
g (mtg.MTG) – mtg object of the plant we later want to write
- Returns:
Plant object that embeds the mtg.MTG objects.
- Return type:
plantconvert.Plant
Internal functions for binary format#
- openalea.plantconvert.binary_tools.pack_vec_array(vec_array, dtype)[source]#
Transform the input array of vectors into a binary string.
- Parameters:
vec_array (array) – list of vectors
dtype (str) – data type
- Returns:
binary string that store the data in compact way, and always pack bytes
in litte endian order. You can write the binary string into a file when you open it by ‘wb’. :rtype: bytes
Geometry related functions#
- openalea.plantconvert.geometry.get_scene(g: MTG, filter=None)[source]#
Generate a plantGL Scene object from mtg geometry properties.
This method traverses the mtg g and reads the geometry property of the nodes that are allowed by the filter. It creates a plantgl Scene object of all geometric objects combined.
- Parameters:
g (mtg.MTG) – mtg object that contains the plant
filter (function, optional) – takes 2 inputs: mtg.MTG and node ID and returns a bool. Defaults to None, i.e. all nodes are taken into account.
- Returns:
plantGL Scene object containing all geometric objects
- Return type:
plantGL.Scene
- openalea.plantconvert.geometry.mat_from_transformed(geo)[source]#
Extract the global transformation matrix from a transformed geometry.
- Parameters:
geo (plantgl.Geometry) – a geometry object from PlantGL
- Raises:
TypeError – if the transformation is not recognized (i.e. not a plantGL instance)
- Returns:
transformation matrix used to obtain the transformed geometry
- Return type:
plantGL.Matrix4
- class openalea.plantconvert.geometry.taper_along_x(ref_meshes=None)[source]#
Bases:
objectClass with information to perform tapering along x axis.
To initialize this class with a list of reference meshes (represented by TriangleSet) If the given mesh is not in the list then it will be added.
- Parameters:
ref_meshes (list) – list of reference meshes
- openalea.plantconvert.geometry.tapering_radius_from_transformed(geo)[source]#
Extract the tapering radii from the input geometry.
- Parameters:
geo (either a plantGL.TriangleSet, a plantGL.Tapered or a plantGL shape) – a geometry object from PlantGL
- Returns:
top and base radii of the tapering geometry
- Return type:
- openalea.plantconvert.geometry.transformed_from_mat(A, geo, is_mesh=False)[source]#
Apply the transformation A (a 3 by 4 matrix) on the geometry.
- Qr transformation of matrix A is done so that A = Q*r where:
Q is a unity matrix and r is upper-triangular. To use the oriented object of plantgl, Q should have positive determinant. r is in our case diagonal since A is a composition of rotations and scaling.
- Parameters:
A (numpy.ndarray) – a 3 by 4 array that describes the transformation in the reference of the scene. This matrix is supposed to be TRS decomposible
geo (plantgl.Geometry) – a geometry object from PlantGL
is_mesh (bool) – if true a new mesh (TriangleSet) will be created. Otherwise we only create a geometry object (no duplication of mesh in the memory). Defaults to False.
- Returns:
Transformed geometry. if is_mesh then we get a new mesh otherwise we only create a geometry object
- Return type:
plantgl.Geometry
Plant material related functions#
- openalea.plantconvert.material.to_gltf(material_data)[source]#
Create the material information accepted by GLTF, not implemented yet.
- openalea.plantconvert.material.to_plantgl(material_data)[source]#
Create a plantgl object to represent a material from the input material_data.
- Parameters:
material_data (dict) – dictionary that contains exactly : An Id 4 colors in RGBA : emission, ambient, diffuse and specular. shininess value.
- Returns:
plantgl.Material object. Note that some information might be lost. For example, the alpha value in .opf is defined for each color (emission, etc. ) while in plantgl there is only a global alpha value : transparency = 1 - alpha
- Return type:
plantgl.Material
Transformation-Matrix related functions#
- openalea.plantconvert.matrix.TRS_from_matrix4(A: ndarray)[source]#
Return the TRS components of a TRS matrix.
- Parameters:
A (numpy.ndarray) – a 4x4 TRS matrix
- Returns:
t, Q, s: the TRS components of the input matrix.
- Return type:
tuple of numpy.ndarray vector of length 3, 3x3 matrix, vector of length 3
- openalea.plantconvert.matrix.global_to_local_matrix(mat_c, mat_p=None)[source]#
Return the local matrix of mat_c in the reference of mat_p.
- Parameters:
mat_c (numpy.ndarray) – a 4x4 matrix
mat_p (numpy.ndarray) – a 4x4 matrix
- Returns:
the local matrix of mat_c in the reference of mat_p.
- Return type:
numpy.ndarray
- openalea.plantconvert.matrix.inv_TRS(A: ndarray)[source]#
Return the inverse of a TRS matrix.
- Parameters:
A (numpy.ndarray) – a 4x4 TRS matrix
- Returns:
inverted matrix of A of size 4x4
- Return type:
numpy.ndarray
- openalea.plantconvert.matrix.is_TRS(A: ndarray)[source]#
Test if the input matrix A is a 4D TRS matrix.
This requires to test if A’s linear part is the composition of a rotation and a scaling. If this is the case, the first three columns should be orthogonal.
- Parameters:
A (numpy.ndarray) – a 4x4 matrix
- Returns:
True if A is a TRS matrix, False otherwise
- Return type:
- openalea.plantconvert.matrix.mat4_to_numpy(A)[source]#
Convert the pgl.Matrix4 object to a 2d array.
- Parameters:
A (pgl.Matrix4) – a pgl.Matrix4 object.
- Returns:
the corresponding 2d numpy array.
- Return type:
numpy.ndarray