Skip to content

Commit

Permalink
add sloppy bounding box derivation, test delta 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
axtimwalde committed Oct 26, 2017
1 parent 79f489f commit ec46251
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 14 deletions.
78 changes: 68 additions & 10 deletions render-app/src/main/java/org/janelia/alignment/spec/TileSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
package org.janelia.alignment.spec;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.io.IOException;
Expand All @@ -31,17 +29,19 @@
import java.util.Set;
import java.util.TreeMap;

import org.janelia.alignment.ImageAndMask;
import org.janelia.alignment.RenderParameters;
import org.janelia.alignment.json.JsonUtils;
import org.janelia.alignment.spec.stack.MipmapPathBuilder;

import com.fasterxml.jackson.annotation.JsonIgnore;

import mpicbg.models.CoordinateTransform;
import mpicbg.models.CoordinateTransformList;
import mpicbg.models.CoordinateTransformMesh;
import mpicbg.models.NoninvertibleModelException;
import mpicbg.trakem2.transform.TransformMesh;

import org.janelia.alignment.ImageAndMask;
import org.janelia.alignment.RenderParameters;
import org.janelia.alignment.json.JsonUtils;
import org.janelia.alignment.spec.stack.MipmapPathBuilder;

/**
* Specifies a set of mipmap level images and masks along with
* a list of transformations to perform against them.
Expand Down Expand Up @@ -195,6 +195,7 @@ public CoordinateTransformMesh getCoordinateTransformMesh(final double meshCellS
height);
}


/**
* Derives this tile's bounding box attributes.
*
Expand All @@ -204,15 +205,72 @@ public CoordinateTransformMesh getCoordinateTransformMesh(final double meshCellS
* @throws IllegalStateException
* if width or height have not been defined for this tile.
*/
public void deriveBoundingBox(final double meshCellSize, final boolean force)
public void deriveBoundingBox(final double meshCellSize, final boolean force, final boolean sloppy)
throws IllegalStateException {

if (force || (!isBoundingBoxDefined(meshCellSize))) {
final TransformMesh mesh = getTransformMesh(meshCellSize);
setBoundingBox(mesh.getBoundingBox(), meshCellSize);
if (sloppy) {
if (! hasWidthAndHeightDefined()) {
throw new IllegalStateException("width and height must be set to create a bounding box");
}

final CoordinateTransformList<CoordinateTransform> ctList = getTransformList();
final ArrayList<double[]> borderSamples = new ArrayList<>();

/* top and bottom */
for (double x = 0; x <= width; x += meshCellSize) {
borderSamples.add(new double[]{x, 0});
borderSamples.add(new double[]{x, height});
}

/* left and right */
for (double y = 0; y < height; y += meshCellSize) {
borderSamples.add(new double[]{0, y});
borderSamples.add(new double[]{width, y});
}

double xMin = Double.MAX_VALUE;
double yMin = Double.MAX_VALUE;

double xMax = -Double.MAX_VALUE;
double yMax = -Double.MAX_VALUE;

for (final double[] point : borderSamples) {
ctList.applyInPlace(point);

if ( point[ 0 ] < xMin ) xMin = point[ 0 ];
if ( point[ 0 ] > xMax ) xMax = point[ 0 ];
if ( point[ 1 ] < yMin ) yMin = point[ 1 ];
if ( point[ 1 ] > yMax ) yMax = point[ 1 ];
}

setBoundingBox(new Rectangle((int)xMin, (int)yMin, (int)Math.ceil(xMax - xMin), (int)Math.ceil(yMax - yMin)), meshCellSize);
// setBoundingBox(new Rectangle((int)xMin, (int)yMin, (int)(xMax - xMin), (int)(yMax - yMin)), meshCellSize);

} else {
final TransformMesh mesh = getTransformMesh(meshCellSize);
setBoundingBox(mesh.getBoundingBox(), meshCellSize);
}
}
}


/**
* Derives this tile's bounding box attributes.
*
* @param force if true, attributes will always be derived;
* otherwise attributes will only be derived if they do not already exist.
*
* @throws IllegalStateException
* if width or height have not been defined for this tile.
*/
public void deriveBoundingBox(final double meshCellSize, final boolean force)
throws IllegalStateException {

deriveBoundingBox(meshCellSize, force, true);
}


/**
* @param tileSpecs collection of tile specs.
* @param meshCellSize specifies the resolution to estimate the individual bounding boxes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ public void testDeriveBoundingBox() throws Exception {
final TileSpec tileSpec = TileSpec.fromJson(json);
tileSpec.deriveBoundingBox(64, true);

Assert.assertEquals("incorrect minX", 1108.0, tileSpec.getMinX(), 0.0);
Assert.assertEquals("incorrect minY", 1957.0, tileSpec.getMinY(), 0.0);
Assert.assertEquals("incorrect maxX", 3773.0, tileSpec.getMaxX(), 0.0);
Assert.assertEquals("incorrect maxY", 4264.0, tileSpec.getMaxY(), 0.0);
Assert.assertEquals("incorrect minX", 1108.0, tileSpec.getMinX(), 1.0);
Assert.assertEquals("incorrect minY", 1957.0, tileSpec.getMinY(), 1.0);
Assert.assertEquals("incorrect maxX", 3773.0, tileSpec.getMaxX(), 1.0);
Assert.assertEquals("incorrect maxY", 4264.0, tileSpec.getMaxY(), 1.0);
}

private static final String EXPECTED_TILE_ID = "test-tile-id";
Expand Down

0 comments on commit ec46251

Please sign in to comment.