A function to export in a pseudo-MTG format

Hi,
I would like that at every step of my dynamic model an file with the architecture of the each plant is generated.

The following function does more or less the job, however, it is still very rudimental, and I would like it to be smarter, specifically in the section where I pull the information from each organ and put it in a row to be attached to the CSV.

Is there a way to specify the name of the header of the column to which a specific value should go?


static void exportMTG() {

// Set the output file, where the computed values should be stored
        PrintWriter out = new PrintWriter(new FileWriter(PATH_EXPORT + MTG_EXPORT, false));

        // Headers
        String[] headers = new String[52]; // Size based on the maximum column index used

        headers[column_ID] = "ID";
        headers[column_order] = "order";
        headers[column_rank] = "rank";
       // Etc...

        // Write headers to CSV
        for (int i = 0; i < headers.length; i++) {
            if (headers[i] != null) {
                out.print(headers[i]);
                if (i < headers.length - 1) {
                    out.print(",");
                }
            }
        }
        
     [
         o:GrowingOrgan ::> {	

///MY PROBLEM IS HERE BELOW: at the moment every new variable added need to be following the exact same order of the headers from the csv
         out.println(o[ID]+","+l[rank]+","+o[order]+","+o[rank]);
			
		}
	]
        out.flush();
        out.close();
}

Or better: is there a way to export ALL the information for every organ in a simple way?

did you consider using the MTG export (which to my knowledge should work) in your code similar to some thing like this:


int i=1;
public void run ()
[
	A(x) ==> F(x) [RU(30) RH(90) A(x*0.8)] [RU(-30) RH(90) A(x*0.8)];

	{
		export3DScene("/home/tim/test"+i+".mtg","mtg",false);
	i++;
	}
]

Thank you!
It is almost perfect!

However, I noticed a few bugs

  • The indentation of plants is wrong: every new plant should be in the same column as the former plant, instead, they get shifted to the right column. In the yellow lines, you can see new plants

  • The letters in the F column indicate the organ type. Apparently, they must be numbers, the mtg export doesn’t allow for a string

  • the symbols indicating the same organs change! organType 2 is sometimes called FREE, sometimes + , another time <

Hi Michele,

I never really looked into the MTG export format so I can’t help you much here.

For the numbers and Key mapping you can have a look in the source code (src/main/java/de/grogra/mtg/MTGKeys.java · master · Grogra / GroIMP plugins / RGG · GitLab) where this mapping is defined.

For the plant indexing issue, it could comes from how the GroIMP graph is not really designed to support multiple plants in one graph (unlike mtg).
In GroIMP it is not possible by default to have several plants in the mtg sense. So you will not have your plants on the first columns.

Knowing that, I see two options to export them:

  1. You keep the new plants in the second column. The first being the RGGRoot
  2. You export each plant in a separate mtg

In any case you need to make sure that the plants are not added as branch or successor from another plant (which is what you probably have done looking at your mtg export).

For instance in the example:

Axiom ==> for (int i=0;i<4;i++)(
	[RU(90*i) M RU(-90*i) Plant]
      );

Each Plant is added as branch to the RGGRoot.
And in:

Axiom ==> for (int i=0;i<4;i++)(
	RU(90*i) M RU(-90*i) Plant
	);

The plants are added to the previous Plant as branch.

If you export the first example, each Plant will be in the second column, with their successors. Their branches will be in the next column.

Once you have each Plant not being linked with another one by a successor or branch edge, you can export them in separate files:
E.g.:

module A extends Sphere;
module Plant extends F;

protected void init ()
[
	Axiom ==> for (int i=0;i<4;i++)(
	[RU(90*i) M RU(-90*i) Plant F F [F A] [RU(50) A] ]);
]

public void run ()
[
	{int i=0;}
	p:Plant ::> {export3DScene("/home/gaetan/eclipse-workspace/test"+i+
		".mtg", "mtg", p);
	i++;}
]

This will export each subgraph under a Plant node in a separate file. (Note that there was a bug in the mtg export for subgraph it should be solved if you download rgg 2.1.4).

2 Likes