/** * Gets the transform which converts from {@code worldBounds} to {@code imageBounds}. * This method is a shortcut for {@code getTransform(worldBounds, imageBounds, false, false)}. * * @param worldBounds the coordinate bounds in world (user-defined) units * @param imageBounds the image bounds * * @return a new transform instance * * @throws IllegalArgumentException if either argument is {@code null} or empty */ public static CoordinateTransform getTransform(Rectangle2D worldBounds, Rectangle imageBounds) { return getTransform(worldBounds, imageBounds, false, false); }
public void runScriptWithBuilder(String script, String destVar, WritableRenderedImage destImage) throws JiffleException { // Image bounds are taken from the destination image Rectangle imageBounds = new Rectangle( destImage.getMinX(), destImage.getMinY(), destImage.getWidth(), destImage.getHeight()); // The world bounds are the unit rectangle Rectangle2D worldBounds = new Rectangle2D.Double(0, 0, 1, 1); CoordinateTransform transform = CoordinateTransforms.unitBounds(imageBounds); JiffleBuilder builder = new JiffleBuilder(); // Set the processing area (world units) builder.worldAndNumPixels(worldBounds, destImage.getWidth(), destImage.getHeight()); // Set the script and the destination image with its transform builder.script(script).dest(destVar, destImage, transform); // This executes the script and writes the results into destImage builder.run(); } // docs end builder method
/** * Setting a default transform without having previously set the world * bounds should throw a JiffleException. */ @Test(expected=JiffleException.class) public void forgetTheWorldBeforeDefaultTransform() throws Exception { System.out.println(" forget to set the world before setting default transform"); JiffleDirectRuntime runtime = getRuntime("images {dest=write;} dest = 42;"); CoordinateTransform tr = CoordinateTransforms.translation(10, 10); runtime.setDefaultTransform(tr); }
@Test public void scale() throws Exception { System.out.println(" scaling transform"); CoordinateTransform tr = CoordinateTransforms.scale(0.1, 0.2); Point pt = tr.worldToImage(100, 100, null); assertPoint(10, 20, pt); }
@Test public void identity_fromHelper() throws Exception { System.out.println(" identity transform from helper"); CoordinateTransform tr = CoordinateTransforms.identity(); Point pt = tr.worldToImage(10.4, 10.6, null); assertPoint(10, 11, pt); }
@Test public void unitBounds() throws Exception { System.out.println(" unit bounds transform"); Rectangle r = new Rectangle(-100, 100, 1000, 2000); CoordinateTransform tr = CoordinateTransforms.unitBounds(r); assertPoint(r.x, r.y, tr.worldToImage(0, 0, null)); assertPoint(r.x + r.width, r.y + r.height, tr.worldToImage(1, 1, null)); }
@Test public void translation() throws Exception { System.out.println(" translation transform"); CoordinateTransform tr = CoordinateTransforms.translation(10, -10); Point pt = tr.worldToImage(100, 100, null); assertPoint(110, 90, pt); }
/** * Gets the transform which converts from {@code worldBounds} to {@code imageBounds}. * This method is a shortcut for {@code getTransform(worldBounds, imageBounds, false, false)}. * * @param worldBounds the coordinate bounds in world (user-defined) units * @param imageBounds the image bounds * * @return a new transform instance * * @throws IllegalArgumentException if either argument is {@code null} or empty */ public static CoordinateTransform getTransform(Rectangle2D worldBounds, Rectangle imageBounds) { return getTransform(worldBounds, imageBounds, false, false); }
CoordinateTransform transform = CoordinateTransforms.unitBounds(imageBounds);
/** * Setting an image with a transform without having previously set the world * bounds should throw a JiffleException. */ @Test(expected=JiffleException.class) public void forgetTheWorldBeforeImageWithTransform() throws Exception { System.out.println(" forget to set the world before setting image with transform"); JiffleDirectRuntime runtime = getRuntime("images {dest=write;} dest = 42;"); WritableRenderedImage destImage = ImageUtilities.createConstantImage(IMG_WIDTH, IMG_WIDTH, 0d); CoordinateTransform tr = CoordinateTransforms.translation(10, 10); runtime.setDestinationImage("dest", destImage, tr); }
/** * Creates a transform for working in the unit rectangle, ie. proportional * image coordinates where both X and Y ordinates vary from 0 to 1. * * @param imageBounds the image bounds * * @return a new transform instance * * @throws IllegalArgumentException if {@code imageBounds} is {@code null} or empty */ public static CoordinateTransform unitBounds(Rectangle imageBounds) { if (imageBounds == null || imageBounds.isEmpty()) { throw new IllegalArgumentException("imageBounds must not be null or empty"); } return getTransform(new Rectangle(0, 0, 1, 1), imageBounds); }
CoordinateTransform tr = CoordinateTransforms.unitBounds(imageBounds); runtime.setDefaultTransform(tr);
/** * Creates a transform for working in the unit rectangle, ie. proportional * image coordinates where both X and Y ordinates vary from 0 to 1. * * @param imageBounds the image bounds * * @return a new transform instance * * @throws IllegalArgumentException if {@code imageBounds} is {@code null} or empty */ public static CoordinateTransform unitBounds(Rectangle imageBounds) { if (imageBounds == null || imageBounds.isEmpty()) { throw new IllegalArgumentException("imageBounds must not be null or empty"); } return getTransform(new Rectangle(0, 0, 1, 1), imageBounds); }
public void runtimeExample() throws Exception { // docs start // World bounds Rectangle2D worldBounds = new Rectangle2D.Double( 750000, 6500000, 100000, 50000); // Common image bounds Rectangle imageBounds = new Rectangle(0, 0, 4000, 2000); // Set the bounds (world units) and resolution of the // processing area runtimeObj.setWorldByNumPixels(worldBounds, 4000, 2000); // Create a new transform that converts from world units to // pixel positions using the CoordinateTransforms helper class CoordinateTransform tr = CoordinateTransforms.getTransform( worldBounds, imageBounds); // Set this coordinate transform object to be used with all images runtimeObj.setDefaultTransform(tr); // docs end } }
@Test public void getTransformReverseYDir() throws Exception { System.out.println(" getTransform with reversed Y axis"); Rectangle world = new Rectangle(5000, 4000, 10000, 10000); Rectangle image = new Rectangle(10, -10, 100, 100); CoordinateTransform tr = CoordinateTransforms.getTransform(world, image, false, true); assertPoint(image.x, image.y, tr.worldToImage(world.x, world.y + world.height, null)); assertPoint(image.x + image.width, image.y + image.height, tr.worldToImage(world.x + world.width, world.y, null)); }
@Test public void getTransformReverseXDir() throws Exception { System.out.println(" getTransform with reversed X axis"); Rectangle world = new Rectangle(5000, 4000, 10000, 10000); Rectangle image = new Rectangle(10, -10, 100, 100); CoordinateTransform tr = CoordinateTransforms.getTransform(world, image, true, false); assertPoint(image.x, image.y, tr.worldToImage(world.x + world.width, world.y, null)); assertPoint(image.x + image.width, image.y + image.height, tr.worldToImage(world.x, world.y + world.height, null)); }
@Test public void getTransformDefault() throws Exception { System.out.println(" getTransform method"); Rectangle world = new Rectangle(0, 0, 10000, 10000); Rectangle image = new Rectangle(10, -10, 100, 100); CoordinateTransform tr = CoordinateTransforms.getTransform(world, image); assertPoint(image.x, image.y, tr.worldToImage(world.x, world.y, null)); assertPoint(image.x + image.width, image.y + image.height, tr.worldToImage(world.x + world.width, world.y + world.height, null)); }
CoordinateTransform tr = CoordinateTransforms.getTransform(worldBounds, imageBounds);
runtime.setWorldByResolution(worldBounds, RES, RES); CoordinateTransform tr = CoordinateTransforms.getTransform(worldBounds, imageBounds); runtime.setDestinationImage("dest", destImg, tr); runtime.evaluateAll(null);
CoordinateTransform srcTr = CoordinateTransforms.getTransform(worldBounds, srcBounds); runtime.setSourceImage("src", srcImg, srcTr); runtime.setDestinationImage("dest", destImg);