From 3e65fef2e390edd2609bd590fe39c15e6a15efbc Mon Sep 17 00:00:00 2001 From: Christian Tischer Date: Thu, 13 Jun 2024 20:16:43 +0200 Subject: [PATCH] Fixes #1153 --- .../lib/bdv/view/AnnotationSliceView.java | 11 +++++----- .../embl/mobie/lib/source/SourceHelper.java | 3 +-- .../viewer/MoBIEViewerTransformAdjuster.java | 7 +++--- .../viewer/ViewerTransformChanger.java | 11 +++++----- .../org/embl/mobie/lib/view/ViewManager.java | 4 ++-- .../embl/mobie/lib/view/save/ViewSaver.java | 3 ++- .../embl/mobie/ui/UserInterfaceHelper.java | 22 +++++++++++++++---- 7 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/embl/mobie/lib/bdv/view/AnnotationSliceView.java b/src/main/java/org/embl/mobie/lib/bdv/view/AnnotationSliceView.java index d4e797c9..476a74ec 100644 --- a/src/main/java/org/embl/mobie/lib/bdv/view/AnnotationSliceView.java +++ b/src/main/java/org/embl/mobie/lib/bdv/view/AnnotationSliceView.java @@ -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 > diff --git a/src/main/java/org/embl/mobie/lib/source/SourceHelper.java b/src/main/java/org/embl/mobie/lib/source/SourceHelper.java index 6ab75992..31a69812 100644 --- a/src/main/java/org/embl/mobie/lib/source/SourceHelper.java +++ b/src/main/java/org/embl/mobie/lib/source/SourceHelper.java @@ -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 ) diff --git a/src/main/java/org/embl/mobie/lib/transform/viewer/MoBIEViewerTransformAdjuster.java b/src/main/java/org/embl/mobie/lib/transform/viewer/MoBIEViewerTransformAdjuster.java index de57d541..bc6ec8cc 100644 --- a/src/main/java/org/embl/mobie/lib/transform/viewer/MoBIEViewerTransformAdjuster.java +++ b/src/main/java/org/embl/mobie/lib/transform/viewer/MoBIEViewerTransformAdjuster.java @@ -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); @@ -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; } diff --git a/src/main/java/org/embl/mobie/lib/transform/viewer/ViewerTransformChanger.java b/src/main/java/org/embl/mobie/lib/transform/viewer/ViewerTransformChanger.java index 60a384c4..ac24d168 100644 --- a/src/main/java/org/embl/mobie/lib/transform/viewer/ViewerTransformChanger.java +++ b/src/main/java/org/embl/mobie/lib/transform/viewer/ViewerTransformChanger.java @@ -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 ) { @@ -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 ); } } @@ -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 ); diff --git a/src/main/java/org/embl/mobie/lib/view/ViewManager.java b/src/main/java/org/embl/mobie/lib/view/ViewManager.java index 7d524323..356da55d 100644 --- a/src/main/java/org/embl/mobie/lib/view/ViewManager.java +++ b/src/main/java/org/embl/mobie/lib/view/ViewManager.java @@ -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 ); } } diff --git a/src/main/java/org/embl/mobie/lib/view/save/ViewSaver.java b/src/main/java/org/embl/mobie/lib/view/save/ViewSaver.java index 5a22c687..9fd3957f 100644 --- a/src/main/java/org/embl/mobie/lib/view/save/ViewSaver.java +++ b/src/main/java/org/embl/mobie/lib/view/save/ViewSaver.java @@ -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(); diff --git a/src/main/java/org/embl/mobie/ui/UserInterfaceHelper.java b/src/main/java/org/embl/mobie/ui/UserInterfaceHelper.java index 6170da92..4a36da0c 100644 --- a/src/main/java/org/embl/mobie/ui/UserInterfaceHelper.java +++ b/src/main/java/org/embl/mobie/ui/UserInterfaceHelper.java @@ -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" ) ); @@ -1210,7 +1210,9 @@ 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" ); @@ -1218,8 +1220,20 @@ public static JButton createFocusButton( AbstractDisplay sourceDisplay, BdvHandl 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;