Skip to content

Commit

Permalink
Address #1176
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Jul 10, 2024
1 parent 1b653d2 commit 132503f
Show file tree
Hide file tree
Showing 5 changed files with 505 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public abstract class AbstractTransformationCommand extends DynamicCommand imple
@Parameter ( label = "Moving image(s)" ) // , callback = "setMovingImages"
public SelectableImages selectedImages;

// FIXME: change the suffix based on the registration method in an init()
@Parameter ( label = "Transformed image(s) suffix",
description = "Upon transformation this suffix will be appended to the moving image name.\n" +
"Carefully choose a meaningful suffix here that will create a unique new image name.\n" +
Expand Down Expand Up @@ -131,27 +132,36 @@ protected void applyTransform( AffineTransform3D affineTransform3D )
// applyTransformInPlace( affineTransform3D );
}

createSaveAndViewAffineTransformedImages( movingImages, affineTransform3D, suffix );
if ( createSaveAndViewAffineTransformedImages(
movingImages,
affineTransform3D,
suffix ) )
{
// Remove the moving image displays
// because the transformed ones are being shown
List< String > movingImageNames = selectedImages.getNames();
ViewManager viewManager = MoBIE.getInstance().getViewManager();
List< Display > displays = viewManager.getCurrentSourceDisplays();
List< Display > displaysToRemove = displays.stream()
.filter( display -> display.getSources().size() == 1 )
.filter( display -> display.getSources().stream().anyMatch( movingImageNames::contains ) )
.collect( Collectors.toList() );

// Remove the moving image displays
// because we are now showing the transformed once
List< String > movingImageNames = selectedImages.getNames();
ViewManager viewManager = MoBIE.getInstance().getViewManager();
List< Display > displays = viewManager.getCurrentSourceDisplays();
List< Display > displaysToRemove = displays.stream()
.filter( display -> display.getSources().size() == 1 )
.filter( display -> display.getSources().stream().anyMatch( movingImageNames::contains ) )
.collect( Collectors.toList() );
for ( Display display : displaysToRemove )
viewManager.removeDisplay( display, false );
}
else
{
resetTransforms();
}

for ( Display display : displaysToRemove )
viewManager.removeDisplay( display, false );

// FIXME close the Command UI, HOW?
// Maybe we use the hack that finds the awt Window based on its name?
// https://imagesc.zulipchat.com/#narrow/stream/327238-Fiji/topic/Close.20Scijava.20Command.20UI
}

protected static void createSaveAndViewAffineTransformedImages(
protected static boolean createSaveAndViewAffineTransformedImages(
Collection< Image< ? > > movingImages,
AffineTransform3D affineTransform3D,
String suffix )
Expand All @@ -178,15 +188,21 @@ protected static void createSaveAndViewAffineTransformedImages(
if ( MoBIE.getInstance().getViewManager().getViewsSaver().saveViewDialog( view ) )
{
// Show the transformed images
// TODO: it would be nice to remove the non-transformed images from the current view
MoBIE.getInstance().getViewManager().show( view );
}
else
{
// TODO: if a user clicks "Cancel" in-between to sources this will create a mess
// Probably anyway better we save all the transformed sources in one go.
return false;
}
}

return true;
}

protected void setMovingImages()
{

// Reset potential previous transforms
if ( movingSources != null )
{
Expand Down Expand Up @@ -246,40 +262,4 @@ protected void resetTransforms()
{
movingSources.forEach( source -> source.setFixedTransform( movingSourcesToInitialTransform.get( source ) ) );
}

// protected void applyTransformInPlace( AffineTransform3D affineTransform )
// {
// final AffineTransform3D newFixedTransform = movingSourcesToInitialTransform.copy();
// newFixedTransform.preConcatenate( affineTransform.copy() );
// movingSources.setFixedTransform( newFixedTransform );
// }

// Should be overwritten by child classes!
// protected void previewTransform()
// {
// previewTransform( new AffineTransform3D() );
// }

// protected void previewTransform( AffineTransform3D affineTransform3D, boolean preview )
// {
// getInfo().getMutableInput("previewTransformation", Boolean.class).setValue( this, preview );
// previewTransform( affineTransform3D );
// }


// protected void previewTransform( AffineTransform3D affineTransform3D )
// {
// if ( previewTransform )
// {
// // add alignmentTransform
// applyTransformInPlace( affineTransform3D );
// }
// else
// {
// // reset original transform
// applyTransformInPlace( new AffineTransform3D() );
// }
//
// bdvHandle.getViewerPanel().requestRepaint();
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import sc.fiji.bdvpg.scijava.command.BdvPlaygroundActionCommand;
import sc.fiji.bdvpg.services.ISourceAndConverterService;
import sc.fiji.bdvpg.services.SourceAndConverterServices;

import static org.embl.mobie.command.context.ConfigureSegmentRenderingCommand.AUTO;
import static org.embl.mobie.command.context.ConfigureSegmentRenderingCommand.USE_BELOW_RESOLUTION;
Expand All @@ -57,10 +55,10 @@ public class ConfigureImageRenderingCommand extends DynamicCommand implements Bd
@Parameter
protected ImageVolumeViewer volumeViewer;

@Parameter ( label = "Volume rendering", choices = { AUTO, USE_BELOW_RESOLUTION } )
@Parameter ( label = ConfigureSegmentRenderingCommand.VOLUME_RENDERING_RESOLUTION, choices = { AUTO, USE_BELOW_RESOLUTION } )
public String volumeRenderingMode = AUTO;

@Parameter ( label = "Volume rendering resolution", style="format:#0.000" )
@Parameter ( label = ConfigureSegmentRenderingCommand.FIXED_RESOLUTION, style="format:#0.000" )
public double voxelSpacing = 1.0;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,21 @@
@Plugin(type = BdvPlaygroundActionCommand.class, menuPath = CommandConstants.CONTEXT_MENU_ITEMS_ROOT + "Display>Configure Segment Rendering")
public class ConfigureSegmentRenderingCommand extends ConfigureLabelRenderingCommand
{

static { net.imagej.patcher.LegacyInjector.preinit(); }

public static final String VOLUME_RENDERING_RESOLUTION = "Volume rendering resolution";
public static final String FIXED_RESOLUTION = "Fixed resolution";
public static final String AUTO = "Automatic";
public static final String USE_BELOW_RESOLUTION = "Use below resolution";
public static final String USE_BELOW_RESOLUTION = "Use below fixed resolution";

@Parameter
protected SegmentVolumeViewer< ? > volumeViewer;

@Parameter ( label = "Volume rendering", choices = { AUTO, USE_BELOW_RESOLUTION } )
@Parameter ( label = VOLUME_RENDERING_RESOLUTION, choices = { AUTO, USE_BELOW_RESOLUTION } )
public String volumeRenderingMode = AUTO;

@Parameter ( label = "Volume rendering resolution", style="format:#0.000" )
@Parameter ( label = FIXED_RESOLUTION, style="format:#0.000" )
public double voxelSpacing = 1.0;

@Override
Expand Down
72 changes: 16 additions & 56 deletions src/main/java/org/embl/mobie/ui/UserInterfaceHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
import org.embl.mobie.lib.volume.ImageVolumeViewer;
import org.embl.mobie.lib.volume.SegmentVolumeViewer;
import org.jetbrains.annotations.NotNull;
import org.scijava.plugin.Parameter;
import sc.fiji.bdvpg.services.ISourceAndConverterService;
import sc.fiji.bdvpg.services.SourceAndConverterServices;
import sc.fiji.bdvpg.sourceandconverter.display.ColorChanger;
Expand Down Expand Up @@ -410,52 +409,7 @@ public static JFrame showContrastLimitsDialog(
return frame;
}

public static void showOpacityDialog(
String name,
List< ? extends SourceAndConverter< ? > > sourceAndConverters,
BdvHandle bdvHandle )
{
JFrame frame = new JFrame( name );
frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
JPanel panel = new JPanel();
panel.setLayout( new BoxLayout( panel, BoxLayout.PAGE_AXIS ) );

// TODO: This cast requires that the sourceAndConverter implements
// an OpacityAdjuster; how to do this more cleanly?
// Maybe we should rather operate on the coloring model that is
// wrapped in the converter?
final double current = ( ( OpacityAdjuster ) sourceAndConverters.get( 0 ).getConverter()).getOpacity();

final BoundedValueDouble selection =
new BoundedValueDouble(
0.0,
1.0,
current );

double spinnerStepSize = 0.05;

final SliderPanelDouble opacitySlider = new SliderPanelDouble( "Opacity", selection, spinnerStepSize );
opacitySlider.setNumColummns( 3 );
opacitySlider.setDecimalFormat( "#.##" );

final OpacityUpdateListener opacityUpdateListener =
new OpacityUpdateListener( selection, opacitySlider, sourceAndConverters, bdvHandle );

selection.setUpdateListener( opacityUpdateListener );
panel.add( opacitySlider );

frame.setContentPane( panel );

//Display the window.
frame.setBounds( MouseInfo.getPointerInfo().getLocation().x,
MouseInfo.getPointerInfo().getLocation().y,
120, 10);
frame.setResizable( false );
frame.pack();
frame.setVisible( true );
}

public static JFrame showOpacityAndContrastLimitsDialog(
public static JFrame showContrastDialog(
String name,
List< ? extends SourceAndConverter< ? > > sacs,
BdvHandle bdvHandle,
Expand Down Expand Up @@ -505,27 +459,31 @@ public static JFrame showOpacityAndContrastLimitsDialog(

double spinnerStepSize = absCurrentRange / 100.0;

// TODO: adapt the number of decimal places to the current range
String decimalFormat = "#####.####";

final SliderPanelDouble minSlider =
new SliderPanelDouble( "Min", min, spinnerStepSize );
minSlider.setNumColummns( 10 );

// TODO: adapt the number of decimal places to the current range
minSlider.setDecimalFormat( "#####.####" );
minSlider.setDecimalFormat( decimalFormat );

final SliderPanelDouble maxSlider =
new SliderPanelDouble( "Max", max, spinnerStepSize );
maxSlider.setNumColummns( 10 );
maxSlider.setDecimalFormat( "#####.####" );
//maxSlider.setDecimalFormat( "####E0" );
maxSlider.setDecimalFormat( decimalFormat );

final BrightnessUpdateListener brightnessUpdateListener = new BrightnessUpdateListener( min, max, minSlider, maxSlider, converterSetups );

min.setUpdateListener( brightnessUpdateListener );
max.setUpdateListener( brightnessUpdateListener );

panel.add( minSlider );
panel.add( maxSlider );
JPanel minPanel = SwingHelper.horizontalLayoutPanel();
minPanel.add( minSlider );
panel.add( minPanel );

JPanel maxPanel = SwingHelper.horizontalLayoutPanel();
maxPanel.add( maxSlider );
panel.add( maxPanel );

JButton autoButton = new JButton("Auto Contrast");
autoButton.addActionListener( e ->
Expand Down Expand Up @@ -610,7 +568,9 @@ public static JFrame showOpacityAndContrastLimitsDialog(
new OpacityUpdateListener( selection, opacitySlider, sacs, bdvHandle );

selection.setUpdateListener( opacityUpdateListener );
panel.add( opacitySlider );
JPanel opacityPanel = SwingHelper.horizontalLayoutPanel();
opacityPanel.add( opacitySlider );
panel.add( opacityPanel );

//Display the window.
frame.setContentPane( panel );
Expand Down Expand Up @@ -1303,7 +1263,7 @@ public static JButton createContrastButton(

button.addActionListener( e ->
{
JFrame jFrame = showOpacityAndContrastLimitsDialog(
JFrame jFrame = showContrastDialog(
name,
sourceAndConverters,
bdvHandle,
Expand Down
Loading

0 comments on commit 132503f

Please sign in to comment.