-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
start RealTransformedSource #133
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,10 +152,12 @@ | |
<dependency> | ||
<groupId>net.imglib2</groupId> | ||
<artifactId>imglib2</artifactId> | ||
<version>5.13.1-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.imglib2</groupId> | ||
<artifactId>imglib2-realtransform</artifactId> | ||
<version>3.1.3-SNAPSHOT</version> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. You could override https://github.com/scijava/pom-scijava/blob/4e69adda1c948f929bcd4d0bf7bb98a1a0e04387/pom.xml#L611 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree, was lazy since both this and the above will both change after new releases. |
||
</dependency> | ||
<dependency> | ||
<groupId>net.imglib2</groupId> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
/* | ||
* #%L | ||
* BigDataViewer core classes with minimal dependencies. | ||
* %% | ||
* Copyright (C) 2012 - 2022 BigDataViewer developers. | ||
* %% | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* #L% | ||
*/ | ||
package bdv.tools.transformation; | ||
|
||
import java.util.function.BiFunction; | ||
import java.util.function.Supplier; | ||
|
||
import bdv.viewer.Interpolation; | ||
import bdv.viewer.Source; | ||
import bdv.viewer.render.DefaultMipmapOrdering; | ||
import bdv.viewer.render.MipmapOrdering; | ||
import mpicbg.spim.data.sequence.VoxelDimensions; | ||
import net.imglib2.Interval; | ||
import net.imglib2.RandomAccessibleInterval; | ||
import net.imglib2.RealRandomAccessible; | ||
import net.imglib2.realtransform.AffineTransform3D; | ||
import net.imglib2.realtransform.InvertibleRealTransform; | ||
import net.imglib2.realtransform.RealTransform; | ||
import net.imglib2.realtransform.RealTransformRealRandomAccessible; | ||
import net.imglib2.realtransform.RealTransformSequence; | ||
import net.imglib2.util.Intervals; | ||
import net.imglib2.util.RealIntervals; | ||
import net.imglib2.view.Views; | ||
|
||
/** | ||
* A {@link Source} that wraps another {@link Source}, transforming it with a | ||
* {@link InvertibleRealTransform}. | ||
* | ||
* @author John Bogovic | ||
* | ||
* @param <T> the type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps more specifically you mean the pixel type for |
||
*/ | ||
public class RealTransformedSource < T > implements Source< T >, MipmapOrdering | ||
{ | ||
/** | ||
* The wrapped {@link Source}. | ||
*/ | ||
private final Source< T > source; | ||
|
||
private final String name; | ||
|
||
/** | ||
* This is either the {@link #source} itself, if it implements | ||
* {@link MipmapOrdering}, or a {@link DefaultMipmapOrdering}. | ||
*/ | ||
private final MipmapOrdering sourceMipmapOrdering; | ||
|
||
private InvertibleRealTransform transform; | ||
|
||
private final Supplier< Boolean > boundingBoxCullingSupplier; | ||
|
||
private final BiFunction< RealTransform, Interval, Interval > boundingBoxEstimator; | ||
|
||
public RealTransformedSource( final Source< T > source, final String name, | ||
final InvertibleRealTransform transform ) | ||
{ | ||
this( source, name, transform, | ||
(t,i) -> { return Intervals.smallestContainingInterval( | ||
RealIntervals.boundingIntervalFaces( i, t, 5 )); }, | ||
null ); | ||
} | ||
|
||
public RealTransformedSource( final Source< T > source, final String name, | ||
final BiFunction< RealTransform, Interval, Interval > boundingBoxEstimator, | ||
final InvertibleRealTransform transform ) | ||
{ | ||
this( source, name, transform, boundingBoxEstimator, null ); | ||
} | ||
|
||
public RealTransformedSource( final Source< T > source, final String name, | ||
final InvertibleRealTransform transform, | ||
final BiFunction< RealTransform, Interval, Interval > boundingBoxEstimator, | ||
final Supplier< Boolean > doBoundingBoxCulling ) | ||
{ | ||
this.source = source; | ||
this.name = name; | ||
this.boundingBoxEstimator = boundingBoxEstimator; | ||
this.boundingBoxCullingSupplier = doBoundingBoxCulling; | ||
setTransform( transform ); | ||
|
||
sourceMipmapOrdering = MipmapOrdering.class.isInstance( source ) ? | ||
( MipmapOrdering ) source : new DefaultMipmapOrdering( source ); | ||
} | ||
|
||
@Override | ||
public boolean isPresent( final int t ) | ||
{ | ||
return source.isPresent( t ); | ||
} | ||
|
||
@Override | ||
public boolean doBoundingBoxCulling() | ||
{ | ||
if( boundingBoxCullingSupplier != null ) | ||
return boundingBoxCullingSupplier.get(); | ||
else | ||
return source.doBoundingBoxCulling(); | ||
} | ||
|
||
public void setTransform( final InvertibleRealTransform transform ) | ||
{ | ||
this.transform = transform; | ||
} | ||
|
||
public Source< T > getWrappedSource() | ||
{ | ||
return source; | ||
} | ||
|
||
@Override | ||
public RandomAccessibleInterval< T > getSource( final int t, final int level ) | ||
{ | ||
// TODO expose interp method - it probably matters | ||
@SuppressWarnings("unchecked") | ||
final RealTransformRealRandomAccessible<T,?> interpSrc = (RealTransformRealRandomAccessible<T,?>)getInterpolatedSource( t, level, Interpolation.NEARESTNEIGHBOR ); | ||
|
||
final AffineTransform3D transform = new AffineTransform3D(); | ||
source.getSourceTransform( t, level, transform ); | ||
final RealTransformSequence totalInverseTransform = new RealTransformSequence(); | ||
totalInverseTransform.add( transform.inverse() ); | ||
totalInverseTransform.add( transform.inverse() ); | ||
totalInverseTransform.add( transform ); | ||
final Interval boundingInterval = boundingBoxEstimator.apply( totalInverseTransform, source.getSource( t, level ) ); | ||
|
||
return Views.interval( Views.raster(interpSrc), boundingInterval ); | ||
} | ||
|
||
@Override | ||
public RealRandomAccessible< T > getInterpolatedSource( final int t, final int level, final Interpolation method ) | ||
{ | ||
final RealRandomAccessible<T> realSrc = source.getInterpolatedSource( t, level, method ); | ||
final AffineTransform3D transform = new AffineTransform3D(); | ||
source.getSourceTransform( t, level, transform ); | ||
|
||
final RealTransformSequence totalTransform = new RealTransformSequence(); | ||
totalTransform.add( transform ); | ||
totalTransform.add( transform ); | ||
totalTransform.add( transform.inverse() ); | ||
|
||
return new RealTransformRealRandomAccessible< T, RealTransform >( realSrc, totalTransform ); | ||
} | ||
|
||
@Override | ||
public synchronized void getSourceTransform( final int t, final int level, final AffineTransform3D transform ) | ||
{ | ||
source.getSourceTransform( t, level, transform ); | ||
} | ||
|
||
public InvertibleRealTransform getTransform() | ||
{ | ||
return transform; | ||
} | ||
|
||
@Override | ||
public T getType() | ||
{ | ||
return source.getType(); | ||
} | ||
|
||
@Override | ||
public String getName() | ||
{ | ||
return name; | ||
} | ||
|
||
@Override | ||
public VoxelDimensions getVoxelDimensions() | ||
{ | ||
return source.getVoxelDimensions(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it always the case that the transformed dimensions are the same as the source dimensions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good question. yes it's always the same, since it also defers getSourceTransform to the wrapped source. The transform should be though of as world coordinates to world coordinates (I should include this in the doc). thanks @mkitti ! |
||
} | ||
|
||
@Override | ||
public int getNumMipmapLevels() | ||
{ | ||
return source.getNumMipmapLevels(); | ||
} | ||
|
||
@Override | ||
public synchronized MipmapHints getMipmapHints( final AffineTransform3D screenTransform, final int timepoint, final int previousTimepoint ) | ||
{ | ||
return sourceMipmapOrdering.getMipmapHints( screenTransform, timepoint, previousTimepoint ); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could override the property
imglib2.version
instead of adding this here.https://github.com/scijava/pom-scijava/blob/4e69adda1c948f929bcd4d0bf7bb98a1a0e04387/pom.xml#L583