Table of Contents

Post processing a QSM with RGG

The combination of GroIMPs rule based graph manipulation and the QSM descriptors can be used to implements code based processing filters to improve a reconstructed tree.

In this tutorial, we will create two simple example methods to improve a QSM model. These examples are designed to be simple and understandable rather than scientifically sound.

Requirements

This tutorial requires GroIMP 2.2.1 with the QSM plugin version 2.2.2.

Preparation

We start by creating a new RGG project in GroIMP. (in the main menu 'File > New > RGG Project'). In this project we will define the functions that can be used to filter any QSM that is later imported.

To do so we first need to make sure out scene is empty by replacing the current code of Model.rgg with, an init function that replaces the axiom by nothing:

protected void init ()[
  Axiom ==> ;
]                                       

If we save this the green sphere in the 3d view will disappear.

Remove unrealistic branches

The first function we want to try is aiming at lateral branches that are clearly to long. We do this by using the QSM descriptor RTREND which describes the reverse trend (the number of apical successor on the same branch).

Our assumption here is that a lateral shoot should not have a much higher reverse trend than its parent, since this would mean that the lateral branch is much longer and (based on the assumption of annual shoots) also likely to be much older.

To find this kind of mismatch we first find all shoots ($fchild$ with the context of having a branch connection('+>') to their parent($fparent$):

(*fparent:F*) +> fchild:F 

Further we introduce the condition that the reverse trend of the child is more than 5 times as high as the one of the parent:

(*fparent:F*) +> fchild:F,(fparent[RTREND]*5 < fchild[RTREND])

If this is the case we remove the lateral child by replacing it with nothing using a single push out rule:

(*fparent:F*) +> fchild:F,(fparent[RTREND]*5 < fchild[RTREND]) ==>>;

To Use this in RGG we first need to import the descriptors and then create a function around our new rule:

import static de.grogra.qsm.utils.Descriptors.*;
protected void init ()
[
	Axiom ==>;
]
 
public void remove_unrealistic_branches ()[
	(*fparent:F*) +> fchild:F,(fparent[RTREND]*5 < fchild[RTREND]) ==>>;
]

The images below show the effect of this filter:

Use predicted diameters

The GroIMP QSM descriptors include the estimation for a Estimated sap wood radius based on a pipe model.

A very simple filtering approach could be to update all cylinders in the scene with this estimated diameter instead of the original one:

The rule for this is quite simple:

Update all F and set the diameter for each of them to twice the SAPWOOD_RADIUS estimated for them. It is important to use := as an assignment to apply all changes semi parallel at the end (otherwise the first changes could influence the later once.)

public void update_diameter()[
	f:F ::>{
		f[diameter]:=f[SAPWOOD_RADIUS]*2;
	}
]

Applied on the example tree this changes the appearance as following: