Skip to content

Commit

Permalink
fix: bug in transform caching
Browse files Browse the repository at this point in the history
* test sizes of scale levels of cached transformed images
  • Loading branch information
bogovicj committed Oct 7, 2024
1 parent 3fd4662 commit d987cee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/main/java/bigwarp/BigWarpInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -1038,15 +1038,15 @@ public static <T extends NumericType<T> & NativeType<T>, V extends Volatile<T> &
// update the source transform to take into account any change in bounding box
final AffineTransform3D newSourceTform = origScaleTform.copy();
final Translation tlation = new Translation(targetInterval.minAsDoubleArray());
newSourceTform.concatenate(tlation.inverse());
newSourceTform.concatenate(tlation);
sourceTransforms[i] = newSourceTform;

InvertibleRealTransformSequence tformToPixelSpace = new InvertibleRealTransformSequence();
tformToPixelSpace.add(origScaleTform);
tformToPixelSpace.add(newSourceTform);
tformToPixelSpace.add(transform.copy());
tformToPixelSpace.add(newSourceTform.inverse());
tformToPixelSpace.add(origScaleTform.inverse());

final RandomAccessibleInterval<T> raiTform = transform( img, pixelInterval, tformToPixelSpace);
final RandomAccessibleInterval<T> raiTform = transform(img, pixelInterval, tformToPixelSpace);
final ReadOnlyCachedCellImgFactory cacheFactory = new ReadOnlyCachedCellImgFactory(
new ReadOnlyCachedCellImgOptions()
.volatileAccesses(true)
Expand All @@ -1071,16 +1071,16 @@ public void load(SingleCellArrayImg<T, ?> cell) throws Exception {
final CacheHints cacheHints = new CacheHints(LoadingStrategy.BUDGETED, priority, false);
vmipmaps[i] = VolatileViews.wrapAsVolatile(cachedTransformedMipmap, sharedQueue, cacheHints);
}

final RandomAccessibleIntervalMipmapSource<T> cachedTransformedSource =
new RandomAccessibleIntervalMipmapSource<T>(
mipmaps,
type,
sourceTransforms,
src.getVoxelDimensions(),
src.getName(),
src.getName() + "cached tform",
src.doBoundingBoxCulling());


final Source<V> vsrc = new VolatileSource<T, V>(cachedTransformedSource, vtype, sharedQueue);
final SourceAndConverter<V> vsac = new SourceAndConverter<V>(vsrc, BigDataViewer.createConverterToARGB(vtype));
return new SourceAndConverter<T>(cachedTransformedSource, BigDataViewer.createConverterToARGB(type), vsac);
Expand Down
9 changes: 8 additions & 1 deletion src/test/java/bigwarp/BigWarpTransformCacheTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ public void cachedIdentityTransform() {
Source<UnsignedByteType> tgtSrc = bwData.getTargetSource(0).getSpimSource();
assertEquals("moving source is not cached", CachedCellImg.class, mvgSrc.getSource(0, 0).getClass());

assertArrayEquals("scale level 0 pixel raster wrong size",
tgtSrc.getSource(0, 0).dimensionsAsLongArray(),
mvgSrc.getSource(0, 0).dimensionsAsLongArray());
assertArrayEquals("scale level 1 pixel raster wrong size",
tgtSrc.getSource(0, 1).dimensionsAsLongArray(),
mvgSrc.getSource(0, 1).dimensionsAsLongArray());

assertTrue("scale level 0 not equal", equal(tgtSrc.getSource(0, 0), mvgSrc.getSource(0, 0)));
assertTrue("scale level 1 not equal", equal(tgtSrc.getSource(0, 1), mvgSrc.getSource(0, 1)));
}
Expand Down Expand Up @@ -111,7 +118,7 @@ public void cachedTranslationTransformOffset() {

final AffineTransform3D tgtTform0 = new AffineTransform3D();
tgtSrc.getSourceTransform(0, 0, tgtTform0);
tgtTform0.preConcatenate(translation);
tgtTform0.preConcatenate(translation.inverse());

assertArrayEquals("mvg transform is not the translated tgt transform", tgtTform0.getRowPackedCopy(), mvgTform0.getRowPackedCopy(), 1e-9);
}
Expand Down

0 comments on commit d987cee

Please sign in to comment.