public class Jiffle extends Object
Example of use:
// A script to write sequential values to image pixels
String script = "images { dest=write; } dest = x() + y() * width();" ;
Jiffle jiffle = new Jiffle();
jiffle.setScript(script);
jifle.compile();
// Now we get the runtime object from the compiled Jiffle object
JiffleDirectRuntime runtime = jiffle.getRuntimeInstance();
// Create an image to hold the results of the script
final int width = 10;
WritableRenderedImage destImg = ImageUtils.createConstantImage(width, width, 0.0d);
// Associate this image with the variable name used in the script
runtime.setDestinationImage("dest", destImg);
// Evaluate the script for all destination image pixels
runtime.evaluateAll();
For further examples of how to create and run Jiffle scripts see the
it.geosolutions.jaiext.demo.jiffle
package in the JAI-tools demo module.
JiffleBuilder
,
JiffleExecutor
Modifier and Type | Class and Description |
---|---|
static class |
Jiffle.ImageRole
Used to specify the roles of images referenced in
a Jiffle script.
|
static class |
Jiffle.RuntimeModel
Constants for runtime model.
|
Constructor and Description |
---|
Jiffle()
Creates a new instance.
|
Jiffle(File scriptFile,
Map<String,Jiffle.ImageRole> params)
Creates a new instance by compiling the script read from
scriptFile . |
Jiffle(String script,
Map<String,Jiffle.ImageRole> params)
Creates a new instance by compiling the provided script.
|
Modifier and Type | Method and Description |
---|---|
void |
compile()
Compiles the script into Java source for the runtime class.
|
Map<String,Jiffle.ImageRole> |
getImageParams()
Gets the current image parameters.
|
String |
getName()
Gets the name assigned to this object.
|
static Set<GetSourceValue> |
getReadPositions(String script,
List<String> sourceImageNames)
A utility method returning the source positions used in a given script
|
JiffleDirectRuntime |
getRuntimeInstance()
Creates an instance of the default runtime class.
|
<T extends JiffleRuntime> |
getRuntimeInstance(Class<T> baseClass)
Gets the runtime object for this script.
|
JiffleRuntime |
getRuntimeInstance(Jiffle.RuntimeModel model)
Creates a runtime object based using the class specified by
model . |
String |
getRuntimeSource(boolean scriptInDocs)
Gets a copy of the Java source for the runtime class.
|
String |
getRuntimeSource(Jiffle.RuntimeModel model,
boolean scriptInDocs)
Gets a copy of the Java source for the runtime class.
|
String |
getScript()
Gets the Jiffle script.
|
boolean |
isCompiled()
Tests whether the script has been compiled successfully.
|
void |
setImageParams(Map<String,Jiffle.ImageRole> params)
Sets the image parameters.
|
void |
setName(String name)
Replaces the default name set for this object with a user-supplied name.
|
void |
setScript(File scriptFile)
Sets the script.
|
void |
setScript(String script)
Sets the script.
|
public static final Logger LOGGER
public Jiffle()
public Jiffle(String script, Map<String,Jiffle.ImageRole> params) throws JiffleException
Jiffle jiffle = new Jiffle();
jiffle.setScript(script);
jiffle.setImageParams(params);
jiffle.compile();
script
- Jiffle source code to compileparams
- defines the names and roles of image variables
referred to in the script.JiffleException
- on compilation errorspublic Jiffle(File scriptFile, Map<String,Jiffle.ImageRole> params) throws JiffleException
scriptFile
.
Using this constructor is equivalent to:
Jiffle jiffle = new Jiffle();
jiffle.setScript(scriptFile);
jiffle.setImageParams(params);
jiffle.compile();
scriptFile
- file containing the Jiffle scriptparams
- defines the names and roles of image variables
referred to in the script.JiffleException
- on compilation errorspublic final void setScript(String script) throws JiffleException
script
- a Jiffle scriptJiffleException
- if the script is empty or null
public final void setScript(File scriptFile) throws JiffleException
scriptFile
- a file containing a Jiffle scriptJiffleException
- if the script is empty or null
public String getScript()
String
if none
has been setpublic final void setImageParams(Map<String,Jiffle.ImageRole> params)
This may be called before or after setting the script. No check is made between script and parameters until the script is compiled.
params
- the image parameterspublic Map<String,Jiffle.ImageRole> getImageParams()
Map
if none
are setpublic void setName(String name)
name
- the name to assignpublic String getName()
setName(String)
public final void compile() throws JiffleException
JiffleException
- on compilation errorspublic boolean isCompiled()
true
if the script has been compiled;
false
otherwisepublic JiffleDirectRuntime getRuntimeInstance() throws JiffleException
The default runtime class implements JiffleDirectRuntime
and
extends an abstract base class provided by the Jiffle compiler. Objects
of this class evaluate the Jiffle script and write results directly to
the destination image(s). Client code can call either of the methods:
evaluate(int x, int y)
evaluateAll(JiffleProgressListener listener
Jiffle
object must be compiled before calling this method.JiffleException
- if the script has not been compiled or if errors
occur in creating the runtime instancepublic JiffleRuntime getRuntimeInstance(Jiffle.RuntimeModel model) throws JiffleException
model
.
The Jiffle
object must be compiled before calling this method.
model
- the Jiffle.RuntimeModel
JiffleException
- if the script has not been compiled or if errors
occur in creating the runtime instancepublic <T extends JiffleRuntime> T getRuntimeInstance(Class<T> baseClass) throws JiffleException
The runtime object is an instance of JiffleRuntime
. By default
it extends an abstract base class supplied JAI-tools:
AbstractDirectRuntime
when using the direct runtiem model or
AbstractIndirectRuntime
when using the indirect model. This method allows you to
specify a custom base class. The custom class must implement either
JiffleDirectRuntime
or JiffleIndirectRuntime
.
T
- the runtime base class typebaseClass
- the runtime base classJiffleException
- if the script has not been compiled or if errors
occur in creating the runtime instancepublic String getRuntimeSource(boolean scriptInDocs) throws JiffleException
scriptInDocs
- whether to include the original Jiffle script
in the class javadocsJiffleException
- if the script has not been compiled or if errors
occur in creating the runtime source codepublic String getRuntimeSource(Jiffle.RuntimeModel model, boolean scriptInDocs) throws JiffleException
model
- the Jiffle.RuntimeModel
scriptInDocs
- whether to include the original Jiffle script
in the class javadocsJiffleException
- if the script has not been compiled or if errors
occur in creating the runtime source codepublic static Set<GetSourceValue> getReadPositions(String script, List<String> sourceImageNames) throws JiffleException
script
- JiffleException
Copyright © 2006–2018 GeoSolutions. All rights reserved.