AMAPstudio

User Tools


Interesting topics

This is a non exhaustive list of things which were built by some modellers for a particular case and which could be used by other people in Capsis.

A simple viewer to show tables or texts at a given date

An easy way to check a simulation by displaying a text or tabular view that can be synchronized on all its steps. This generic viewer is compatible with the models which MethodProvider object implements TablesInterface (capsis.util.methodprovider package).

This interface declares a single method named getTables (…). You may return a Map with one or more entries.

The key is the name of the table. The value is a String with a textual description of the scene under the given simlation Step. If the perHectare parameter is true, the description should be calculated per hectare.

It is possible to return a text with several lines by adding newline characters : '\n' in the value String. It is thus possible to build tables like in the upper example, one line per simulation step from the root step of the simulation.

If several entries are returned in the map, the viewer will show them in several tabs with matching names.

public interface TablesInterface {
 
    /**
     * Returns a Map of Strings (supposed to be tables: several lines with \n)
     * to be printed in the SVTables. Key in the map is the table name, value is
     * the table itself.
     */
    public Map<String, String> getTables(Step step, boolean perHectare);
 
}

Spatializer / Avatars viewer

This feature was built with Sergio de Miguel in the Optimist module. This module contains several models (one is chosen at simulation start time). These models may be spatialized or not. It is possible to view all stands in a spatialized viewer by using the capsis.defaulttype.Spatializer interface and the SVAvatar viewer.

Spatializer is available for the Capsis modules which scene class extends capsis.defaulttype.TreeList and the trees extends capsis.defaulttype.Tree. The Model class must implement Spatializer and provide a getAvatars () method.

/**
 * Returns a list of individual spatialized avatars for the trees
 * (individuals or class widths) in the given treeList.
 */
public List<TreeAvatar> getAvatars(TreeList treeList);

The method must return a list of capsis.defaulttype.TreeAvatar instances, i.e. spatialized individual images of the trees in the stand. Thus, for a model with Numberable tree classes (i.e. represents several trees), the method will return n avatars with n = tree.getNumer () for each tree class.

It is important that the avatars of a single Numberable tree are kept on the same locations all along the simulation. To spatialize in a consistent manner the avatars of a single Numberable tree, the following kind of method can be used. The trick is to pass the tree id (unique in the scene) at instanciation time to the random number generator. Then if you draw n times an x and a y, they will be the same at each call of the method, consequently each time the viewer is synchronized on a different step of the simulation.

You may notice that each avatar holds a reference to the original tree it represents at its current location. TreeAvatars provide a simple description for the crown. Other avatar classes could be built to represent more complex crowns if needed.

Random random = new Random(t.getId());
double xSize = treeList.getXSize();
double ySize = treeList.getYSize();
 
for (int i = 0; i < t.getNumber(); i++) {
	String name = "";
 
	double x = random.nextDouble() * xSize;
	double y = random.nextDouble() * ySize;
	double z = 0;
 
	TreeAvatar a = new TreeAvatar(t.getId(), name, x, y, z,
			t.getDbh(), t.getHeight(), trunkColor);
 
	double crownBaseHeight = 0.5d * t.getHeight();
	double crownRadius = 0.33 * crownBaseHeight;
	double[][] crownProfile = BrutiauaModel.crownProfile;
	a.setCrown(crownBaseHeight, crownRadius, crownColor,
			crownProfile);
 
	a.setRealTree(t);
 
	Vertex3d relativeMin = new Vertex3d(-crownRadius,
			-crownRadius, 0);
	Vertex3d relativeMax = new Vertex3d(crownRadius,
			crownRadius, t.getHeight());
	a.setRelativeMin(relativeMin);
	a.setRelativeMax(relativeMax);
 
	list.add(a);
}
documentation/interesting_topics.txt · Last modified: 2013/05/23 08:25 (external edit)