diff --git a/src/main/java/org/embl/mobie/lib/image/StitchedImage.java b/src/main/java/org/embl/mobie/lib/image/StitchedImage.java index f74e2565..81a32c63 100644 --- a/src/main/java/org/embl/mobie/lib/image/StitchedImage.java +++ b/src/main/java/org/embl/mobie/lib/image/StitchedImage.java @@ -28,6 +28,9 @@ */ package org.embl.mobie.lib.image; +import static net.imglib2.view.fluent.RandomAccessibleIntervalView.Extension.value; +import static net.imglib2.view.fluent.RandomAccessibleView.Interpolation.nearestNeighbor; + import bdv.tools.transformation.TransformedSource; import bdv.util.Affine3DHelpers; import bdv.util.DefaultInterpolators; @@ -42,7 +45,6 @@ import net.imglib2.RealPoint; import net.imglib2.RealRandomAccessible; import net.imglib2.Volatile; -import net.imglib2.interpolation.randomaccess.NearestNeighborInterpolatorFactory; import net.imglib2.outofbounds.OutOfBoundsConstantValueFactory; import net.imglib2.position.FunctionRandomAccessible; import net.imglib2.realtransform.AffineTransform3D; @@ -54,6 +56,7 @@ import net.imglib2.view.ExtendedRandomAccessibleInterval; import net.imglib2.view.IntervalView; import net.imglib2.view.Views; + import org.embl.mobie.DataStore; import org.embl.mobie.lib.MoBIEHelper; import org.embl.mobie.lib.ThreadHelper; @@ -392,7 +395,7 @@ static class StitchedSource< T extends Type< T > > implements Source< T > private final VoxelDimensions voxelDimensions; private final T type; private final String name; - private final DefaultInterpolators< ? extends NumericType > interpolators; + private final DefaultInterpolators interpolators; public StitchedSource( final Map< Integer, List< RandomAccessibleInterval< T > > > stitched, @@ -455,9 +458,9 @@ public RealRandomAccessible< T > getInterpolatedSource( int t, int level, Interp } else { - final T outOfBoundsVariable = type.createVariable(); - final RandomAccessible ra = new ExtendedRandomAccessibleInterval<>( getSource( t, level ), new OutOfBoundsConstantValueFactory<>( outOfBoundsVariable ) ); - return Views.interpolate( ra, new NearestNeighborInterpolatorFactory< T >() ); + return getSource( t, level ).view() + .extend( value( type.createVariable() ) ) + .interpolate( nearestNeighbor() ); } } diff --git a/src/main/java/org/embl/mobie/lib/plot/WithinDistancesSearchOnKDTree.java b/src/main/java/org/embl/mobie/lib/plot/WithinDistancesSearchOnKDTree.java index 027e49c6..4a3b4892 100644 --- a/src/main/java/org/embl/mobie/lib/plot/WithinDistancesSearchOnKDTree.java +++ b/src/main/java/org/embl/mobie/lib/plot/WithinDistancesSearchOnKDTree.java @@ -53,7 +53,7 @@ public WithinDistancesSearchOnKDTree( final KDTree< T > tree ) this.tree = tree; this.n = tree.numDimensions(); this.pos = new float[ n ]; - this.resultPoints = new ArrayList< ValuePair< KDTreeNode< T >, Double > >(); + this.resultPoints = new ArrayList<>(); } public void search( final RealLocalizable reference, final double[] distances, final boolean sortResults ) @@ -93,11 +93,11 @@ protected void searchNode( final KDTreeNode< T > current, final double[] distanc } } - Double distance = Double.valueOf( 0 ); // TODO: If we want round dots and if we want to sort + // TODO: If we want round dots and if we want to sort if ( closeEnough ) { - resultPoints.add( new ValuePair< KDTreeNode< T >, Double >( current, distance ) ); + resultPoints.add( new ValuePair<>( current, 0.0 ) ); } final double axisDiff = pos[ current.getSplitDimension() ] - current.getSplitCoordinate(); @@ -105,8 +105,21 @@ protected void searchNode( final KDTreeNode< T > current, final double[] distanc final double axisAbsDistance = Math.abs( axisDiff ); // search the near branch - final KDTreeNode< T > nearChild = leftIsNearBranch ? current.left : current.right; - final KDTreeNode< T > awayChild = leftIsNearBranch ? current.right : current.left; + final KDTreeNode< T > nearChild = leftIsNearBranch ? current.left() : current.right(); + final KDTreeNode< T > awayChild = leftIsNearBranch ? current.right() : current.left(); + + // TODO: Revise for efficiency: + // current.left() and current.right() are deprecated. + // They will create new KDTreeNode instances everytime. + // Searches on the KDTree are now implemented on net.imglib2.kdtree.KDTreeImpl (which has the tree structure but no associated values). + // See for example net.imglib2.kdtree.RadiusNeighborSearchImpl + // https://github.com/imglib/imglib2/blob/e6545cc41cabdcd16aba5f655fe9f92b9789797a/src/main/java/net/imglib2/kdtree/RadiusNeighborSearchImpl.java#L46 + // This is then wrapped to present the results as KDTreeNodes. + // See for example net.imglib2.neighborsearch.RadiusNeighborSearchOnKDTree + // https://github.com/imglib/imglib2/blob/e6545cc41cabdcd16aba5f655fe9f92b9789797a/src/main/java/net/imglib2/neighborsearch/RadiusNeighborSearchOnKDTree.java#L50 + // WithinDistancesSearchOnKDTree seems to be a slightly modified RadiusNeighborSearchOnKDTree? + // So it should be relatively easy to adapt. + if ( nearChild != null ) searchNode( nearChild, distances ); diff --git a/src/main/java/org/embl/mobie/lib/source/RandomAccessibleIntervalMipmapSource.java b/src/main/java/org/embl/mobie/lib/source/RandomAccessibleIntervalMipmapSource.java index 8406f966..4740dfd0 100644 --- a/src/main/java/org/embl/mobie/lib/source/RandomAccessibleIntervalMipmapSource.java +++ b/src/main/java/org/embl/mobie/lib/source/RandomAccessibleIntervalMipmapSource.java @@ -28,6 +28,9 @@ */ package org.embl.mobie.lib.source; +import static net.imglib2.view.fluent.RandomAccessibleIntervalView.Extension.value; +import static net.imglib2.view.fluent.RandomAccessibleView.Interpolation.nearestNeighbor; + import bdv.util.DefaultInterpolators; import bdv.viewer.Interpolation; import bdv.viewer.Source; @@ -52,7 +55,7 @@ public class RandomAccessibleIntervalMipmapSource< T extends Type< T > > impleme private final VoxelDimensions voxelDimensions; private final T type; private final String name; - private final DefaultInterpolators< ? extends NumericType > interpolators; + private final DefaultInterpolators interpolators; public RandomAccessibleIntervalMipmapSource( final List< RandomAccessibleInterval< T > > rais, @@ -118,9 +121,9 @@ public RealRandomAccessible< T > getInterpolatedSource( int t, int level, Interp } else { - final T outOfBoundsVariable = type.createVariable(); - final RandomAccessible ra = new ExtendedRandomAccessibleInterval<>( getSource( t, level ), new OutOfBoundsConstantValueFactory<>( outOfBoundsVariable ) ); - return Views.interpolate( ra, new NearestNeighborInterpolatorFactory< T >() ); + return getSource( t, level ).view() + .extend( value( type.createVariable() ) ) + .interpolate( nearestNeighbor() ); } }