Jiffle.getRuntimeInstance
Code IndexAdd Codota to your IDE (free)

Best Java code snippets using it.geosolutions.jaiext.jiffle.Jiffle.getRuntimeInstance (Showing top 20 results out of 315)

origin: it.geosolutions.jaiext.jiffle/jt-jiffle-language

/**
 * Creates an instance of the default runtime class. 
 * <p>
 * The default runtime class implements {@link 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:
 * <ul>
 * <li>{@code evaluate(int x, int y)}
 * <li>{@code evaluateAll(JiffleProgressListener listener}
 * </ul>
 * The {@code Jiffle} object must be compiled before calling this method.
 * 
 * @return the runtime object
 * @throws JiffleException if the script has not been compiled or if errors
 *         occur in creating the runtime instance
 */
public JiffleDirectRuntime getRuntimeInstance() throws
    it.geosolutions.jaiext.jiffle.JiffleException {
  return (JiffleDirectRuntime) getRuntimeInstance(RuntimeModel.DIRECT);
}

origin: geosolutions-it/jai-ext

/**
 * Creates an instance of the default runtime class. 
 * <p>
 * The default runtime class implements {@link 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:
 * <ul>
 * <li>{@code evaluate(int x, int y)}
 * <li>{@code evaluateAll(JiffleProgressListener listener}
 * </ul>
 * The {@code Jiffle} object must be compiled before calling this method.
 * 
 * @return the runtime object
 * @throws JiffleException if the script has not been compiled or if errors
 *         occur in creating the runtime instance
 */
public JiffleDirectRuntime getRuntimeInstance() throws
    it.geosolutions.jaiext.jiffle.JiffleException {
  return (JiffleDirectRuntime) getRuntimeInstance(RuntimeModel.DIRECT);
}

origin: geosolutions-it/jai-ext

private JiffleDirectRuntime getRuntimeWithImageParams() throws Exception {
  String script = "dest1 = src1; dest2 = src2; dest3 = src3;" ;
  Map<String, Jiffle.ImageRole> imageParams = new HashMap<>();
  imageParams.put("dest1", Jiffle.ImageRole.DEST);
  imageParams.put("dest2", Jiffle.ImageRole.DEST);
  imageParams.put("dest3", Jiffle.ImageRole.DEST);
  imageParams.put("src1", Jiffle.ImageRole.SOURCE);
  imageParams.put("src2", Jiffle.ImageRole.SOURCE);
  imageParams.put("src3", Jiffle.ImageRole.SOURCE);
  Jiffle jiffle = new Jiffle(script, imageParams);
  return jiffle.getRuntimeInstance();
}

origin: geosolutions-it/jai-ext

/**
 * Compiles a script read from a file and submits it for execution.
 * 
 * @param scriptFile file containing the Jiffle script
 * @throws Exception on problems compiling the script
 */
public void compileAndRun(File scriptFile) throws Exception {
  Map<String, Jiffle.ImageRole> imageParams = new HashMap<>();
  imageParams.put("result", Jiffle.ImageRole.DEST);
  Jiffle jiffle = new Jiffle(scriptFile, imageParams);
  JiffleDirectRuntime runtime = jiffle.getRuntimeInstance();
  
  WritableRenderedImage destImage = ImageUtilities.createConstantImage(WIDTH, HEIGHT, 0d);
  runtime.setDestinationImage("result", destImage);
  executor.submit(runtime, new NullProgressListener());
}
origin: geosolutions-it/jai-ext

/**
 * Compiles a script read from a file and submits it for execution.
 * 
 * @param scriptFile file containing the Jiffle script
 * @throws Exception on an error in the Jiffle compiler
 */
public void compileAndRun(File scriptFile) throws Exception {
  Map<String, Jiffle.ImageRole> imageParams = new HashMap<>();
  imageParams.put("result", Jiffle.ImageRole.DEST);
  Jiffle jiffle = new Jiffle(scriptFile, imageParams);
  Map<String, RenderedImage> images = new HashMap<>();
  images.put("result",
      ImageUtilities.createConstantImage(WIDTH, HEIGHT, Double.valueOf(0d)));
  if (jiffle.isCompiled()) {
    JiffleDirectRuntime runtime = jiffle.getRuntimeInstance();
    final TiledImage destImg = ImageUtilities.createConstantImage(WIDTH, HEIGHT, 0d);
    runtime.setDestinationImage("result", destImg);
    
    runtime.evaluateAll(null);
    
    ImageFrame frame = new ImageFrame(destImg, "Jiffle image demo");
    frame.setVisible(true);
  }
}
origin: geosolutions-it/jai-ext

protected void testScript(String script, RenderedImage srcImg, Evaluator evaluator) throws Exception {
  imageParams = new HashMap<>();
  imageParams.put("dest", Jiffle.ImageRole.DEST);
  imageParams.put("src", Jiffle.ImageRole.SOURCE);
  // test the direct runtime
  Jiffle jiffle = new Jiffle(script, imageParams);
  directRuntimeInstance = jiffle.getRuntimeInstance();
  testDirectRuntime(srcImg, directRuntimeInstance, evaluator);
  
  // and now the indirect one
  indirectRuntimeInstance =
      (JiffleIndirectRuntime) jiffle.getRuntimeInstance(Jiffle.RuntimeModel.INDIRECT);
  evaluator.reset();
  testIndirectRuntime(srcImg, indirectRuntimeInstance, evaluator);
}
origin: geosolutions-it/jai-ext

  @Test(expected=JiffleException.class)
  public void getRuntimeBeforeCompiling() throws Exception {
    System.out.println("   getRuntimeInstance before compiling");
    
    String script = "dest = 42;";
    jiffle.setScript(script);
    
    imageParams.put("dest", Jiffle.ImageRole.DEST);
    jiffle.setImageParams(imageParams);
    
    JiffleRuntime runtime = jiffle.getRuntimeInstance();
  }    
}
origin: geosolutions-it/jai-ext

@Test(expected=JiffleException.class)
public void invalidBaseClass() throws Exception {
  class Foo extends NullRuntime { }
  
  setupSingleDestScript();
   Object runtime = jiffle.getRuntimeInstance(Foo.class);
}
origin: geosolutions-it/jai-ext

private JiffleDirectRuntime getRuntime(String script) throws Exception {
  Jiffle jiffle = new Jiffle();
  jiffle.setScript(script);
  
  Map<String, Jiffle.ImageRole> params = new HashMap<>();
  params.put("dest", Jiffle.ImageRole.DEST);
  jiffle.setImageParams(params);
  jiffle.compile();
  
  return jiffle.getRuntimeInstance();
}

origin: geosolutions-it/jai-ext

private JiffleDirectRuntime getRuntimeWithImagesBlock() throws Exception {
  String script = 
       "images {"
      + "  src1=read; src2=read; src3=read;"
      + "  dest1=write; dest2=write; dest3=write;"
      + "}"
      + "dest1 = src1; dest2 = src2; dest3 = src3;" ;
  Jiffle jiffle = new Jiffle();
  jiffle.setScript(script);
  jiffle.compile();
  return jiffle.getRuntimeInstance();
}

origin: geosolutions-it/jai-ext

@Test
public void getDirectRuntime() throws Exception {
  setupSingleDestScript();
  Object runtime = jiffle.getRuntimeInstance(Jiffle.RuntimeModel.DIRECT);
  assertTrue(runtime instanceof JiffleDirectRuntime);
}
origin: geosolutions-it/jai-ext

  private JiffleDirectRuntime getRuntime(String script) throws Exception {
    Jiffle jiffle = new Jiffle();
    jiffle.setScript(script);
    jiffle.compile();
    return jiffle.getRuntimeInstance();
  }
}
origin: geosolutions-it/jai-ext

@Test
public void customIndirectBaseClass() throws Exception {
  setupSingleDestScript();
  Object runtime = jiffle.getRuntimeInstance(MockIndirectBaseClass.class);
  assertTrue(runtime instanceof MockIndirectBaseClass);
}

origin: geosolutions-it/jai-ext

@Test
public void customDirectBaseClass() throws Exception {
  setupSingleDestScript();
  Object runtime = jiffle.getRuntimeInstance(MockDirectBaseClass.class);
  assertTrue(runtime instanceof MockDirectBaseClass);
}    
origin: geosolutions-it/jai-ext

@Test
public void getIndirectRuntime() throws Exception {
  setupSingleDestScript();
  Object runtime = jiffle.getRuntimeInstance(Jiffle.RuntimeModel.INDIRECT);
  assertTrue(runtime instanceof JiffleIndirectRuntime);
}
origin: geosolutions-it/jai-ext

private JiffleDirectRuntime getRuntime(String script) throws Exception {
  Jiffle jiffle = new Jiffle();
  jiffle.setScript(script);
  
  Map<String, Jiffle.ImageRole> imageParams = new HashMap<>();
  imageParams.put("dest", Jiffle.ImageRole.DEST);
  
  jiffle.setImageParams(imageParams);
  jiffle.compile();
  JiffleDirectRuntime runtime = jiffle.getRuntimeInstance();
  
  WritableRenderedImage destImg = ImageUtilities.createConstantImage(WIDTH, WIDTH, 0d);
  runtime.setDestinationImage("dest", destImg);
  
  return runtime;
}

origin: geosolutions-it/jai-ext

@Test
public void countValues() throws Exception {
  System.out.println("   counting pixels that meet a condition");
  
  final int testVal = 10;
  
  String script = String.format(
       "images { src=read; } \n"
      + "init { count = 0; } \n"
      + "count += src > %d;",
      testVal);
  
  TestData testData = createTestData(testVal);
  
  Jiffle jiffle = getCompiledJiffle(script);
  JiffleDirectRuntime runtime = jiffle.getRuntimeInstance();
  runtime.setSourceImage("src", testData.image);
  runtime.evaluateAll(null);
  
  Double count = runtime.getVar("count");
  assertNotNull(count);
  assertEquals(testData.expectedCount, count.intValue());
}

origin: geosolutions-it/jai-ext

@Test
public void noDestImage() throws Exception {
  System.out.println("   destination-less script with images block");
  String script = String.format(
       "images { inimage = read; } \n"
      + "init { n = 0; } \n"
      + "n += inimage >= %d;",
      NUM_PIXELS - 5);
  
  Jiffle jiffle = new Jiffle();
  jiffle.setScript(script);
  jiffle.compile();
  
  directRuntimeInstance = jiffle.getRuntimeInstance();
  directRuntimeInstance.setSourceImage("inimage", createSequenceImage());
  directRuntimeInstance.evaluateAll(null);
  
  Double var = directRuntimeInstance.getVar("n");
  assertNotNull(var);
  assertEquals(5, var.intValue());
}

origin: geosolutions-it/jai-ext

private void testScript(String script, int numSrcBands, Evaluator evaluator) throws Exception {
  imageParams = new HashMap<>();
  imageParams.put("dest", Jiffle.ImageRole.DEST);
  imageParams.put("src", Jiffle.ImageRole.SOURCE);
  Jiffle jiffle = new Jiffle(script, imageParams);
  JiffleDirectRuntime runtime = jiffle.getRuntimeInstance();
  TiledImage srcImg = createSequenceImage(numSrcBands);
  runtime.setSourceImage("src", srcImg);
  TiledImage destImg = ImageUtilities.createConstantImage(WIDTH, WIDTH, 0d);
  runtime.setDestinationImage("dest", destImg);
  runtime.evaluateAll(null);
  double[] values = new double[numSrcBands];
  for (int y = 0; y < WIDTH; y++) {
    for (int x = 0; x < WIDTH; x++) {
      for (int b = 0; b < numSrcBands; b++) {
        values[b] = srcImg.getSampleDouble(x, y, b);
      }
      assertEquals(evaluator.eval(values), destImg.getSampleDouble(x, y, 0), TOL);
    }
  }
}
origin: geosolutions-it/jai-ext

private void assertScriptResult(String script, 
    Evaluator e, String srcVarName, String destVarName) throws Exception {
  
  RenderedImage srcImg = null;
  WritableRenderedImage destImg = null;
  
  Jiffle jiffle = new Jiffle();
  jiffle.setScript(script);
  jiffle.compile();
  
  directRuntimeInstance = (JiffleDirectRuntime) jiffle.getRuntimeInstance();
  
  if (srcVarName != null && srcVarName.length() > 0) {
    srcImg = createSequenceImage();
    directRuntimeInstance.setSourceImage(srcVarName, srcImg);
  }
  
  if (destVarName != null && destVarName.length() > 0) {
    destImg = ImageUtilities.createConstantImage(IMG_WIDTH, IMG_WIDTH, 0d);
    directRuntimeInstance.setDestinationImage(destVarName, destImg);
  }
  
  directRuntimeInstance.evaluateAll(null);
  assertImage(srcImg, destImg, e);
}
it.geosolutions.jaiext.jiffleJifflegetRuntimeInstance

Javadoc

Creates an instance of the default runtime class.

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
The Jiffle object must be compiled before calling this method.

Popular methods of Jiffle

  • <init>
    Creates a new instance by compiling the provided script. Using this constructor is equivalent to: J
  • compile
    Compiles the script into Java source for the runtime class.
  • setImageParams
    Sets the image parameters. These define which variables in the script refer to images and their type
  • setScript
    Sets the script. Calling this method will clear any previous script and runtime objects.
  • isCompiled
    Tests whether the script has been compiled successfully.
  • getReadPositions
    A utility method returning the source positions used in a given script
  • getRuntimeSource
    Gets a copy of the Java source for the runtime class. The script must have been compiled before call
  • clearCompiledObjects
    Clears all compiler and runtime objects.
  • createRuntimeInstance
  • createRuntimeSource
  • getImageParams
    Gets the current image parameters. The parameters are returned as an unmodifiable map.
  • getName
    Gets the name assigned to this object. This will either be the default name or one assigned by the c
  • getImageParams,
  • getName,
  • getRuntimeBaseClass,
  • getScript,
  • getScriptImageParams,
  • init,
  • parseScript,
  • reportMessages,
  • setName

Popular in Java

  • Making http requests using okhttp
  • getResourceAsStream (ClassLoader)
  • findViewById (Activity)
  • onRequestPermissionsResult (Fragment)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the

For IntelliJ IDEA,
Android Studio or Eclipse

  • Search for JavaScript code betaCodota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutBlogContact Us
  • Plugin user guideTerms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)