Module rgg
Package de.grogra.rgg

Class RGG

All Implemented Interfaces:
Manageable, PersistenceCapable, Shareable, RegistryContext, Selectable, UserFields, XObject, Map, Serializable, Observer
Direct Known Subclasses:
LSystem

public class RGG extends Node implements Selectable, RegistryContext, Observer
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:
  • init() is invoked to initialize an RGG instance. This happens after the compilation of its source code and after a reset.
  • startup() 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.
  • shutdown() 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.
  • run(Object) is invoked as a response to the invocation of runLater(Object) or runLater(long, Object). The argument is the argument which has been passed to runLater. The invocation of run is queued in the JobManager of the current workbench and executed in its thread.
A newly compiled RGG induces an initialization of the graph as defined by reset().
Author:
Ole Kniemeyer
See Also:
  • Field Details

  • Constructor Details

    • RGG

      public RGG()
  • Method Details

    • addLock

      public void addLock(Lock li)
    • pullLock

      public Lock pullLock()
    • 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
    • startup

      public static void startup(Registry r, Type type)
    • 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
    • getMainRGG

      public static RGG getMainRGG(RegistryContext r)
    • shutdown

      public static void shutdown(Registry r, Type t)
    • getRGGForTypeMap

      public static Map<String,RGG> getRGGForTypeMap(RegistryContext r)
    • 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
    • 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
    • initializeApplyMenu

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

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

      public static boolean isTransformationMethod(Method m)
    • 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.
    • 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.
    • 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.
    • 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.
    • invokeInit

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

      public void initializeTurtleState(TurtleState s)
    • stop

      public void stop()
      This method can be invoked in order to stop the repeated invocation of a method.
    • 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:
      • Existing interpretive nodes are removed.
      • A transformation boundary is passed in order to apply pending transformations.
      • The current extent is set up such that following ==> rules are treated as interpretive rules. This action is undone at the end of this method.
      • The method interpret() is invoked.
    • interpret

      protected void interpret()
    • getSolver

      public Solver getSolver()
    • setSolver

      public void setSolver(Solver solver)
    • setSolver

      public void setSolver(org.apache.commons.math3.ode.FirstOrderIntegrator integrator)
    • 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, 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, 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
    • unmonitor

      protected void unmonitor()
      Remove all currently set monitor functions. This will be called implicitly after integrate(double) if isAutoClearMonitors() is true.
    • 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
    • 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
    • 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

      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

      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.
    • ignore

      protected void ignore(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
    • consider

      protected void consider(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
    • 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
    • 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
    • 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, String plane, Node node)
    • getTasks

      public ConcurrentTasks getTasks()
      Returns an instance of ConcurrentTasks which is associated with this RGG.
      Returns:
      instance of ConcurrentTasks for use within this RGG
    • 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
    • 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).
    • runLater

      public void runLater(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)
    • runLater

      public void runLater(long delay, 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)
    • run

      protected void run(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
    • observe

      public void observe(ScaleClass s, Object arg, String methodName)
      Register the method (by its name) to invoke given the notification from an observable and an argument object.
      Parameters:
      s -
      arg -
      methodName -
    • observe

      public void observe(ScaleClass s, int arg, String methodName)
      Register the method (by its name) to invoke given the notification from an observable and an argument object.
      Parameters:
      o -
      arg -
      methodName -
    • update

      public void update(Observable o, Object arg)
      Method invoked when the observable object observed by this object invokes notify
      Specified by:
      update in interface Observer
    • 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
    • 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