Skip to content

Commit

Permalink
Fixes #1153
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Jun 13, 2024
1 parent 71c6cee commit 3e65fef
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,34 @@
import bdv.viewer.Source;
import bdv.viewer.SourceAndConverter;
import bdv.viewer.SynchronizedViewerState;
import net.imglib2.Volatile;
import net.imglib2.converter.Converter;
import net.imglib2.roi.RealMaskRealInterval;
import net.imglib2.type.numeric.ARGBType;
import org.embl.mobie.MoBIE;
import org.embl.mobie.DataStore;
import org.embl.mobie.MoBIE;
import org.embl.mobie.lib.annotation.Annotation;
import org.embl.mobie.lib.annotation.SliceViewAnnotationSelector;
import org.embl.mobie.lib.color.AnnotationARGBConverter;
import org.embl.mobie.lib.color.ColoringListener;
import org.embl.mobie.lib.color.VolatileAnnotationARGBConverter;
import org.embl.mobie.lib.image.Image;
import org.embl.mobie.lib.image.SpotAnnotationImage;
import org.embl.mobie.lib.playground.BdvPlaygroundHelper;
import org.embl.mobie.lib.select.SelectionListener;
import org.embl.mobie.lib.serialize.display.AbstractAnnotationDisplay;
import org.embl.mobie.lib.serialize.display.RegionDisplay;
import org.embl.mobie.lib.serialize.display.SegmentationDisplay;
import org.embl.mobie.lib.select.SelectionListener;
import org.embl.mobie.lib.serialize.display.SpotDisplay;
import org.embl.mobie.lib.source.AnnotationType;
import org.embl.mobie.lib.source.BoundarySource;
import org.embl.mobie.lib.image.Image;
import org.embl.mobie.lib.source.SourceHelper;
import org.embl.mobie.lib.source.VolatileBoundarySource;
import org.embl.mobie.lib.annotation.Annotation;
import org.embl.mobie.lib.transform.viewer.ViewerTransformChanger;
import org.embl.mobie.lib.volume.SegmentVolumeViewer;
import net.imglib2.Volatile;
import sc.fiji.bdvpg.services.SourceAndConverterServices;

import javax.swing.*;
import javax.xml.crypto.Data;
import java.awt.*;

public class AnnotationSliceView< A extends Annotation > extends AbstractSliceView implements ColoringListener, SelectionListener< A >
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/embl/mobie/lib/source/SourceHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ public static RealMaskRealInterval getMask( Source< ? > source, int t )
// create mask
// as compared with estimateBounds this has the
// advantage that it can represent a rotated box
final RealMaskRealInterval mask = GeomMasks.closedBox( min, max ).transform( sourceTransform.inverse() );
return mask;
return GeomMasks.closedBox( min, max ).transform( sourceTransform.inverse() );
}

public static RealMaskRealInterval estimatePhysicalMask( Source< ? > source, int t, boolean includeVoxelDimensions )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public AffineTransform3D getSingleSourceTransform()
double[] pScreen = new double[3];
sourceTransform.apply(pSource, pGlobal);


LinAlgHelpers.quaternionApply(qViewer, centerGlobal, translation);
LinAlgHelpers.scale(translation, -1.0D, translation);
LinAlgHelpers.setCol(3, translation, m);
Expand All @@ -115,10 +114,12 @@ public AffineTransform3D getSingleSourceTransform()
}
}

// TODO: This does not seem to work well if one of the sources
// contains a rotation: https://github.com/mobie/mobie-viewer-fiji/issues/1153
public AffineTransform3D getMultiSourceTransform() {
SynchronizedViewerState state = bdvHandle.getViewerPanel().state();
final RealInterval bounds = TransformHelper.createMask( sources, state.getCurrentTimepoint() );
final AffineTransform3D transform = TransformHelper.getIntervalViewerTransform( bdvHandle, bounds );
final RealInterval mask = TransformHelper.createMask( sources, state.getCurrentTimepoint() );
final AffineTransform3D transform = TransformHelper.getIntervalViewerTransform( bdvHandle, mask );
return transform;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@
public abstract class ViewerTransformChanger
{
public static int animationDurationMillis = 1500;

private static BdvOverlaySource< BdvOverlay > pointOverlaySource;
private static CircleOverlay circleOverlay;
private static boolean pointOverlaySourceIsActive;
private static boolean isPointOverlayEnabled;

public static void changeLocation( BdvHandle bdvHandle, ViewerTransform viewerTransform )
public static void apply( BdvHandle bdvHandle, ViewerTransform viewerTransform )
{
if ( viewerTransform instanceof PositionViewerTransform )
{
Expand All @@ -67,18 +66,18 @@ else if ( viewerTransform instanceof TimepointViewerTransform )
else if ( viewerTransform instanceof NormalVectorViewerTransform )
{
final AffineTransform3D transform = NormalVectorViewerTransform.createTransform( bdvHandle, viewerTransform.getParameters() );
changeLocation( bdvHandle, transform, animationDurationMillis );
apply( bdvHandle, transform, animationDurationMillis );
adaptTimepoint( bdvHandle, viewerTransform );
}
else if ( viewerTransform instanceof AffineViewerTransform )
{
changeLocation( bdvHandle, TransformHelper.asAffineTransform3D( viewerTransform.getParameters() ), animationDurationMillis );
apply( bdvHandle, TransformHelper.asAffineTransform3D( viewerTransform.getParameters() ), animationDurationMillis );
adaptTimepoint( bdvHandle, viewerTransform );
}
else if ( viewerTransform instanceof NormalizedAffineViewerTransform )
{
final AffineTransform3D transform = TransformHelper.createUnnormalizedViewerTransform( TransformHelper.asAffineTransform3D( viewerTransform.getParameters() ), bdvHandle.getBdvHandle().getViewerPanel() );
changeLocation( bdvHandle, transform, animationDurationMillis );
apply( bdvHandle, transform, animationDurationMillis );
adaptTimepoint( bdvHandle, viewerTransform );
}
}
Expand Down Expand Up @@ -160,7 +159,7 @@ public static void moveToPosition( BdvHandle bdvHandle, double[] xyz, long durat
}
}

public static void changeLocation( BdvHandle bdvHandle, AffineTransform3D newViewerTransform, long duration)
public static void apply( BdvHandle bdvHandle, AffineTransform3D newViewerTransform, long duration )
{
AffineTransform3D currentViewerTransform = new AffineTransform3D();
bdvHandle.getBdvHandle().getViewerPanel().state().getViewerTransform( currentViewerTransform );
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/embl/mobie/lib/view/ViewManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ public synchronized void show( View view )
final String imageName = ( ( ImageZoomViewerTransform ) viewerTransform ).getImageName();
final RealMaskRealInterval mask = DataStore.getImage( imageName ).getMask();
final AffineTransform3D transform = TransformHelper.getIntervalViewerTransform( bdvHandle, mask );
ViewerTransformChanger.changeLocation( bdvHandle, transform, 0 );
ViewerTransformChanger.apply( bdvHandle, transform, 0 );
}
else
{
ViewerTransformChanger.changeLocation( bdvHandle, viewerTransform );
ViewerTransformChanger.apply( bdvHandle, viewerTransform );
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/embl/mobie/lib/view/save/ViewSaver.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public boolean saveViewDialog( View view )
gd.addStringField("New selection group", "my-new-group", 30 );

gd.showDialog();
if( gd.wasCanceled() ) return;

if( gd.wasCanceled() ) return false;

// fetch primary user input
saveToProjectOrFile = gd.getNextChoice();
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/org/embl/mobie/ui/UserInterfaceHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ public JPanel createMoveToLocationPanel( ViewerTransform transform )
button.addActionListener( e ->
{
ViewerTransform viewerTransform = ViewerTransform.toViewerTransform( jTextField.getText() );
ViewerTransformChanger.changeLocation( this.moBIE.getViewManager().getSliceViewer().getBdvHandle(), viewerTransform );
ViewerTransformChanger.apply( this.moBIE.getViewManager().getSliceViewer().getBdvHandle(), viewerTransform );
} );

panel.add( SwingHelper.getJLabel( "location" ) );
Expand Down Expand Up @@ -1210,16 +1210,30 @@ public void visibility( boolean isVisible )
return checkBox;
}

public static JButton createFocusButton( AbstractDisplay sourceDisplay, BdvHandle bdvHandle, List< Source< ? > > sources )
public static JButton createFocusButton( AbstractDisplay< ? > sourceDisplay,
BdvHandle bdvHandle,
List< Source< ? > > sources )
{
JButton button = new JButton( "F" );
button.setToolTipText( "Show whole dataset" );
button.setPreferredSize( PREFERRED_BUTTON_SIZE );

button.addActionListener( e ->
{
final AffineTransform3D transform = new MoBIEViewerTransformAdjuster( sourceDisplay.sliceViewer.getBdvHandle(), sources ).getMultiSourceTransform();
new sc.fiji.bdvpg.bdv.navigate.ViewerTransformChanger( bdvHandle, transform, false, ViewerTransformChanger.animationDurationMillis ).run();
if ( sources.size() == 1 )
{
final AffineTransform3D transform = new MoBIEViewerTransformAdjuster(
sourceDisplay.sliceViewer.getBdvHandle(),
sources ).getSingleSourceTransform();
ViewerTransformChanger.apply( bdvHandle, transform, ViewerTransformChanger.animationDurationMillis );
}
else
{
final AffineTransform3D transform = new MoBIEViewerTransformAdjuster(
sourceDisplay.sliceViewer.getBdvHandle(),
sources ).getMultiSourceTransform();
ViewerTransformChanger.apply( bdvHandle, transform, ViewerTransformChanger.animationDurationMillis );
}
} );

return button;
Expand Down

0 comments on commit 3e65fef

Please sign in to comment.