diff --git a/src/main/java/org/embl/mobie/command/context/SIFT2DAlignCommand.java b/src/main/java/org/embl/mobie/command/context/SIFT2DAlignCommand.java index 9dee6f317..afdea4212 100644 --- a/src/main/java/org/embl/mobie/command/context/SIFT2DAlignCommand.java +++ b/src/main/java/org/embl/mobie/command/context/SIFT2DAlignCommand.java @@ -32,24 +32,61 @@ import bdv.util.BdvHandle; import bdv.viewer.SourceAndConverter; import ij.IJ; -import ij.gui.NonBlockingGenericDialog; -import ij.gui.YesNoCancelDialog; import net.imglib2.realtransform.AffineTransform3D; import org.embl.mobie.command.CommandConstants; +import org.scijava.command.Interactive; import org.scijava.plugin.Parameter; import org.scijava.plugin.Plugin; +import org.scijava.widget.Button; import sc.fiji.bdvpg.scijava.command.BdvPlaygroundActionCommand; @Plugin(type = BdvPlaygroundActionCommand.class, menuPath = CommandConstants.CONTEXT_MENU_ITEMS_ROOT + "Transform>Registration - SIFT") -public class SIFT2DAlignCommand implements BdvPlaygroundActionCommand +public class SIFT2DAlignCommand implements BdvPlaygroundActionCommand, Interactive { static { net.imagej.patcher.LegacyInjector.preinit(); } @Parameter public BdvHandle bdvHandle; + @Parameter ( label = "Compute Alignment", callback = "compute") + private Button compute; + + @Parameter ( label = "Toggle Alignment", callback = "toggle") + private Button toggle; + + private AffineTransform3D previousTransform; + private AffineTransform3D newTransform; + private TransformedSource< ? > transformedSource; + private boolean isAligned; + @Override public void run() + { + // + } + + private void toggle() + { + if ( transformedSource == null ) + { + IJ.showMessage( "Please first [ Compute Alignment ]." ); + return; + } + + if ( isAligned ) + { + transformedSource.setFixedTransform( previousTransform ); + } + else + { + transformedSource.setFixedTransform( newTransform ); + } + + bdvHandle.getViewerPanel().requestRepaint(); + isAligned = ! isAligned; + } + + private void compute() { IJ.log("# SIFT registration" + "\nThe registration is computed in the currently visible 2D plane" + @@ -63,33 +100,26 @@ public void run() if ( movingSac.getSpimSource() instanceof TransformedSource ) { // apply the transformation - AffineTransform3D siftTransform3D = aligner.getSiftTransform3D(); - TransformedSource< ? > transformedSource = ( TransformedSource< ? > ) movingSac.getSpimSource(); - AffineTransform3D previousFixedTransform = new AffineTransform3D(); - transformedSource.getFixedTransform( previousFixedTransform ); - AffineTransform3D newFixedTransform = previousFixedTransform.copy(); - newFixedTransform.preConcatenate( siftTransform3D ); - transformedSource.setFixedTransform( newFixedTransform ); - bdvHandle.getViewerPanel().requestRepaint(); + AffineTransform3D siftTransform = aligner.getSiftTransform3D(); + transformedSource = ( TransformedSource< ? > ) movingSac.getSpimSource(); + previousTransform = new AffineTransform3D(); + transformedSource.getFixedTransform( previousTransform ); + newTransform = previousTransform.copy(); + newTransform.preConcatenate( siftTransform ); + transformedSource.setFixedTransform( newTransform ); + IJ.showMessage( "Transforming " + transformedSource.getName() ); + IJ.showMessage( "Previous Transform: " + previousTransform ); + IJ.showMessage( "Additional SIFT Transform: " + siftTransform ); + IJ.showMessage( "Combined Transform: " + newTransform ); - // ask user whether to accept the transformation - NonBlockingGenericDialog dialog = new NonBlockingGenericDialog( "SIFT Alignment" ); - dialog.addMessage( "Press OK to keep the transformation" ); - dialog.addMessage( "Press Cancel to discard the transformation" ); - dialog.showDialog(); - if ( dialog.wasOKed() ) - { - IJ.log( "Transformed " + movingSac.getSpimSource().getName() + " with " + siftTransform3D ); - } - else if ( dialog.wasCanceled() ) - { - transformedSource.setFixedTransform( previousFixedTransform ); - bdvHandle.getViewerPanel().requestRepaint(); - } + isAligned = true; + bdvHandle.getViewerPanel().requestRepaint(); } else { IJ.log("Cannot apply transformation to image of type " + movingSac.getSpimSource().getClass() ); } } + + } diff --git a/src/main/java/org/embl/mobie/command/context/SIFT2DAligner.java b/src/main/java/org/embl/mobie/command/context/SIFT2DAligner.java index 34716d245..21ac1f8af 100644 --- a/src/main/java/org/embl/mobie/command/context/SIFT2DAligner.java +++ b/src/main/java/org/embl/mobie/command/context/SIFT2DAligner.java @@ -79,6 +79,8 @@ public class SIFT2DAligner private SourceAndConverter< ? > fixedSac; private SourceAndConverter< ? > movingSac; private ScreenShotMaker screenShotMaker; + private static String fixedImageName; + private static String movingImageName; static private class Param { @@ -135,8 +137,9 @@ public SIFT2DAligner( BdvHandle bdvHandle ) public boolean showUI() { - if( p.pixelSize == null ) - p.pixelSize = BdvHandleHelper.getViewerVoxelSpacing( bdvHandle ); + double viewerVoxelSpacing = BdvHandleHelper.getViewerVoxelSpacing( bdvHandle ); + + p.pixelSize = 2 * viewerVoxelSpacing; List< SourceAndConverter< ? > > sourceAndConverters = MoBIEHelper.getVisibleSacs( bdvHandle ); if ( sourceAndConverters.size() < 2 ) @@ -151,8 +154,11 @@ public boolean showUI() final GenericDialog gd = new GenericDialog( "SIFT 2D Aligner" ); - gd.addChoice( "fixed_image :", titles, titles[ 0 ] ); - gd.addChoice( "moving_image :", titles, titles[ 1 ] ); + String fixedDefault = Arrays.asList( titles ).contains( fixedImageName ) ? fixedImageName : titles[ 0 ]; + gd.addChoice( "fixed_image :", titles, fixedDefault ); + + String movingDefault = Arrays.asList( titles ).contains( movingImageName ) ? movingImageName : titles[ 1 ]; + gd.addChoice( "moving_image :", titles, movingDefault ); String voxelUnit = sourceAndConverters.get( 0 ).getSpimSource().getVoxelDimensions().unit(); gd.addNumericField( "pixel_size :", p.pixelSize, 2, 6, voxelUnit ); @@ -178,8 +184,8 @@ public boolean showUI() if (gd.wasCanceled()) return false; - String fixedImageName = gd.getNextChoice(); - String movingImageName = gd.getNextChoice(); + fixedImageName = gd.getNextChoice(); + movingImageName = gd.getNextChoice(); p.pixelSize = gd.getNextNumber(); p.modelIndex = gd.getNextChoiceIndex(); diff --git a/src/main/java/org/embl/mobie/command/open/OpenHCSDatasetCommand.java b/src/main/java/org/embl/mobie/command/open/OpenHCSDatasetCommand.java index 3901671f7..1c49b3ff0 100644 --- a/src/main/java/org/embl/mobie/command/open/OpenHCSDatasetCommand.java +++ b/src/main/java/org/embl/mobie/command/open/OpenHCSDatasetCommand.java @@ -37,7 +37,6 @@ import org.scijava.plugin.Plugin; import org.scijava.widget.Button; -import java.io.File; import java.io.IOException; diff --git a/src/test/java/projects/em_xray_alignment/OpenEMXRAY.java b/src/test/java/projects/em_xray_alignment/OpenEMXRAY.java index dbca1bfb6..37b121179 100644 --- a/src/test/java/projects/em_xray_alignment/OpenEMXRAY.java +++ b/src/test/java/projects/em_xray_alignment/OpenEMXRAY.java @@ -10,7 +10,7 @@ public class OpenEMXRAY { public static void main( String[] args ) throws IOException { - OpenerLogging.setLogging( true ); +// OpenerLogging.setLogging( true ); final ImageJ imageJ = new ImageJ(); imageJ.ui().showUI(); new MoBIE("/Volumes/cba/exchange/em-xray-alignment/mobie" );