Working with MTG in Openalea and exporting the MTG to GroIMP

Hi,

I am using plantscan3D to reconstruct the topology of a leafless plant from a 3d point cloud. Plantscan3D gives me the following mtg as output, that is a list of nodes, instead of internodes. Do you know if Openalea.mtg can convert this list of nodes in a list of internodes (with their length, inclination, and diameters)?

CODE :  	FORM-A

CLASSES :
SYMBOL	SCALE	DECOMPOSITION	INDEXATION	DEFINITION
$	0	FREE	FREE	IMPLICIT
P	1	FREE	FREE	EXPLICIT
N	2	FREE	FREE	EXPLICIT

DESCRIPTION :
LEFT	RIGHT	RELTYPE	MAX
P	P	<	?
P	P	+	?
N	N	<	?
N	N	+	?

FEATURES :
NAME	TYPE
XX	REAL
YY	REAL
ZZ	REAL
radius	REAL

MTG :
ENTITY-CODE			XX	YY	ZZ	radius
/P						
^/N			5.248443218780803	73.06494354349961	-7.031594088906226	2.4137014477037395
^<N			4.889759287475431	71.72857781032648	-7.644402165893186	2.6168209609975355
^<N			4.6069335325123735	67.84877379035905	-6.973345804495052	2.432544704131437
	+N		11.013382159550174	68.39569763245449	1.0417601655762854	2.0794498718238503
		+N	12.792504690221982	64.23079914006823	3.034597206648359	2.6232951441088033
		^<N	16.20684863342351	60.70695086486208	5.300659764471138	2.8343774592140245
		^<N	18.97833108755337	59.24096149981203	7.754736952243863	2.391653421774906
^<N			3.570239078594491	62.60848800756486	-7.557524548899295	2.746142798096636
	+N		0.14384842150109442	61.82603690662265	-16.92815939232912	2.853906251293676
	^<N		2.767903250740018	59.474661176542206	-25.25567294026061	1.906252272260073
^<N			3.6172941591758416	57.257888898301964	-5.208176418652122	3.089129751574498
^<N			4.324714389943549	51.840894309125105	-5.366176635359147	2.539112692887605
	+N		10.874431363859584	49.44920079616662	-8.183778663493868	1.2226536626849875
	^<N		15.506269986100598	47.06353257481447	-10.367801493211715	1.3599099039520268
^<N			2.327236248329535	47.07571485581331	-4.6544305319868124	2.7140932351706057
^<N			1.360599645041318	42.25860932415444	-4.452158604069243	2.691696932149381
^<N			0.13606359652561706	37.19644141435886	-4.279109035839622	2.5726050330614085
	+N		-9.549779334487198	31.4922882882708	-7.356393770832838	1.4683911726187324
	^<N		-13.989773176686505	29.35781023102802	-8.971175498429766	1.3521757267850447
	^<N		-16.50279786976688	27.39049475992383	-9.939129948764588	1.4222848844807694

I also would like to import and MTG file into GroIMP. Unforutunately, the MTG importer of GroIMP is broken and the developers cannot fix it.

As far as I understood there should be a way to import MTG from Openalea to GroIMP but I cannot find documentation. Can someone give me some guidance?
Openalea–>GroIMP.

I cant say anything about the first part, but for importing MTG to GroIMP:
first of all you are right fixing the MTG importer for GroIMP is a difficult task and has for now a lower priority for us in Göttingen. One reason for that is, that we currently work on improving the XEG file format which was designed to transfer Models between OpenAlea and GroIMP. XEG is explained in the work of Qinqin (THE INTEGRATION OF DIFFERENT FUNCTIONAL AND STRUCTURAL PLANT MODELS).

Importing and exporting XEG files in GroIMP is implemented (with small issues) in all current GroIMP versions (1.5, 1.6 2.0,2.1).

The import and export for XEG in OpenAlea is published on github

1 Like

thank you!
I tried to have a look at that repository but I am able to understand the steps to follow - considering also that I also don’t have knowledge about openalea.
Did you try it yourself? Would you know where to start?

I my self never worked with OpenALEA but I think there is a description in Qinqin’s work…
Otherwise you can ask Christophe @pradal, maybe he can help you

1 Like

Hi guys!
What you want is to convert an MTG generated by PlantScan and transforming it to GroIMP?
Because we developped PlantScan and MTG in the same team, it may possible :wink:

MTG represents plant internodes and not plant nodes.
Vertces in MTG are modularities (e.g. Internodes, phytomer, axis, plant, …).
But the X, Y, Z coordinates are the top position of the internode (i.e. the uper node).

I am currently working to update the connection between OpenAlea and GroIMP.
When we will have nice results, I will update the discussion.
We may even write a tuto with PlantScan, MTG and GroIMP…
Stay tuned!

2 Likes

Hi Michele, regarding the conversion from nodes to internodes, you can make a custom function in XL, where you first import the node measurements (x, y, z, radius) to GroIMP and then use this information to calculate location and direction of the internodes, by working with transformation matrices. We did something similar for mangrove reconstruction. I can help with that.

2 Likes

Hi Michele,

I actually almost had a similar issue. So plantscan already has a build in solution to get internode length → nodelength. You could use following code. Radius and angles require some additional work.

def angleEstimate(g,file_name):
    """code copied from mainviewer line 2877"""
    from openalea.plantscan3d.angleanalysis import lines_estimation, phylo_angles, lines_representation, write_phylo_angles
    trunk_line, lateral_lines, nodelength = lines_estimation(mtg=g,degree=3)
    print(type(trunk_line), trunk_line)
    if hasattr(trunk_line, 'isValid') and not trunk_line.isValid():
        print('Invalid approximation', 'Invalid approximation')
        return
    phyangles = phylo_angles(trunk_line, lateral_lines)
    fname = str(file_name.parent / 'output_openalea_angles.txt')
    print('filename',fname)
    print('length of filename',len(fname))
    if len(fname) == 0: return
    write_phylo_angles(str(fname), phyangles, nodelength)
1 Like

A little update:

Thanks to the Julia Packages written by @rvezy, I managed to automate the conversion of the MTG of Nodes (output of PlantScan3D) to the MTG of Organs (more useful for FSPM softwares) - thank you @pradal for pointing that out. (I can share the code of course, it would by nice to include it in a package? @rvezy )

In the meantime, I also included in my Groimp model a way to interpret a MTG file (saved as .csv) and convert it to a functional 3d plant. I got immense help from @ksmolen and @JoraddeVries, thank you.

I frequently hear requests for this functionality, so it would be great if the Groimp developer could improve my code even more and possibly include it in the XL language(@tim @gaetanH ).

1 Like

Hi Michele,

It is possible to make your project a part of GroIMP, the easier way is to make a plugin out of your solution. That way any user can get it in their groimp environment. (the plugin can add file formats for import/export, internal operations to process the graphs, …).

There is documentation on our gitlab wiki with examples to show how to do it and I am available if you have any questions.

You can also share your code with me so we can see what could be improved even more.

Best,
Gaetan

1 Like

awesome! I will fix one thing in the code and then share it with you