MTGmanip#

openalea.plantscan3d.mtgmanip.gaussian_filter(mtg, propname, considerapicalonly=True)[source]#

Apply a Gaussian filter to smooth a property along the MTG.

Parameters:
  • mtg (openalea.mtg.MTG) – MTG object.

  • propname (str) – Name of the property to filter.

  • considerapicalonly (bool) – If True, only consider apical (edge_type “<”) children. Default to True.

Return type:

None. The property is updated in-place.

openalea.plantscan3d.mtgmanip.gaussian_weight(x, var)[source]#

Compute a Gaussian weight at a given value.

Parameters:
  • x (float) – Input value.

  • var (float) – Variance of the Gaussian distribution.

Returns:

Gaussian weight exp(-x²/(2*var)) / sqrt(2*pi*var²).

Return type:

float

openalea.plantscan3d.mtgmanip.get_first_param_value(mtg, propname)[source]#

Get the first non-None property value at the maximum scale.

Parameters:
  • mtg (openalea.mtg.MTG) – MTG object.

  • propname (str) – Name of the property.

Returns:

First non-None property value found at the maximum scale, or None if no such value exists.

Return type:

object or None

openalea.plantscan3d.mtgmanip.initialize_mtg(root, nodelabel='N')[source]#

Initialize a new MTG with a single node at the given position.

Parameters:
  • root (Vector3) – Position of the root node.

  • nodelabel (str) – Label for the nodes (default “N”).

Returns:

New MTG with one node.

Return type:

openalea.mtg.MTG

openalea.plantscan3d.mtgmanip.mtg2pgltree(mtg)[source]#

Convert an MTG to a PlantGL tree representation.

Parameters:

mtg (openalea.mtg.MTG) – MTG object to convert.

Returns:

(nodes, parents, vertex2node) where nodes is a list of positions, parents is a list of parent indices, and vertex2node maps MTG vertex ids to list indices.

Return type:

tuple

openalea.plantscan3d.mtgmanip.pgltree2mtg(mtg, startfrom, parents, positions, radii=None, filter_short_branch=False, angle_between_trunk_and_lateral=60, nodelabel='N')[source]#

Convert a PlantGL tree representation back into an MTG.

Parameters:
  • mtg (openalea.mtg.MTG) – MTG object to add nodes to.

  • startfrom (int) – Starting node id in the MTG.

  • parents (list of int) – Parent indices for each node in the tree.

  • positions (list of Vector3) – Positions of each node.

  • radii (list of float or None) – Radii of each node. If None, no radius property is set.

  • filter_short_branch (bool) – If True, remove branches with no children.

  • angle_between_trunk_and_lateral (float) – Angle threshold in degrees to determine edge type between trunk and lateral branches.

  • nodelabel (str) – Label for the nodes (default “N”).

Returns:

MTG with the tree added.

Return type:

openalea.mtg.MTG

openalea.plantscan3d.mtgmanip.pipemodel(mtg, rootradius=None, leafradius=None, root=None)[source]#

Uses the pipemodel algorithm to estimate the radius of each node of the MTG.

Parameters:
  • mtg (openalea.mtg.MTG) – MTG object to be processed.

  • rootradius (float | None) – Radius of the root node. If None, the radius of the first node is used. Default to None.

  • leafradius (float | None) – Radius of the leaf nodes. If None, it is estimated as 1/100 of the root radius. Default to None.

  • root (int | None) – Id of the root node. If None, the root node is selected automatically.

Return type:

MTG with a new or updated radius property computed using the pipe model algorithm.

openalea.plantscan3d.mtgmanip.threshold_filter(mtg, propname)[source]#

Apply a threshold filter to a property, preventing values from increasing along the traversal from root to leaves.

Parameters:
  • mtg (openalea.mtg.MTG) – MTG object.

  • propname (str) – Name of the property to filter.

Return type:

None. The property is updated in-place.