API

PlantGeom.GeometryType
Geometry(; ref_mesh<:RefMesh, transformation=Identity(), dUp=1.0, dDwn=1.0)

A Node geometry with the reference mesh, its transformation (as a function) and the resulting mesh (optional, may be lazily computed).

The transformation field should be a TransformsBase.Transform, such as TransformsBase.Identity, or the ones implemented in Meshes.jl, e.g. Translate, Scale... If you already have the transformation matrix, you can pass it to Meshes.Affine().

source
PlantGeom.PhongType

Data structure for a mesh material that is used to describe the light components of a Phong reflection type model. All data is stored as RGBα for Red, Green, Blue and transparency.

source
PlantGeom.RefMeshType
RefMesh(
    name::S
    mesh::SimpleMesh
    normals::N
    texture_coords::T
    material::M
    taper::Bool
)

RefMesh(name, mesh, material = RGB(220 / 255, 220 / 255, 220 / 255))

RefMesh type. Stores all information about a Mesh:

  • name::S: the mesh name
  • mesh::SimpleMesh: the actual mesh information -> points and topology
  • normals::Vector{Float64}: the normals, given as a vector of x1,y1,z1,x2,y2,z2...
  • texture_coords::Vector{Float64}: the texture coordinates (not used yet), idem, a vector
  • material::M: the material, used to set the shading
  • taper::Bool: true if tapering is enabled

The reference meshes are then transformed on each node of the MTG using a transformation matrix to match the actual mesh.

source
Base.:==Method
==(a::Geometry, b::Geometry)

Test RefMesh equality.

source
Base.:==Method
==(a::RefMesh, b::RefMesh)

Test RefMesh equality.

source
PlantGeom.build_merged_mesh_with_mapMethod
build_merged_mesh_with_map(mtg; filter_fun=nothing, symbol=nothing, scale=nothing, link=nothing)

Traverse selected MTG nodes and merge their geometry meshes into a single Meshes.SimpleMesh.

Returns a merged mesh::Meshes.SimpleMesh and a face2node::Vector{Int} mapping each face index in the merged mesh to the originating MTG node id.

source
PlantGeom.build_merged_mesh_with_map_threadedMethod
build_merged_mesh_with_map_threaded(mtg; filter_fun=nothing, symbol=nothing, scale=nothing, link=nothing)

Threaded variant of [build_merged_mesh_with_map] that parallelizes vertex copy and connectivity reindexing across meshes. Preserves original mesh order.

source
PlantGeom.color_typeMethod
color_type(color, opf)

Return the type of the color, whether it is an attribute, a colorant, or a RefMeshColorant.

Arguments

  • color: The color to be checked.
  • opf: The MTG to be plotted.

Returns

  • RefMeshColorantType: If color is nothing (the default) to color by reference mesh.
  • DictRefMeshColorantType: If the color is a dictionary mapping reference meshes to colorants.
  • DictVertexRefMeshColorantType: If the color is a dictionary mapping vertices to colorants.
  • VectorColorantType: If the color is a vector of colorants, then we color each mesh by that vector.
  • VectorSymbolType: If the color is a vector of symbols, then we color each mesh by that vector.
  • AttributeColorantType: If the color is an attribute of the MTG, then we color by that attribute.
  • T: If the color is a colorant, then we color everything by that color.

Examples

using MultiScaleTreeGraph, PlantGeom, Colors

file = joinpath(dirname(dirname(pathof(PlantGeom))),"test","files","simple_plant.opf")

opf = read_opf(file)

# Colors:
color_type(:red, opf)
color_type(RGB(0.1,0.5,0.1), opf)

# Attributes:
color_type(:Length, opf)

# Default color:
color_type(nothing, opf)

# Dict of colors:
color_type(Dict(1=>RGB(0.1,0.5,0.1), 2=>RGB(0.5,0.1,0.1)), opf)
source
PlantGeom.coordinates!Method
coordinates!(mtg; angle = 45; force = false)

Compute dummy 3d coordinates for the mtg nodes using an alterning phyllotaxy. Used when coordinates are missing. Coordinates are just node attributes with reserved names: :XX, :YY and :ZZ.

Returns

Nothing, mutates the mtg in-place (adds :XX, :YY and :ZZ to nodes).

Examples

file = joinpath(dirname(dirname(pathof(MultiScaleTreeGraph))),"test","files","simple_plant.mtg")
mtg = read_mtg(file)
coordinates!(mtg)
DataFrame(mtg, [:XX, :YY, :ZZ])
source
PlantGeom.diagramFunction
diagram(opf::MultiScaleTreeGraph.Node; kwargs...)
diagram!(opf::MultiScaleTreeGraph.Node; kwargs...)

Make a diagram of the MTG tree using a Makie.jl backend.

Danger

This function is an extension to the package. It is only available if you imported a Makie backend (e.g. using GLMakie) prior to using PlantGeom.

The main attributes are:

  • color: the color of the nodes
  • colormap: the colormap used if the color uses an attribute. By default it uses viridis.

Must be a ColorScheme from ColorSchemes or a Symbol with its name.

Examples

using GLMakie, PlantGeom

file = joinpath(dirname(dirname(pathof(PlantGeom))),"test","files","simple_plant.opf")
# file = joinpath(dirname(dirname(pathof(PlantGeom))),"test","files","coffee.opf")

opf = read_opf(file)

diagram(opf)

# We can also color the 3d plot with several options:
# With one shared color:
diagram(opf, color = :red)

# Or colouring by opf attribute, *e.g.* using the nodes Z coordinates:
diagram(opf, color = :ZZ)
source
PlantGeom.diagram!Function
diagram(opf::MultiScaleTreeGraph.Node; kwargs...)
diagram!(opf::MultiScaleTreeGraph.Node; kwargs...)

Make a diagram of the MTG tree using a Makie.jl backend.

Danger

This function is an extension to the package. It is only available if you imported a Makie backend (e.g. using GLMakie) prior to using PlantGeom.

The main attributes are:

  • color: the color of the nodes
  • colormap: the colormap used if the color uses an attribute. By default it uses viridis.

Must be a ColorScheme from ColorSchemes or a Symbol with its name.

Examples

using GLMakie, PlantGeom

file = joinpath(dirname(dirname(pathof(PlantGeom))),"test","files","simple_plant.opf")
# file = joinpath(dirname(dirname(pathof(PlantGeom))),"test","files","coffee.opf")

opf = read_opf(file)

diagram(opf)

# We can also color the 3d plot with several options:
# With one shared color:
diagram(opf, color = :red)

# Or colouring by opf attribute, *e.g.* using the nodes Z coordinates:
diagram(opf, color = :ZZ)
source
PlantGeom.get_cached_sceneMethod
get_cached_scene(mtg, key) -> Union{Nothing,NamedTuple}

Retrieve the single cached merged scene if it matches key. Returns a NamedTuple with (hash, mesh, face2node) or nothing.

source
PlantGeom.get_colorMethod
get_color(var <: AbstractArray, range_var, colormap=colorschemes[:viridis])
get_color(var, range_var, colormap=colorschemes[:viridis])

Map value(s) to colors from a colormap based on a range of values

Arguments

  • var: value(s) to map to colors
  • range_var: range of values to map to colors
  • colormap: colormap to use

Returns

  • color: color(s) corresponding to var

Examples

```julia using Colors

getcolor(1, 1:2, colormap = colorschemes[:viridis]) # returns RGB{N0f8}(0.267004,0.00487433,0.329415) getcolor(1:2, 1:10, colormap = colorschemes[:viridis]) # returns RGB{N0f8}(0.267004,0.00487433,0.329415) get_color(1:2, 1:10, 1, colormap = colorschemes[:viridis]) # returns RGB{N0f8}(0.267004,0.00487433,0.329415)

source
PlantGeom.get_color_rangeMethod
get_color_range(colorrange, opf, colorant)

Get the color range from the colorrange argument or from the MTG attribute.

Arguments

  • colorrange: the color range specified by the user, can be an Observable or a tuple of two values.
  • opf: the MTG object.
  • colorant: the color attribute to use for the range.

Returns

  • colorrange: the color range as a tuple of two values.
source
PlantGeom.get_mtg_colorMethod
get_mtg_color(color, opf)

Return the color to be used for the plot.

Arguments

  • color: The color to be checked.
  • opf: The MTG to be plotted.

Returns

The color to be used for the plot.

Examples

using MultiScaleTreeGraph, PlantGeom, Colors
file = joinpath(dirname(dirname(pathof(PlantGeom))),"test","files","simple_plant.opf")
opf = read_opf(file)

get_mtg_color(:red, opf)
get_mtg_color(RGB(0.1,0.5,0.1), opf)
get_mtg_color(:Length, opf)
get_mtg_color(:slategray3, opf)
get_mtg_color(Dict(1=>RGB(0.1,0.5,0.1), 2=>RGB(0.1,0.1,0.5)), opf)
get_mtg_color(Dict(1 => :burlywood4, 2 => :springgreen4), opf)
source
PlantGeom.get_ref_meshesMethod
get_ref_meshes(mtg)

Get all reference meshes from an mtg, usually from an OPF.

Examples

using PlantGeom
file = joinpath(dirname(dirname(pathof(PlantGeom))),"test","files","simple_plant.opf")
opf = read_opf(file)
meshes = get_ref_meshes(opf)

using GLMakie
plantviz(meshes)
source
PlantGeom.get_ref_meshes_colorMethod
get_ref_meshes_color(meshes::Vector{<:RefMesh})

Get the reference meshes colors (only the diffuse part for now).

Examples

using MultiScaleTreeGraph, PlantGeom
file = joinpath(dirname(dirname(pathof(MultiScaleTreeGraph))),"test","files","simple_plant.opf")
opf = read_opf(file)
meshes = get_ref_meshes(opf)
PlantGeom.get_ref_meshes_color(meshes)
source
PlantGeom.map_coordMethod
map_coord(f, mesh, coord)

Apply function f over the mesh coordinates coord. Values for coord can be 1 for x, 2 for y and 3 for z.

source
PlantGeom.merge_children_geometry!Method
merge_children_geometry!(mtg; from, into, delete=:nodes, verbose=true, child_link_fun=x -> new_child_link(x, verbose))

Simplifies the geometry of a MultiScaleTreeGraph (MTG) by merging low-scale geometries into an higher-scale geometry.

Arguments

  • mtg: The MultiScaleTreeGraph to process.
  • from: The string for the type of nodes to simplify, this is the lower scale meshes that need to be merged. Can be a string or a vector of strings, e.g. ["Petiole", "Rachis"].
  • into: The string for the type of nodes to merge into. Must be a single string, e.g. "Leaf".
  • delete: A symbol indicating whether to delete the nodes or the geometry after merging:
    • :none: No deletion will be performed, the geometry is merged into the into nodes, and also kept as before in the from nodes.
    • :nodes: The nodes of type from will be deleted after merging.
    • :geometry: Only the geometry will be deleted, but the from nodes will remain in the MTG.
  • verbose: A boolean indicating if information should be returned when nodes or geometry was not found on expected nodes
  • child_link_fun: A function that takes a parent node targeted for deletion and returns the new links for their children. Required if delete is true. The

default function is new_child_link, which tries to be clever considering the parent and child links. See its help page for more information. If the link shouldn't be modified, use the link function instead.

Returns

  • Nothing. The function modifies the mtg in place.

Notes

If no geometry is found in the children nodes of type from, an informational message is logged.

source
PlantGeom.merge_simple_meshesMethod
merge_simple_meshes(meshes::AbstractVector{<:Meshes.SimpleMesh}) -> Meshes.SimpleMesh

Merge a collection of Meshes.SimpleMesh into a single mesh in one pass by concatenating vertices and reindexing element connectivities with running offsets. This avoids repeated pairwise merges and additional allocations.

source
PlantGeom.meshBDD_to_meshesMethod
meshBDD_to_meshes(x)

Examples

using MultiScaleTreeGraph
file = joinpath(dirname(dirname(pathof(MultiScaleTreeGraph))),"test","files","simple_plant.opf")
opf = read_opf(file)
meshBDD_to_meshes(opf[:meshBDD])
source
PlantGeom.mtg_coordinates_dfFunction
mtg_coordinates_df(mtg, attr; force = false)
mtg_coordinates_df!(mtg, attr; force = false)

Extract the coordinates of the nodes of the mtg and the coordinates of their parents (:XXfrom, :YYfrom, :ZZ_from) and output a DataFrame. Optionally you can also provide an attribute to add to the output DataFrame too by passing its name as a symbol to attr.

The coordinates are computed using coordinates! if missing, or if force = true.

source
PlantGeom.mtg_to_opf_linkMethod
mtg_to_opf_link(link)

Takes an MTG link as input ("/", "<" or "+") and outputs its corresponding link as declared in the OPF format ("decomp", "follow" or "branch")

source
PlantGeom.mtg_topology_to_xml!Function
mtg_topology_to_xml!(node, xml_parent)

Write the MTG topology, attributes and geometry into XML format. This function is used to write the "topology" section of the OPF.

source
PlantGeom.normals_vertexMethod
normals_vertex(mesh::Meshes.SimpleMesh)

Compute per vertex normals and return them as a StaticArrays.SVector.

#! This is a naive approach because I have no time right know. #! We just put the face mesh as a vertex mesh (and ovewritting values for common points)

TODO: Use a real computation instead. See e.g.:

https://stackoverflow.com/questions/45477806/general-method-for-calculating-smooth-vertex-normals-with-100-smoothness?noredirect=1&lq=1

source
PlantGeom.parse_opf_arrayFunction

Parse an array of values from the OPF into a Julia array (Arrays in OPFs are not following XML recommendations)

source
PlantGeom.parse_opf_elements!Method

Generic parser for OPF elements.

Arguments

  • opf::OrderedDict: the opf Dict (using [XMLDict.xml_dict])
  • elem_types::Array: the target types of the element (e.g. "[String, Int64]")

Details

elem_types should be of the same length as the number of elements found in each item of the subchild. elem_types = [Float64, Float64, Float64, Float64, Float64, Float64]

source
PlantGeom.parse_opf_topology!Function
parse_opf_topology!(node, mtg, features, attr_type, mtg_type, ref_meshes, id_set=Set{Int}())

Parser of the OPF topology.

Arguments

  • node::ElementNode: the XML node to parse.
  • mtg::Union{Nothing,Node}: the parent MTG node.
  • features::Dict: the features of the OPF.
  • attr_type::DataType: the type of the attributes to use.
  • mtg_type::DataType: the type of the MTG to use.
  • ref_meshes::Dict: the reference meshes.
  • read_id::Bool: whether to read the ID from the OPF or recompute it on the fly.
  • max_id::RefValue{Int64}=Ref(1): the ID of the first node, if read_id==false.

Note

The transformation matrices in geometry are 3*4.

source
PlantGeom.plantvizFunction
plantviz(mtg::MultiScaleTreeGraph.Node; kwargs...)
plantviz!(mtg::MultiScaleTreeGraph.Node; kwargs...)

Vizualise the 3D geometry of an MTG (usually read from an OPF). This function search for the :geometry attribute in each node of the MTG, and build the vizualisation using the reference meshes and the associated transformation matrix.

Arguments

  • mtg: The MTG to be vizualised.
  • kwargs: Additional arguments to be passed to plantviz!, wich includes:
    • color: The color to be used for the plot. Can be a colorant, an attribute of the MTG (given as a Symbol), or a dictionary of colors for each reference mesh.
    • colormap: The colorscheme to be used for the plot. Can be a Symbol or a ColorScheme.
    • segmentcolor: The color to be used for the facets. Should be a colorant or a symbol of color.
    • showsegments: A boolean indicating whether the facets should be shown or not.
    • color_missing=RGBA(0, 0, 0, 0.3): The color to be used for missing values. Should be a colorant or a symbol of color.
    • index: An integer giving the index of the attribute value to be vizualised. This is useful when the attribute is a vector of values for e.g. each timestep.
    • color_cache_name: The name of the color cache. Should be a string (default to a random string).
    • filter_fun: A function to filter the nodes to be plotted. Should be a function taking a node as argument and returning a boolean.
    • symbol: Plot only nodes with this symbol. Should be a String or a vector of.
    • scale: Plot only nodes with this scale. Should be an Int or a vector of.
    • link: Plot only nodes with this link. Should be a String or a vector of.

Examples

using MultiScaleTreeGraph, PlantGeom, GLMakie

file = joinpath(dirname(dirname(pathof(PlantGeom))),"test","files","simple_plant.opf")
# file = joinpath(dirname(dirname(pathof(PlantGeom))),"test","files","coffee.opf")

mtg = read_opf(file)
plantviz(mtg)

# Then plot it again like before, and it will be faster:
plantviz(mtg)

# We can color the 3d plot with several options:
# With one shared color:
plantviz(mtg, color = :red)
# One color per reference mesh:
plantviz(mtg, color = Dict(1 => :burlywood4, 2 => :springgreen4, 3 => :burlywood4))

# Or just changing the color of some:
plantviz(mtg, color = Dict(1 => :burlywood4))

# Or coloring by mtg attribute, e.g. using the mesh max Z coordinates:
transform!(mtg, zmax => :z_max, ignore_nothing = true)
plantviz(mtg, color = :z_max)

# One color for each vertex of the refmesh 1:
using Meshes
vertex_color = get_color(1:nvertices(get_ref_meshes(mtg))[1], [1,nvertices(get_ref_meshes(mtg))[1]])
plantviz(mtg, color = Dict(1 => vertex_color))

# Or even coloring by the value of the Z coordinates of each vertex:
transform!(mtg, (x -> [Meshes.coords(i).z for i in Meshes.vertices(refmesh_to_mesh(x))]) => :z_vertex, filter_fun= node -> hasproperty(node, :geometry))
plantviz(mtg, color = :z, showsegments = true)

f,a,p = plantviz(mtg, color = :z, showsegments = true)
p[:color] = :Length
plantviz!(ref_meshes; kwargs...)

Plot all reference meshes in a single 3d plot using Makie.

Examples

using PlantGeom, GLMakie

file = joinpath(dirname(dirname(pathof(PlantGeom))),"test","files","simple_plant.opf")
mtg = read_opf(file)
meshes = get_ref_meshes(mtg)

plantviz(meshes)
# With one shared color:
plantviz(meshes, color = :green)
# One color per reference mesh:
plantviz(meshes, color = Dict(1 => :burlywood4, 2 => :springgreen4, 3 => :burlywood4))
# Or just changing the color of some:
plantviz(meshes, color = Dict(1 => :burlywood4, 3 => :burlywood4))
# One color for each vertex of the refmesh 0:
plantviz(meshes, color = Dict(2 => 1:nvertices(meshes)[2]))
source
PlantGeom.plantviz!Function
viplantviz!(mtg; [options])

Visualize the 3D meshes of an mtg using Meshes.jl and makie. This function adds the plot to an existing scene with options forwarded to plantviz.

source
PlantGeom.read_opfMethod
read_opf(file; attr_type = Dict, mtg_type = MutableNodeMTG)

Read an OPF file, and returns an MTG.

Arguments

  • file::String: The path to the opf file.
  • attr_type::DataType = Dict: the type used to hold the attribute values for each node.
  • mtg_type = MutableNodeMTG: the type used to hold the mtg encoding for each node (i.e.

link, symbol, index, scale). See details section below.

  • read_id::Bool = true: whether to read the ID from the OPF or recompute it on the fly.
  • max_id::RefValue{Int64}=Ref(1): the ID of the first node, if read_id==false.

Details

attr_type should be:

  • NamedTuple if you don't plan to modify the attributes of the mtg, e.g. to use them for

plotting or computing statistics...

  • MutableNamedTuple if you plan to modify the attributes values but not adding new attributes

very often, e.g. recompute an attribute value...

  • Dict or similar (e.g. OrderedDict) if you plan to heavily modify the attributes, e.g.

adding/removing attributes a lot

The MultiScaleTreeGraph package provides two types for mtg_type, one immutable (NodeMTG), and one mutable (MutableNodeMTG). If you're planning on modifying the mtg encoding of some of your nodes, you should use MutableNodeMTG, and if you don't want to modify anything, use NodeMTG instead as it should be faster.

Note

See the documentation of the MTG format from the MTG package documentation for further details, e.g. The MTG concept.

Returns

The MTG root node.

Examples

using PlantGeom
file = joinpath(dirname(dirname(pathof(PlantGeom))),"test","files","simple_plant.opf")
# file = joinpath(dirname(dirname(pathof(PlantGeom))),"test","files","coffee.opf")
opf = read_opf(file)
source
PlantGeom.read_opsMethod
read_ops(file; attr_type=Dict{String,Any}, mtg_type=MutableNodeMTG)

Reads an OPS file and returns the content as a MultiScaleTreeGraph.

Arguments

  • file::String: Path of the .ops file to read.
  • attr_type::Type=Dict{Symbol,Any}: Type of the attributes to use.
  • mtg_type::Type: Type of the MTG to use, e.g. NodeMTG or MutableNodeMTG.

Returns

A MultiScaleTreeGraph of the scene, with the OPFs as children of the scene node. The dimension of the scene is available in the scene_dimensions attribute of the scene node. Each root node of the OPFs has a scene_transformation attribute that stores the transformation applied to the OPF by the scene. It allows updating the scene transformations and write the scene back to disk. The OPF root node also has the following attributes:

  • sceneID::Int: Scene ID.
  • plantID::Int: Plant ID.
  • filePath::String: Path to the original .opf file.
  • pos::Meshes.Point: Position of the object.
  • scale::Float64: Scale of the object.
  • inclinationAzimut::Float64: Inclination azimut of the object.
  • inclinationAngle::Float64: Inclination angle of the object.
  • rotation::Float64: Rotation of the object.
  • functional_group::String: Functional group of the object.

Details

Node IDs of the OPFs are recomputed at import to ensure their uniqueness in the larger scene MTG.

Example

using CairoMakie, PlantGeom
joinpath(pathof(PlantGeom) |> dirname |> dirname, "test", "files", "scene.ops") |> read_ops |> plantviz
source
PlantGeom.read_ops_fileMethod
read_ops_file(file)

Read the content of an .ops file and return a tuple with the scene dimensions and the object table.

Arguments

  • file::String: Path of the .ops file to read.

Returns

The scene dimensions and the object table as a tuple. The scene dimensions are a tuple of two Meshes.Point with the origin point and opposite point of the scene. The object table is an array of NamedTuple with the following fields:

  • sceneID::Int: Scene ID.
  • plantID::Int: Plant ID.
  • filePath::String: Path to the .opf file.
  • pos::Meshes.Point: Position of the object.
  • scale::Float64: Scale of the object.
  • inclinationAzimut::Float64: Inclination azimut of the object.
  • inclinationAngle::Float64: Inclination angle of the object.
  • rotation::Float64: Rotation of the object.
  • functional_group::String: Functional group of the object.
source
PlantGeom.refmesh_to_meshFunction
refmesh_to_mesh(node)

Compute a node mesh based on the reference mesh, the transformation matrix and the tapering.

Examples

using PlantGeom
file = joinpath(dirname(dirname(pathof(PlantGeom))),"test","files","simple_plant.opf")
opf = read_opf(file)

node = opf[1][1][1]

new_mesh = refmesh_to_mesh(node)

using GLMakie
plantviz(new_mesh)
source
PlantGeom.scene_cache_keyMethod
scene_cache_key(mtg; symbol=nothing, scale=nothing, link=nothing, filter_fun=nothing) -> UInt

Compute a stable cache key for the current scene rendering request.

source
PlantGeom.set_cached_scene!Method
set_cached_scene!(mtg, key; mesh, face2node=nothing)

Store a single merged scene cache with associated key hash. Only mesh and face2node are cached.

source
PlantGeom.taperMethod

Returns a tapered mesh using dDwn and dUp based on the geometry of an input mesh. Tapering a mesh transforms it into a tapered version (i.e. pointy) or enlarged object, e.g. make a cone from a cylinder.

source
PlantGeom.transform_mesh!Method
transform_mesh!(node::Node, transformation)

Add a new transformation to the node geometry transformation field. The transformation is composed with the previous transformation if any.

transformation must be a function.

It is also possible to invert a transformation using revert from Meshes.jl.

Examples

using PlantGeom, MultiScaleTreeGraph, GLMakie, Rotations, Meshes

file = joinpath(dirname(dirname(pathof(PlantGeom))), "test", "files", "simple_plant.opf")
opf = read_opf(file)

# Visualize the mesh as is:
plantviz(opf)

# Copy the OPF, and translate the whole plant by 15 in the y direction (this is in cm, the mesh comes from XPlo):
clean_cache!(opf) # Clean the cache to remove the observables that where cached by the previous `plantviz` call (necessary for the `deepcopy`).
opf2 = deepcopy(opf)
transform!(opf2, x -> transform_mesh!(x, Translate(0, 15, 0)))
plantviz!(opf2) # Visualize it again in the same figure

# Same but rotate the whole plant around the X axis:
clean_cache!(opf)
opf3 = deepcopy(opf)
transform!(opf3, x -> transform_mesh!(x, Rotate(RotX(0.3))))
# NB: we use Rotations.jl's RotX here. Input in radian, use rad2deg and deg2rad if needed.
plantviz!(opf3)

# Same but rotate only the second leaf around the Z axis:
clean_cache!(opf)
opf4 = deepcopy(opf)

# Get the second leaf in the OPF:
leaf_node = get_node(opf4, 8)

# Get the parent node (internode) Z coordinates:
parent_zmax = zmax(leaf_node.parent)

# Define a rotation of the mesh around the Z axis defined by the parent node max Z:
transformation = recenter(Rotate(RotZ(1.0)), Point(0.0, 0.0, parent_zmax))

# Update the transformation matrix of the leaf and its mesh:
transform_mesh!(leaf_node, transformation)

# Plot the result:
plantviz(opf)
plantviz!(opf4)
source
PlantGeom.write_opfMethod
write_opf(file, opf)

Write an MTG with explicit geometry to disk as an OPF file.

Notes

Node attribute :geometry is treated as a reserved keyword and should not be used without knowing their meaning.

Examples

using PlantGeom
file = joinpath(dirname(dirname(pathof(PlantGeom))),"test","files","simple_plant.opf")
opf = read_opf(file)
write_opf("test.opf", opf)
opf2 = read_opf("test.opf")
plantviz(opf2)
source
PlantGeom.write_opsMethod
write_ops(file, scene_dimensions, object_table)

Write a scene file (.ops), with the given dimensions and object table.

Arguments

  • file::String: Path of the .ops file to write.
  • scene_dimensions::Tuple{Meshes.Point{3,T},Meshes.Point{3,T}}: Dimensions of the scene.
  • object_table: Table with the objects to write in the .ops file. The table may have the following columns:
    • sceneID::Int: Scene ID (mandatory).
    • plantID::Int: Plant ID (mandatory).
    • filePath::String: Path to the .opf file (mandatory).
    • pos::Meshes.Point{3,T}: Position of the object (mandatory).
    • functional_group::String: Functional group of the object, used to map the object to the models (mandatory).
    • scale::T: Scale of the object (optional, 0.0 as default).
    • inclinationAzimut::T: Inclination azimut of the object (optional, 0.0 as default).
    • inclinationAngle::T: Inclination angle of the object (optional, 0.0 as default).
    • rotation::T: Rotation of the object (optional, 0.0 as default).

Details

object_table can be of any format that implement the Tables.jl interface, e.g. an array of NamedTuples, a DataFrame...

Example

using Meshes
using Tables
using PlantGeom

scene_dimensions = (Meshes.Point(0.0, 0.0, 0.0), Meshes.Point(100.0, 100.0, 100.0))
positions = [Meshes.Point(50.0, 50.0, 50.0), Meshes.Point(60.0, 60.0, 60.0), Meshes.Point(70.0, 70.0, 70.0)]
object_table = [
    (sceneID=1, plantID=p, filePath="opf/plant_$p.opf", pos=positions[p], functional_group="plant", rotation=0.1) for p in 1:3
]

write_ops("scene.ops", scene_dimensions, object_table)
source
PlantGeom.xmaxFunction
xmax(x)
ymax(x)
zmax(x)

Get the maximum x, y or z coordinates of a mesh or a Node.

source
PlantGeom.xminFunction
xmin(x)
ymin(x)
zmin(x)

Get the minimum x, y or z coordinates of a mesh or a Node.

source
PlantGeom.ymaxFunction
xmax(x)
ymax(x)
zmax(x)

Get the maximum x, y or z coordinates of a mesh or a Node.

source
PlantGeom.yminFunction
xmin(x)
ymin(x)
zmin(x)

Get the minimum x, y or z coordinates of a mesh or a Node.

source
PlantGeom.zmaxFunction
xmax(x)
ymax(x)
zmax(x)

Get the maximum x, y or z coordinates of a mesh or a Node.

source
PlantGeom.zminFunction
xmin(x)
ymin(x)
zmin(x)

Get the minimum x, y or z coordinates of a mesh or a Node.

source
RecipesBase.plotFunction
plot(opf::MultiScaleTreeGraph.Node; kwargs...)
plot!(opf::MultiScaleTreeGraph.Node; kwargs...)

Make a diagram of the MTG tree, paired with a Plots.jl backend.

See also diagram for the same plot with a Makie.jl backend.

Attributes

  • mode = "2d": The mode for plotting, either "2d" or "3d"
  • node_color = :black: the node color, can be a color or any MTG attribute
  • edge_color = node_color: same as node_color, but for the edges
  • colormap = :viridis: the colormap used for coloring
  • color_missing = RGBA(0, 0, 0, 0.3): The color used for missing values

Examples

# import Pkg; Pkg.add("PlotlyJS")
using Plots, PlantGeom
plotlyjs()

file = joinpath(dirname(dirname(pathof(PlantGeom))),"test","files","simple_plant.opf")
# file = joinpath(dirname(dirname(pathof(PlantGeom))),"test","files","coffee.opf")

opf = read_opf(file)

plot(opf, node_color = :Length)
source
RecipesBase.plot!Function
plot(opf::MultiScaleTreeGraph.Node; kwargs...)
plot!(opf::MultiScaleTreeGraph.Node; kwargs...)

Make a diagram of the MTG tree, paired with a Plots.jl backend.

See also diagram for the same plot with a Makie.jl backend.

Attributes

  • mode = "2d": The mode for plotting, either "2d" or "3d"
  • node_color = :black: the node color, can be a color or any MTG attribute
  • edge_color = node_color: same as node_color, but for the edges
  • colormap = :viridis: the colormap used for coloring
  • color_missing = RGBA(0, 0, 0, 0.3): The color used for missing values

Examples

# import Pkg; Pkg.add("PlotlyJS")
using Plots, PlantGeom
plotlyjs()

file = joinpath(dirname(dirname(pathof(PlantGeom))),"test","files","simple_plant.opf")
# file = joinpath(dirname(dirname(pathof(PlantGeom))),"test","files","coffee.opf")

opf = read_opf(file)

plot(opf, node_color = :Length)
source