de.grogra.rgg
Class RGG

java.lang.Object
  extended by de.grogra.graph.impl.Edge
      extended by de.grogra.graph.impl.Node
          extended by de.grogra.rgg.RGG
All Implemented Interfaces:
Manageable, PersistenceCapable, Shareable, RegistryContext, Selectable, UserFields, XObject, Map, java.io.Serializable
Direct Known Subclasses:
LSystem

public class RGG
extends Node
implements Selectable, RegistryContext

This class is the base class of all instances of relational growth grammars within GroIMP. The main class of an rgg-file automatically extends this class.
This class declares some methods which may be overriden by subclasses in order to respond to specific events:

A newly compiled RGG induces an initialization of the graph as defined by reset().

Author:
Ole Kniemeyer
See Also:
Serialized Form

Nested Class Summary
 class RGG.Apply
           
 
Nested classes/interfaces inherited from class de.grogra.graph.impl.Node
Node.AccessorBridge, Node.FieldAttributeAccessor, Node.NType
 
Nested classes/interfaces inherited from interface de.grogra.util.Map
Map.Chain
 
Field Summary
static Node.NType $TYPE
           
static Node.NType.Field classesToIgnoreOrConsider$FIELD
           
static Node.NType.Field consider$FIELD
           
static Node.NType.Field doRun$FIELD
           
static EnumerationType GROUP_TYPE
           
static I18NBundle I18N
           
protected  TurtleState initialTurtleState
           
static Node.NType.Field initialTurtleState$FIELD
           
static UIProperty STEPRUN
           
 
Fields inherited from class de.grogra.graph.impl.Node
ADDITIONAL_FIELDS, bits, DELETED, EXTENT_BIT, EXTENT_MASK, extentIndex$FIELD, extentTail$FIELD, HAS_OBSERVERS, IS_INTERPRETIVE, isInterpretive$FIELD, LAST_EXTENT_INDEX, layer$FIELD, MARK, mark$FIELD, MIME_TYPE, MIN_UNUSED_SPECIAL_OF_SOURCE, MIN_UNUSED_SPECIAL_OF_TARGET, name$FIELD, USED_BITS
 
Fields inherited from interface de.grogra.util.Map
DEFAULT_VALUE, EMPTY_MAP
 
Constructor Summary
RGG()
           
 
Method Summary
 void addTask(ConcurrentTask task)
          Adds a single task to the set of tasks of this RGG (see getTasks()).
protected  void applyInterpretation()
          This method can be invoked if interpretive rules shall be applied to the current graph by the method interpret().
protected  void consider(java.lang.Class... consider)
          Sets the node classes which shall be considered by the methods left(Node) and right(Node).
static RGG getMainRGG(RegistryContext r)
           
protected  Node.NType getNTypeImpl()
          This method returns the Node.NType which describes the managed fields of the class of this node.
protected  void getRate()
          Override this to provide the rate function using the rate assignment operator :'=.
 Registry getRegistry()
          Returns the Registry which is linked with this instance.
static java.util.Map<java.lang.String,RGG> getRGGForTypeMap(RegistryContext r)
           
 Node getRoot()
          Returns the RGG root of the graph.
 Solver getSolver()
           
 ConcurrentTasks getTasks()
          Returns an instance of ConcurrentTasks which is associated with this RGG.
protected  void ignore(java.lang.Class... ignore)
          Sets the node classes which shall be ignored by the methods left(Node) and right(Node).
protected  void init()
          This method is invoked to initialize an RGG This happens after the compilation of its source code and after a reset.
protected  void initializeApplyMenu(Item d, boolean flat, boolean useRunCheckBox)
           
protected  void initializeRunMenu(Item d, boolean flat, boolean useRunCheckBox)
           
 void initializeTurtleState(TurtleState s)
           
protected  void integrate()
          Integrate numerically using the ODE framework for an unlimited duration of time units.
protected  void integrate(double duration)
          Integrate numerically using the ODE framework over a duration of duration time units.
protected  void interpret()
           
 void invokeInit()
          This method is used to invoke the normally protected init-method when compiler is called from outside GroIMP.
 boolean isAutoClearMonitors()
          Get whether if all monitors should be removed automatically after integration.
protected  boolean isMainRGG()
          Determins whether this RGG should be used as the project's main RGG.
 Node left(Node n)
          Computes the first neighbour to the left of n which is not an instance of one of the classes set by ignore(Class[]).
protected  void monitor(VoidToDouble g)
          Install a monitor function that generates an event when the returned value changes its sign.
protected  void monitor(VoidToDouble g, java.lang.Runnable r)
          Install a monitor function that generates an event when the returned value changes its sign.
protected  void monitorPeriodic(double period, java.lang.Runnable r)
          Trigger an event in regular intervals and call the event handler.
protected  Node newInstance()
          This method returns a new instance of the class of this node.
 float readChannelAt(int channel, Parallelogram plane, float x, float y, float z)
           
 float readChannelAt(int channel, Parallelogram plane, Node node)
           
 float readChannelAt(int channel, java.lang.String plane, Node node)
           
protected  void reset()
          This method can be invoked to reset the RGG to its initial state.
 Node right(Node n)
          Computes the first neighbour to the right of n which is not an instance of one of the classes set by ignore(Class[]).
protected  void run(java.lang.Object arg)
          This callback method is invoked as a response to the invocation of runLater(Object) or runLater(long, Object).
 void runLater(long delay, java.lang.Object arg)
          This method is used to induce an invocation of run(Object) in the thread of the JobManager of the current workbench after a delay of at least delay milliseconds.
 void runLater(java.lang.Object arg)
          This method is used to induce an invocation of run(Object) in the thread of the JobManager of the current workbench.
 void setAutoClearMonitors(boolean autoClearMonitors)
          Set whether if all monitors should be removed automatically after integration.
 void setSolver(org.apache.commons.math.ode.FirstOrderIntegrator integrator)
           
 void setSolver(Solver solver)
           
protected  void shutdown()
          This method is invoked when an RGG instance is unloaded within GroIMP.
static void shutdown(Registry r, Type t)
           
 void solveTasks()
          This method simply invokes ConcurrentTasks.solve() on the set of tasks of this RGG (see getTasks()).
protected  void startup()
          This method is invoked when an RGG instance is loaded within GroIMP.
static void startup(Registry r, Type type)
           
 void stop()
          This method can be invoked in order to stop the repeated invocation of a method.
 Selection toSelection(Context ctx)
          Converts this object into a Selection.
protected  void unmonitor()
          Remove all currently set monitor functions.
 
Methods inherited from class de.grogra.graph.impl.Node
addEdgeBitsTo, addReference, appendBranchNode, appendBranchNode, appendReferencesTo, clone, clone, cloneGraph, dump, dumpTree, dup, dupUnmanagedFields, edgeChanged, fieldModified, findAdjacent, get, getAccessor, getAccessor, getAttributes, getAxisParent, getBoolean, getBranch, getBranchLength, getBranchNode, getBranchTail, getByte, getChar, getCommonAncestor, getCurrentGraphState, getDirectChildCount, getDouble, getEdgeAttributeAccessor, getEdgeAttributes, getEdgeBitsTo, getEdgeTo, getExtentIndex, getFirst, getFirstEdge, getFloat, getGraph, getId, getIndex, getInstantiator, getInt, getLayer, getLong, getManageableType, getName, getNeighbor, getNext, getNType, getObject, getOrCreateEdgeTo, getOrNull, getPersistenceManager, getPredecessor, getProvider, getShort, getSource, getStamp, getSuccessor, getSymbol, getSymbolColor, getTarget, getTransaction, getUserField, getUserFieldCount, getXClass, getXData, hasName, initProvider, initXClass, insertBranchNode, insertBranchNode, instantiateGraph, isAncestorOf, isDirection, isManagingInstance, isMarked, isRoot, isSource, isTarget, manageableReadResolve, manageableWriteReplace, paramString, removeAll, removeEdgeBitsTo, removeFromChain, removeFromChain, removeReference, setBranch, setBranch, setExtentIndex, setGraphForDeserialization, setLayer, setMark, setName, setSuccessor, setSuccessor, specialEdgeAdded, specialEdgeRefModified, specialEdgeRemoved, toString, writeReplace
 
Methods inherited from class de.grogra.graph.impl.Edge
addEdgeBits, getBitMark, getEdgeBits, getObjectMark, getSpecialEdgeDescriptor, parseEdgeKeys, remove, removeEdgeBits, setBitMark, setEdgeBits, setObjectMark, testEdgeBits
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.grogra.persistence.PersistenceCapable
getBitMark, getObjectMark, setBitMark, setObjectMark
 

Field Detail

$TYPE

public static final Node.NType $TYPE

classesToIgnoreOrConsider$FIELD

public static final Node.NType.Field classesToIgnoreOrConsider$FIELD

consider$FIELD

public static final Node.NType.Field consider$FIELD

doRun$FIELD

public static final Node.NType.Field doRun$FIELD

GROUP_TYPE

public static final EnumerationType GROUP_TYPE

I18N

public static final I18NBundle I18N

initialTurtleState

protected TurtleState initialTurtleState

initialTurtleState$FIELD

public static final Node.NType.Field initialTurtleState$FIELD

STEPRUN

public static final UIProperty STEPRUN
Constructor Detail

RGG

public RGG()
Method Detail

addTask

public void addTask(ConcurrentTask task)
Adds a single task to the set of tasks of this RGG (see getTasks()). After all tasks have been added, the method solveTasks() has to be invoked in order to solve the tasks concurrently using a number of threads or even distributed computers.

Parameters:
task - task to add

applyInterpretation

protected void applyInterpretation()
This method can be invoked if interpretive rules shall be applied to the current graph by the method interpret(). The effect of applyInterpretation is the following:


consider

protected void consider(java.lang.Class... consider)
Sets the node classes which shall be considered by the methods left(Node) and right(Node). This method may be invoked as a variable arity method, i.e., with a variable number of arguments of class Class.

Parameters:
consider - an array of classes to be considered

getMainRGG

public static RGG getMainRGG(RegistryContext r)

getNTypeImpl

protected Node.NType getNTypeImpl()
Description copied from class: Node
This method returns the Node.NType which describes the managed fields of the class of this node. This method has to be implemented in every concrete subclass.

Overrides:
getNTypeImpl in class Node
Returns:
type describing the managed fields of the class of this node

getRate

protected void getRate()
Override this to provide the rate function using the rate assignment operator :'=. The state is passed implicitly as the current graph, and graph queries can be used to calculate the rates.


getRegistry

public Registry getRegistry()
Description copied from interface: RegistryContext
Returns the Registry which is linked with this instance.

Specified by:
getRegistry in interface RegistryContext
Returns:
the registry linked with this instance

getRGGForTypeMap

public static java.util.Map<java.lang.String,RGG> getRGGForTypeMap(RegistryContext r)

getRoot

public Node getRoot()
Returns the RGG root of the graph. This is not necessarily the real root of the graph: If there exists a branch edge from the real root to an instance of RGGRoot, then this instance is returned. Otherwise, the real root is returned.

Returns:
RGG root of graph

getSolver

public Solver getSolver()

getTasks

public ConcurrentTasks getTasks()
Returns an instance of ConcurrentTasks which is associated with this RGG.

Returns:
instance of ConcurrentTasks for use within this RGG

ignore

protected void ignore(java.lang.Class... ignore)
Sets the node classes which shall be ignored by the methods left(Node) and right(Node). This method may be invoked as a variable arity method, i.e., with a variable number of arguments of class Class.

Parameters:
ignore - an array of classes to be ignored

init

protected void init()
This method is invoked to initialize an RGG This happens after the compilation of its source code and after a reset.
The default implementation does nothing. It may be overridden by subclasses in order to perform some initialization. This may include the creation of an initial graph structure, or the initialization of field values.


initializeApplyMenu

protected void initializeApplyMenu(Item d,
                                   boolean flat,
                                   boolean useRunCheckBox)

initializeRunMenu

protected void initializeRunMenu(Item d,
                                 boolean flat,
                                 boolean useRunCheckBox)

initializeTurtleState

public void initializeTurtleState(TurtleState s)

integrate

protected void integrate()
                  throws NumericException
Integrate numerically using the ODE framework for an unlimited duration of time units. This is implemented by calling integrate(double) with a duration of java.lang.Double.MAX_VALUE. To stop the integration a monitor must be set.

Throws:
NumericException
See Also:
integrate(double), monitor(VoidToDouble)

integrate

protected void integrate(double duration)
                  throws NumericException
Integrate numerically using the ODE framework over a duration of duration time units. The user has to provide a rate function dy/dt=f(t,y) to calculate the first derivative of the state vector with respect to time for a given time and state pair. The rate function f(t,y) is implemented by overriding the function getRate(). The user should not make any assumptions about how many times or with which parameters of time and state the function getRate() will be called. Since laws of physics do not depend on the current time the parameter t of f(t,y) is hidden from the user. The state y is provided implicitly as the attributes of the nodes in the current graph.

Parameters:
duration - time duration over which to integrate
Throws:
NumericException
See Also:
getRate()

interpret

protected void interpret()

invokeInit

public void invokeInit()
This method is used to invoke the normally protected init-method when compiler is called from outside GroIMP.


isAutoClearMonitors

public boolean isAutoClearMonitors()
Get whether if all monitors should be removed automatically after integration.

Returns:
true if all monitors should be removed after integration automatically

isMainRGG

protected boolean isMainRGG()
Determins whether this RGG should be used as the project's main RGG. The main RGG creates menu entries in the RGG toolbar. A project must not contain more than one main RGG.

This default implementation defines an RGG to be the main RGG iff its class declares a public void method with no arguments, or an init method. This method should be overwritten by non-main RGGs for which this simple definition is not sufficient.

Returns:
true iff this RGG is the main RGG of a project

left

public Node left(Node n)
Computes the first neighbour to the left of n which is not an instance of one of the classes set by ignore(Class[]). The neighbours to the left are those which are reachable by successor or branch edges in reverse direction.

Parameters:
n - where to start the search
Returns:
first neighbour to the left, excluding instances of ignored classes

monitor

protected void monitor(VoidToDouble g)
Install a monitor function that generates an event when the returned value changes its sign. The monitor must not modify the state of the graph.

Parameters:
g - monitor function

monitor

protected void monitor(VoidToDouble g,
                       java.lang.Runnable r)
Install a monitor function that generates an event when the returned value changes its sign. The monitor must not modify the state of the graph. When the event triggers, the event handler is called.

Parameters:
g - monitor function
r - event handler

monitorPeriodic

protected void monitorPeriodic(double period,
                               java.lang.Runnable r)
Trigger an event in regular intervals and call the event handler. Additionally, the write lock on the graph (automatically obtained when executing rules) is temporarily released so that modifications to the attributes made in the event handler will become visible.

Parameters:
g - monitor function
r - event handler

newInstance

protected Node newInstance()
Description copied from class: Node
This method returns a new instance of the class of this node. This method has to be implemented in every concrete subclass.

Overrides:
newInstance in class Node
Returns:
new instance of class of this node

readChannelAt

public float readChannelAt(int channel,
                           Parallelogram plane,
                           float x,
                           float y,
                           float z)

readChannelAt

public float readChannelAt(int channel,
                           Parallelogram plane,
                           Node node)

readChannelAt

public float readChannelAt(int channel,
                           java.lang.String plane,
                           Node node)

reset

protected void reset()
This method can be invoked to reset the RGG to its initial state. The following steps are performed:
  1. If there is an instance of RGGRoot which is connected with the real root of the graph by a branch edge, then this instance is removed. A new instance of RGGRoot is created and connected with the real root by a branch edge.
  2. A new instance of Axiom is created and inserted in the graph by a successor edge from the RGGRoot instance. The result of this step is a graph containing an RGGRoot which has a single Axiom as its successor.
  3. The method init() is invoked. This invocation is surrounded by transformation boundaries (see Library.apply()).
This method is also invoked when a newly compiled RGG is instantiated.


right

public Node right(Node n)
Computes the first neighbour to the right of n which is not an instance of one of the classes set by ignore(Class[]). The neighbours to the right are those which are reachable by successor edges in forward direction.

Parameters:
n - where to start the search
Returns:
first neighbour to the right, excluding instances of ignored classes

run

protected void run(java.lang.Object arg)
This callback method is invoked as a response to the invocation of runLater(Object) or runLater(long, Object). arg is the argument which has been passed to runLater. The invocation is executed in the thread of the JobManager of the current workbench. In addition, a write-lock on the graph is being aquired during execution.
The default implementation does nothing.

Parameters:
arg - the argument which has been passed to runLater

runLater

public void runLater(long delay,
                     java.lang.Object arg)
This method is used to induce an invocation of run(Object) in the thread of the JobManager of the current workbench after a delay of at least delay milliseconds. The invocation is queued in the job manager, i.e., it is performed after all pending jobs have been completed and after the delay is elapsed.

Parameters:
delay - delay in milliseconds
arg - argument to pass to run(Object)

runLater

public void runLater(java.lang.Object arg)
This method is used to induce an invocation of run(Object) in the thread of the JobManager of the current workbench. The invocation is queued in the job manager, i.e., it is performed after all pending jobs have been completed.

Parameters:
arg - argument to pass to run(Object)

setAutoClearMonitors

public void setAutoClearMonitors(boolean autoClearMonitors)
Set whether if all monitors should be removed automatically after integration.

Parameters:
autoClearMonitors - if true, all monitors should be removed after integration automatically

setSolver

public void setSolver(org.apache.commons.math.ode.FirstOrderIntegrator integrator)

setSolver

public void setSolver(Solver solver)

shutdown

protected void shutdown()
This method is invoked when an RGG instance is unloaded within GroIMP. This happens to an old RGG instance after compilation when this old instance is to be replaced by the newly compiled RGG instance.
If this method is overriden, super.shutdown(); should be invoked.


shutdown

public static void shutdown(Registry r,
                            Type t)

solveTasks

public void solveTasks()
This method simply invokes ConcurrentTasks.solve() on the set of tasks of this RGG (see getTasks()). This solves all added tasks (see addTask(ConcurrentTask)) concurrently using the available resources (multiple processors, distributed computers).


startup

protected void startup()
This method is invoked when an RGG instance is loaded within GroIMP. This happens after the compilation of its source code and after loading a project containing an RGG.
If this method is overridden, super.startup(); should be invoked at first.


startup

public static void startup(Registry r,
                           Type type)

stop

public void stop()
This method can be invoked in order to stop the repeated invocation of a method.


toSelection

public Selection toSelection(Context ctx)
Description copied from interface: Selectable
Converts this object into a Selection.

Specified by:
toSelection in interface Selectable
Parameters:
ctx - the UI context
Returns:
a selection, or null if this is not possible

unmonitor

protected void unmonitor()
Remove all currently set monitor functions. This will be called implicitly after integrate(double) if isAutoClearMonitors() is true.