org.jaitools.jiffle.runtime
Class AbstractJiffleRuntime

java.lang.Object
  extended by org.jaitools.jiffle.runtime.AbstractJiffleRuntime
All Implemented Interfaces:
JiffleRuntime
Direct Known Subclasses:
AbstractDirectRuntime, AbstractIndirectRuntime

public abstract class AbstractJiffleRuntime
extends java.lang.Object
implements JiffleRuntime

Provides default implementations of JiffleRuntime methods plus some common fields. The fields include those involved in handling image-scope variables and script options; an instance of JiffleFunctions; and an integer stack used in evaluating con statements.

Since:
0.1
Version:
$Id: AbstractJiffleRuntime.java 1653 2011-06-16 10:23:02Z michael.bedward $
Author:
Michael Bedward

Nested Class Summary
 class AbstractJiffleRuntime.ImageScopeVar
          Holds information about an image-scope variable.
 
Field Summary
protected  JiffleFunctions _FN
          Provides runtime function support.
protected  boolean _imageScopeVarsInitialized
          Whether the image-scope variables have been initialized.
protected  int _numVars
          The number of image-scope variables defined.
protected  double _outsideValue
          The value to return for out-of-bounds image data requests if the outside option is set.
protected  boolean _outsideValueSet
          Whether the outside option is set.
protected  IntegerStack _stk
          A stack of integer values used in the evaluation of if statements.
protected  AbstractJiffleRuntime.ImageScopeVar[] _vars
          Image-scope variables.
static java.lang.String VAR_STRING
          Advertizes the image-scope variable getter syntax to source generators.
 
Constructor Summary
AbstractJiffleRuntime()
          Creates a new instance of this class and initializes its JiffleFunctions and IntegerStack objects.
 
Method Summary
protected abstract  java.lang.Double getDefaultValue(int index)
          Gets the default value for an image-scope variable.
 java.lang.String[] getDestinationVarNames()
          Gets the variable names associated with destination images.
 double getHeight()
          Gets the height of the processing area.
 double getMaxX()
          Gets the max X ordinate of the processing area.
 double getMaxY()
          Gets the max Y ordinate of the processing area.
 double getMinX()
          Gets the min X ordinate of the processing area.
 double getMinY()
          Gets the min Y ordinate of the processing area.
 long getNumPixels()
          Gets the total number of pixels in the processing area.
 java.lang.String[] getSourceVarNames()
          Gets the variable names associated with source images.
protected  CoordinateTransform getTransform(java.lang.String imageVarName)
          Gets the coordinate transform to use with the image represented by imageVarName.
 java.lang.Double getVar(java.lang.String varName)
          Returns the value of a variable that was declared in the script's init block.
protected  int getVarIndex(java.lang.String varName)
          Gets the index for an image-scope variable by name.
 java.lang.String[] getVarNames()
          Returns the names of image scope variables that can be used with the JiffleRuntime.getVar(String) and JiffleRuntime.setVar(String, Double) methods.
 double getWidth()
          Gets the width of the processing area.
 double getXRes()
          Gets the pixel width (resolution in X direction) in world units.
 double getYRes()
          Gets the pixel height (resolution in Y direction) in world units.
protected  void initImageScopeVars()
          Initializes image-scope variables.
protected abstract  void initOptionVars()
          Initializes runtime class fields related to Jiffle script options.
 boolean isWorldSet()
          Checks whether the world bounds and pixel dimensions have been set.
protected  void registerVar(java.lang.String name, boolean hasDefault)
          Registers a variable as having image scope.
 void setDefaultTransform(CoordinateTransform tr)
          Sets a coordinate transform to be used by any source and destination images submitted to the runtime object without their own transforms.
 void setImageParams(java.util.Map imageParams)
          Supplies the runtime object with the names and roles if image variables used in the script.
protected  void setTransform(java.lang.String imageVarName, CoordinateTransform tr)
          Sets a coordinate transform to use with the image represented by imageVarName.
 void setVar(java.lang.String varName, java.lang.Double value)
          Sets the value of a variable that was declared in the script's init block, overriding the default value in the script if present.
protected  void setVarValue(int index, java.lang.Double value)
          Sets the value of an image-scope variable.
 void setWorldByNumPixels(java.awt.geom.Rectangle2D bounds, int numX, int numY)
          Sets the world (processing area) bounds and the number of pixels in the X and Y directions.
 void setWorldByResolution(java.awt.geom.Rectangle2D bounds, double xres, double yres)
          Sets the world (processing area) bounds and resolution (pixel dimensions).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_vars

protected AbstractJiffleRuntime.ImageScopeVar[] _vars
Image-scope variables.


_imageScopeVarsInitialized

protected boolean _imageScopeVarsInitialized
Whether the image-scope variables have been initialized.


_numVars

protected int _numVars
The number of image-scope variables defined.


VAR_STRING

public static final java.lang.String VAR_STRING
Advertizes the image-scope variable getter syntax to source generators.

See Also:
Constant Field Values

_outsideValueSet

protected boolean _outsideValueSet
Whether the outside option is set.


_outsideValue

protected double _outsideValue
The value to return for out-of-bounds image data requests if the outside option is set.


_stk

protected IntegerStack _stk
A stack of integer values used in the evaluation of if statements.


_FN

protected final JiffleFunctions _FN
Provides runtime function support.

Constructor Detail

AbstractJiffleRuntime

public AbstractJiffleRuntime()
Creates a new instance of this class and initializes its JiffleFunctions and IntegerStack objects.

Method Detail

setImageParams

public void setImageParams(java.util.Map imageParams)
Supplies the runtime object with the names and roles if image variables used in the script. Although this is a public method it is not intended for general use. It is called by the jaitools.jiffle.Jiffle instance that is creating the runtime object so that clients can use the JiffleRuntime.getSourceVarNames() and JiffleRuntime.getDestinationVarNames() methods.

Specified by:
setImageParams in interface JiffleRuntime
Parameters:
imageParams - a Map of variable names (key) and roles (value)

getSourceVarNames

public java.lang.String[] getSourceVarNames()
Gets the variable names associated with source images.

Specified by:
getSourceVarNames in interface JiffleRuntime
Returns:
an array of names; may be empty but not null

getDestinationVarNames

public java.lang.String[] getDestinationVarNames()
Gets the variable names associated with destination images.

Specified by:
getDestinationVarNames in interface JiffleRuntime
Returns:
an array of names; may be empty but not null

setWorldByResolution

public void setWorldByResolution(java.awt.geom.Rectangle2D bounds,
                                 double xres,
                                 double yres)
Sets the world (processing area) bounds and resolution (pixel dimensions).

Specified by:
setWorldByResolution in interface JiffleRuntime
Parameters:
bounds - outer bounds of the processing area
xres - pixel width in world units
yres - pixel height in world units

setWorldByNumPixels

public void setWorldByNumPixels(java.awt.geom.Rectangle2D bounds,
                                int numX,
                                int numY)
Sets the world (processing area) bounds and the number of pixels in the X and Y directions.

Specified by:
setWorldByNumPixels in interface JiffleRuntime
Parameters:
bounds - outer bounds of the processing area
numX - number of pixels in the X direction
numY - number of pixels in the Y direction

isWorldSet

public boolean isWorldSet()
Checks whether the world bounds and pixel dimensions have been set.

Specified by:
isWorldSet in interface JiffleRuntime
Returns:
true if set; false otherwise

getVar

public java.lang.Double getVar(java.lang.String varName)
Returns the value of a variable that was declared in the script's init block.

Specified by:
getVar in interface JiffleRuntime
Parameters:
varName - variable name
Returns:
the values or null if the variable name is not found

setVar

public void setVar(java.lang.String varName,
                   java.lang.Double value)
            throws JiffleRuntimeException
Sets the value of a variable that was declared in the script's init block, overriding the default value in the script if present. Setting value to null results in the default script value being used.

Specified by:
setVar in interface JiffleRuntime
Parameters:
varName - variable name
value - the new value
Throws:
JiffleRuntimeException - if the variable name is not found

getVarNames

public java.lang.String[] getVarNames()
Returns the names of image scope variables that can be used with the JiffleRuntime.getVar(String) and JiffleRuntime.setVar(String, Double) methods.

Specified by:
getVarNames in interface JiffleRuntime
Returns:
array of variable names; may be empty but not null

getMinX

public double getMinX()
Gets the min X ordinate of the processing area.

Specified by:
getMinX in interface JiffleRuntime
Returns:
min X ordinate in world units

getMaxX

public double getMaxX()
Gets the max X ordinate of the processing area.

Specified by:
getMaxX in interface JiffleRuntime
Returns:
max X ordinate in world units

getMinY

public double getMinY()
Gets the min Y ordinate of the processing area.

Specified by:
getMinY in interface JiffleRuntime
Returns:
min Y ordinate in world units

getMaxY

public double getMaxY()
Gets the max Y ordinate of the processing area.

Specified by:
getMaxY in interface JiffleRuntime
Returns:
max Y ordinate in world units

getWidth

public double getWidth()
Gets the width of the processing area.

Specified by:
getWidth in interface JiffleRuntime
Returns:
the width in world units

getHeight

public double getHeight()
Gets the height of the processing area.

Specified by:
getHeight in interface JiffleRuntime
Returns:
the height in world units

getXRes

public double getXRes()
Gets the pixel width (resolution in X direction) in world units.

Specified by:
getXRes in interface JiffleRuntime
Returns:
pixel width

getYRes

public double getYRes()
Gets the pixel height (resolution in Y direction) in world units.

Specified by:
getYRes in interface JiffleRuntime
Returns:
pixel height

getNumPixels

public long getNumPixels()
Description copied from interface: JiffleRuntime
Gets the total number of pixels in the processing area.

Specified by:
getNumPixels in interface JiffleRuntime
Returns:
number of pixels

setTransform

protected void setTransform(java.lang.String imageVarName,
                            CoordinateTransform tr)
                     throws org.jaitools.jiffle.runtime.WorldNotSetException
Sets a coordinate transform to use with the image represented by imageVarName.

Parameters:
imageVarName - variable name
tr - the transform or null for the default transform
Throws:
WorldNotSetException - if world bounds and resolution are not yet set

setDefaultTransform

public void setDefaultTransform(CoordinateTransform tr)
                         throws JiffleException
Sets a coordinate transform to be used by any source and destination images submitted to the runtime object without their own transforms. This includes any images submitted prior to calling this method. If tr is null the system default transform (IdentityCoordinateTransform) will be used.

Specified by:
setDefaultTransform in interface JiffleRuntime
Parameters:
tr - the coordinate transform to use as the default; or null for the system default
Throws:
JiffleException - if the world bounds and resolution have not been set previously

getTransform

protected CoordinateTransform getTransform(java.lang.String imageVarName)
Gets the coordinate transform to use with the image represented by imageVarName.

Parameters:
imageVarName - variable name
Returns:
the coordinate transform

setVarValue

protected void setVarValue(int index,
                           java.lang.Double value)
                    throws JiffleRuntimeException
Sets the value of an image-scope variable. If value is null the variable is set to its default value if one is defined, otherwise an exception is thrown.

Parameters:
index - variable index
value - the new value or null for default value
Throws:
JiffleRuntimeException - if value is null but no default value is defined for the variable

getVarIndex

protected int getVarIndex(java.lang.String varName)
Gets the index for an image-scope variable by name.

Parameters:
varName - variable name
Returns:
the index or -1 if the name is not found

initImageScopeVars

protected void initImageScopeVars()
Initializes image-scope variables. These are fields in the runtime class. They are initialized in a separate method rather than the constructor because they may depend on expressions involving values which are not known until the processing area is set (e.g. Jiffle's width() function).

Throws:
JiffleRuntimeException - if any variables do not have either a default or provided value

getDefaultValue

protected abstract java.lang.Double getDefaultValue(int index)
Gets the default value for an image-scope variable. This method is overridden as part of the generated run-time class code.

Parameters:
index - the index of the variable
Returns:
the default value or null if one is not defined

initOptionVars

protected abstract void initOptionVars()
Initializes runtime class fields related to Jiffle script options.


registerVar

protected void registerVar(java.lang.String name,
                           boolean hasDefault)
Registers a variable as having image scope.

Parameters:
name - variable name
hasDefault - whether the variable has a default value


Copyright © 2011. All Rights Reserved.