Skip to content

Commit

Permalink
fix grid block creation bug and remove unused methods
Browse files Browse the repository at this point in the history
  • Loading branch information
trautmane committed Sep 9, 2024
1 parent f6cb826 commit d055aa9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 69 deletions.
70 changes: 1 addition & 69 deletions render-app/src/main/java/org/janelia/alignment/util/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.janelia.saalfeldlab.n5.DataBlock;

import net.imglib2.Interval;
import net.imglib2.util.Intervals;

/**
*
Expand Down Expand Up @@ -77,7 +75,7 @@ public static List<Block> create(
final long[] longCroppedGridBlockSize = new long[n];
for (int d = 0; d < n;) {
cropBlockDimensions(dimensions, offset, outBlockSize, gridBlockSize, longCroppedGridBlockSize, gridPosition);
gridBlocks.add(new Block(offset, longCroppedGridBlockSize, gridPosition));
gridBlocks.add(new Block(longCroppedGridBlockSize, offset, gridPosition));

for (d = 0; d < n; ++d) {
offset[d] += gridBlockSize[d];
Expand All @@ -102,68 +100,6 @@ public static List<Block> create(
return create(dimensions, blockSize, blockSize);
}


/**
* Create a {@link List} of grid block offsets in world coordinates
* covering an {@link Interval} at a given spacing.
*/
public static List<long[]> createOffsets(
final Interval interval,
final int[] spacing) {

final int n = interval.numDimensions();
final ArrayList<long[]> offsets = new ArrayList<>();

final long[] offset = Intervals.minAsLongArray(interval);
for (int d = 0; d < n;) {
offsets.add(offset.clone());

for (d = 0; d < n; ++d) {
offset[d] += spacing[d];
if (offset[d] <= interval.max(d))
break;
else
offset[d] = interval.min(d);
}
}
return offsets;
}

/**
* Returns the grid coordinates of a given offset for a min coordinate and
* a grid spacing.
*/
public static long[] gridCell(
final long[] offset,
final long[] min,
final int[] spacing) {

final long[] gridCell = new long[offset.length];
Arrays.setAll(gridCell, i -> (offset[i] - min[i]) / spacing[i]);
return gridCell;
}

/**
* Returns the long coordinates <= scaled double coordinates.
*/
public static long[] floorScaled(final double[] doubles, final double scale) {

final long[] floorScaled = new long[doubles.length];
Arrays.setAll(floorScaled, i -> (long)Math.floor(doubles[i] * scale));
return floorScaled;
}

/**
* Returns the long coordinate >= scaled doubel coordinates.
*/
public static long[] ceilScaled(final double[] doubles, final double scale) {

final long[] ceilScaled = new long[doubles.length];
Arrays.setAll(ceilScaled, i -> (long)Math.ceil(doubles[i] * scale));
return ceilScaled;
}


public static class Block implements Serializable, Interval {
public final long[] dimensions;
public final long[] offset;
Expand All @@ -178,10 +114,6 @@ public Block(final long[] dimensions, final long[] offset, final long[] gridPosi
throw new IllegalArgumentException("Dimensions of block, offset, and grid position must match.");
}

public Block(final Block otherBlock) {
this(otherBlock.dimensions, otherBlock.offset, otherBlock.gridPosition);
}

public Block(final Interval interval, final long[] gridPosition) {
this(interval.dimensionsAsLongArray(), interval.minAsLongArray(), gridPosition);
}
Expand Down
37 changes: 37 additions & 0 deletions render-app/src/test/java/org/janelia/alignment/util/GridTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.janelia.alignment.util;

import java.util.List;

import org.junit.Assert;
import org.junit.Test;

/**
* Tests the {@link Grid} class.
*/
public class GridTest {

@Test
public void testCreate() {
final int tileWidth = 4096;
final int tileHeight = 4096;
final int[] blockSize = { 128, 128, 64 };

final long[] dimensions = { 34839, 19362, 29491};
final int[] gridBlockSize = { tileWidth, tileHeight, blockSize[2] };

final List<Grid.Block> blockList = Grid.create(dimensions, gridBlockSize, blockSize);

Assert.assertNotNull("block list is null", blockList);
Assert.assertEquals("invalid number of blocks", 20745, blockList.size());

final Grid.Block firstBlock = blockList.get(0);
Assert.assertNotNull("first block is null", firstBlock);
Assert.assertEquals("first block has invalid number of dimensions",
3, firstBlock.numDimensions());
for (int d = 0; d < 3; ++d) {
Assert.assertEquals("first block has invalid dimension " + d,
gridBlockSize[d], firstBlock.dimension(d));
}
}

}

0 comments on commit d055aa9

Please sign in to comment.