Skip to content

Commit

Permalink
Fixes #1174
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Jul 10, 2024
1 parent 6ab81ca commit 1b653d2
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@
import bdv.util.BdvHandle;
import bdv.viewer.SourceAndConverter;
import org.embl.mobie.command.CommandConstants;
import org.embl.mobie.lib.bdv.blend.BlendingMode;
import org.embl.mobie.lib.volume.ImageVolumeViewer;
import org.scijava.Initializable;
import org.scijava.command.DynamicCommand;
import org.scijava.module.MutableModuleItem;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import sc.fiji.bdvpg.scijava.command.BdvPlaygroundActionCommand;
Expand All @@ -50,20 +48,15 @@ public class ConfigureImageRenderingCommand extends DynamicCommand implements Bd
{
static { net.imagej.patcher.LegacyInjector.preinit(); }

protected static ISourceAndConverterService sourceAndConverterService = SourceAndConverterServices.getSourceAndConverterService();

@Parameter
protected BdvHandle bdvh;
protected BdvHandle bdvHandle;

@Parameter
protected SourceAndConverter< ? >[] sourceAndConverters;

@Parameter
protected ImageVolumeViewer volumeViewer;

@Parameter( label = "Blending mode", choices = { BlendingMode.SUM, BlendingMode.ALPHA }, persist = false )
String blendingMode = BlendingMode.SUM;

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

Expand All @@ -73,40 +66,15 @@ public class ConfigureImageRenderingCommand extends DynamicCommand implements Bd
@Override
public void initialize()
{
initBlendingModeItem();
}

private void initBlendingModeItem()
{
final MutableModuleItem< String > blendingModeItem = getInfo().getMutableInput("blendingMode", String.class );

for ( SourceAndConverter sourceAndConverter : sourceAndConverters )
{
final BlendingMode blendingMode = ( BlendingMode ) sourceAndConverterService.getMetadata( sourceAndConverter, BlendingMode.class.getName() );
final String toString = blendingMode.toString();
blendingModeItem.setValue( this, toString );
return;
}
}

@Override
public void run()
{
updateBlendingMode();

updateVolumeRendering();
}

private void updateBlendingMode()
{
for ( SourceAndConverter< ? > sourceAndConverter : sourceAndConverters )
{
final BlendingMode blendingMode = BlendingMode.valueOf( this.blendingMode );
SourceAndConverterServices.getSourceAndConverterService().setMetadata( sourceAndConverter, BlendingMode.class.getName(), blendingMode );
}
bdvh.getViewerPanel().requestRepaint();
}

private void updateVolumeRendering()
{
if ( volumeViewer == null ) return;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/embl/mobie/lib/bdv/ScreenShotMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void run( List< SourceAndConverter< ? > > sacs, double targetVoxelSpacing
screenshotDimensions,
blockSize );

IJ.log( ThreadHelper.getNumIoThreads() + " threads working on blocks of " + Arrays.toString( blockSize ) );
// IJ.log( ThreadHelper.getNumIoThreads() + " threads working on blocks of " + Arrays.toString( blockSize ) );
final long currentTimeMillis = System.currentTimeMillis();
for ( SourceAndConverter< ? > sac : sacs )
{
Expand Down
145 changes: 84 additions & 61 deletions src/main/java/org/embl/mobie/ui/UserInterfaceHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.embl.mobie.io.util.IOHelper;
import org.embl.mobie.MoBIE;
import org.embl.mobie.lib.bdv.AutoContrastAdjuster;
import org.embl.mobie.lib.bdv.blend.BlendingMode;
import org.embl.mobie.lib.io.FileLocation;
import org.embl.mobie.lib.MoBIEInfo;
import org.embl.mobie.lib.Services;
Expand All @@ -71,6 +72,8 @@
import org.embl.mobie.lib.transform.viewer.ViewerTransform;
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 @@ -458,37 +461,13 @@ public static JFrame showOpacityAndContrastLimitsDialog(
BdvHandle bdvHandle,
boolean addContrastLimitUI )
{
ISourceAndConverterService service = SourceAndConverterServices.getSourceAndConverterService();

JFrame frame = new JFrame( name );
frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
JPanel panel = new JPanel();
panel.setLayout( new BoxLayout( panel, BoxLayout.PAGE_AXIS ) );

ISourceAndConverterService service = SourceAndConverterServices.getSourceAndConverterService();

// Opacity Slider
//
// 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 ) sacs.get( 0 ).getConverter()).getOpacity();

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

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

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

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

if ( addContrastLimitUI )
{
// Contrast Limits
Expand Down Expand Up @@ -547,6 +526,7 @@ public static JFrame showOpacityAndContrastLimitsDialog(
panel.add( minSlider );
panel.add( maxSlider );


JButton autoButton = new JButton("Auto Contrast");
autoButton.addActionListener( e ->
{
Expand All @@ -555,7 +535,9 @@ public static JFrame showOpacityAndContrastLimitsDialog(
min.setCurrentValue( minMax[ 0 ] );
max.setCurrentValue( minMax[ 1 ] );
});
panel.add( autoButton );
JPanel autoPanel = SwingHelper.horizontalLayoutPanel();
autoPanel.add( autoButton );
panel.add( autoPanel );

boolean isInvert = false;
for ( Converter< ?, ARGBType > converter : converters )
Expand All @@ -580,9 +562,56 @@ public static JFrame showOpacityAndContrastLimitsDialog(
}
bdvHandle.getViewerPanel().requestRepaint();
} );
panel.add( invertCheckBox );
JPanel invertPanel = SwingHelper.horizontalLayoutPanel();
invertPanel.add( invertCheckBox );
panel.add( invertPanel );
panel.add( new JLabel("") ); // create some Luft
}

// Blending mode
JPanel blendingPanel = SwingHelper.horizontalLayoutPanel();
blendingPanel.add( new JLabel("Blending ") );
JComboBox< BlendingMode > blendingModeComboBox = new JComboBox<>(
new BlendingMode[]{ BlendingMode.Sum, BlendingMode.Alpha } );
BlendingMode currentBlendingMode = ( BlendingMode ) service.getMetadata( sacs.get( 0 ), BlendingMode.class.getName() );
blendingModeComboBox.setSelectedItem( currentBlendingMode );
blendingModeComboBox.addActionListener( e ->
{
for ( SourceAndConverter< ? > sourceAndConverter : sacs )
{
service.setMetadata( sourceAndConverter,
BlendingMode.class.getName(),
blendingModeComboBox.getSelectedItem() );
}
bdvHandle.getViewerPanel().requestRepaint();
} );
blendingPanel.add( blendingModeComboBox );
panel.add( blendingPanel );

// Opacity Slider
//
// 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 ) sacs.get( 0 ).getConverter()).getOpacity();

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

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

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

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

//Display the window.
frame.setContentPane( panel );
frame.setBounds( MouseInfo.getPointerInfo().getLocation().x,
Expand All @@ -604,7 +633,7 @@ public JPanel createRegionDisplaySettingsPanel( RegionDisplay display )
// Buttons
panel.add( space() );
panel.add( createFocusButton( display, display.sliceViewer.getBdvHandle(), sourceAndConverters.stream().map( sac -> sac.getSpimSource() ).collect( Collectors.toList() ) ) );
panel.add( createOpacityAndContrastLimitsButton( sourceAndConverters, display.getName(), display.sliceViewer.getBdvHandle(), false ) );
panel.add( createContrastButton( sourceAndConverters, display.getName(), display.sliceViewer.getBdvHandle(), false ) );
panel.add( createButtonPlaceholder() ); // color
panel.add( createLabelRenderingSettingsButton( sourceAndConverters ) ); // special settings
panel.add( createRemoveButton( display ) );
Expand All @@ -625,7 +654,7 @@ public JPanel createSpotDisplaySettingsPanel( SpotDisplay display )
// Buttons
panel.add( space() );
panel.add( createFocusButton( display, display.sliceViewer.getBdvHandle(), sourceAndConverters.stream().map( sac -> sac.getSpimSource() ).collect( Collectors.toList() ) ) );
panel.add( createOpacityAndContrastLimitsButton( sourceAndConverters, display.getName(), display.sliceViewer.getBdvHandle(), false ) );
panel.add( createContrastButton( sourceAndConverters, display.getName(), display.sliceViewer.getBdvHandle(), false ) );
panel.add( createButtonPlaceholder() ); // color
panel.add( createSpotSettingsButton( sourceAndConverters ) ); // special settings
panel.add( createRemoveButton( display ) );
Expand Down Expand Up @@ -712,7 +741,7 @@ public JPanel createImageDisplaySettingsPanel( ImageDisplay< ? > display )
// Buttons
panel.add( space() );
panel.add( createFocusButton( display, display.sliceViewer.getBdvHandle(), sourceAndConverters.stream().map( sac -> sac.getSpimSource() ).collect( Collectors.toList() ) ) );
panel.add( createOpacityAndContrastLimitsButton( sourceAndConverters, display.getName(), display.sliceViewer.getBdvHandle(), true ) );
panel.add( createContrastButton( sourceAndConverters, display.getName(), display.sliceViewer.getBdvHandle(), true ) );
panel.add( createColorButton( panel, sourceAndConverters, display.sliceViewer.getBdvHandle() ) );
//panel.add( createImageDisplayBrightnessButton( display ) );
panel.add( createImageRenderingSettingsButton( sourceAndConverters, display.imageVolumeViewer ) );
Expand Down Expand Up @@ -758,7 +787,7 @@ public JPanel createSegmentationDisplaySettingsPanel( SegmentationDisplay displa

panel.add( space() );
panel.add( createFocusButton( display, display.sliceViewer.getBdvHandle(), sourceAndConverters.stream().map( sac -> sac.getSpimSource() ).collect( Collectors.toList() ) ) );
panel.add( createOpacityAndContrastLimitsButton( sourceAndConverters, display.getName(), display.sliceViewer.getBdvHandle(), false ) );
panel.add( createContrastButton( sourceAndConverters, display.getName(), display.sliceViewer.getBdvHandle(), false ) );
panel.add( createButtonPlaceholder() );
panel.add( createSegmentRenderingSettingsButton( sourceAndConverters, display.segmentVolumeViewer ) );
panel.add( createRemoveButton( display ) );
Expand Down Expand Up @@ -787,10 +816,7 @@ public JPanel createSegmentationDisplaySettingsPanel( SegmentationDisplay displa

private JButton createImageRenderingSettingsButton( List< ? extends SourceAndConverter< ? > > sourceAndConverters, ImageVolumeViewer imageVolumeViewer )
{
final URL resource = UserInterfaceHelper.class.getResource( "/settings_19.png" );
final ImageIcon imageIcon = new ImageIcon( resource );
JButton button = new JButton( imageIcon );
button.setPreferredSize( PREFERRED_BUTTON_SIZE );
JButton button = getIconButton( "settings.png" );
button.addActionListener( e ->
{
SwingUtilities.invokeLater( () ->
Expand All @@ -807,15 +833,15 @@ private JButton createImageRenderingSettingsButton( List< ? extends SourceAndCon

private JButton createLabelRenderingSettingsButton( List< SourceAndConverter< ? > > sourceAndConverters )
{
JButton button = new JButton( "S" );
JButton button = getIconButton( "settings.png" );
button.setPreferredSize( PREFERRED_BUTTON_SIZE );
button.addActionListener( e -> Services.commandService.run( ConfigureLabelRenderingCommand.class, true, "sourceAndConverters", sourceAndConverters.toArray( new SourceAndConverter[ 0 ] ) ) );
return button;
}

private JButton createSegmentRenderingSettingsButton( List< SourceAndConverter< ? > > sourceAndConverters, SegmentVolumeViewer< ? > segmentVolumeViewer )
{
JButton button = new JButton( "S" );
JButton button = getIconButton( "settings.png" );
button.setPreferredSize( PREFERRED_BUTTON_SIZE );
button.addActionListener( e -> Services.commandService.run( ConfigureSegmentRenderingCommand.class, true, "sourceAndConverters", sourceAndConverters.toArray( new SourceAndConverter[ 0 ] ), "volumeViewer", segmentVolumeViewer ) );
return button;
Expand Down Expand Up @@ -1225,11 +1251,8 @@ public static JButton createFocusButton( AbstractDisplay< ? > sourceDisplay,
BdvHandle bdvHandle,
List< Source< ? > > sources )
{
final URL resource = UserInterfaceHelper.class.getResource( "/focus_19.png" );
final ImageIcon imageIcon = new ImageIcon( resource );
JButton button = new JButton( imageIcon );
JButton button = getIconButton( "focus.png" );
button.setToolTipText( "Show whole dataset" );
button.setPreferredSize( PREFERRED_BUTTON_SIZE );

button.addActionListener( e ->
{
Expand All @@ -1254,9 +1277,8 @@ public static JButton createFocusButton( AbstractDisplay< ? > sourceDisplay,

public static JButton createImageDisplayBrightnessButton( ImageDisplay< ? > imageDisplay )
{
JButton button = new JButton( "B" );
JButton button = getIconButton( "contrast.png" );
button.setToolTipText( "Change brightness/contrast" );
button.setPreferredSize( PREFERRED_BUTTON_SIZE );

button.addActionListener( e ->
{
Expand All @@ -1270,17 +1292,14 @@ public static JButton createImageDisplayBrightnessButton( ImageDisplay< ? > imag
return button;
}

public static JButton createOpacityAndContrastLimitsButton(
public static JButton createContrastButton(
List< ? extends SourceAndConverter< ? > > sourceAndConverters,
String name,
BdvHandle bdvHandle,
boolean addContrastLimitUI )
{
final URL resource = UserInterfaceHelper.class.getResource( "/contrast_19.png" );
final ImageIcon imageIcon = new ImageIcon( resource );
JButton button = new JButton( imageIcon );
JButton button = getIconButton( "contrast.png" );
button.setToolTipText( "Change opacity and contrast limits" );
button.setPreferredSize( PREFERRED_BUTTON_SIZE );

button.addActionListener( e ->
{
Expand All @@ -1296,16 +1315,23 @@ public static JButton createOpacityAndContrastLimitsButton(
return button;
}

private static JButton createColorButton( JPanel parentPanel, List< ? extends SourceAndConverter< ? > > sourceAndConverters, BdvHandle bdvHandle )
@NotNull
private static JButton getIconButton( final String iconResource )
{
final URL resource = UserInterfaceHelper.class.getResource( "/color_19.png" );
final ImageIcon imageIcon = new ImageIcon( resource );
JButton colorButton = new JButton( imageIcon );
colorButton.setToolTipText( "Change color" );
final URL resource = UserInterfaceHelper.class.getResource( "/" + iconResource );
Image scaledInstance = new ImageIcon( resource ).getImage().getScaledInstance( 19, 19, Image.SCALE_SMOOTH );
ImageIcon imageIcon = new ImageIcon( scaledInstance );
JButton button = new JButton( imageIcon );
button.setPreferredSize( PREFERRED_BUTTON_SIZE);
return button;
}

colorButton.setPreferredSize( PREFERRED_BUTTON_SIZE);
private static JButton createColorButton( JPanel parentPanel, List< ? extends SourceAndConverter< ? > > sourceAndConverters, BdvHandle bdvHandle )
{
JButton button = getIconButton( "color.png" );
button.setToolTipText( "Change color" );

colorButton.addActionListener( e ->
button.addActionListener( e ->
{
Color color = JColorChooser.showDialog( null, "", null );
if ( color == null ) return;
Expand All @@ -1320,7 +1346,7 @@ private static JButton createColorButton( JPanel parentPanel, List< ? extends So
bdvHandle.getViewerPanel().requestRepaint();
} );

return colorButton;
return button;
}

private void setPanelColor( JPanel panel, ARGBType argbType )
Expand All @@ -1345,11 +1371,8 @@ private void setPanelColor( JPanel panel, String colorString )

private JButton createRemoveButton( Display display )
{
final URL resource = UserInterfaceHelper.class.getResource( "/delete_19.png" );
final ImageIcon imageIcon = new ImageIcon( resource );
JButton button = new JButton( imageIcon );
JButton button = getIconButton( "delete.png" );
button.setToolTipText( "Remove dataset" );
button.setPreferredSize( PREFERRED_BUTTON_SIZE );

button.addActionListener( e ->
{
Expand Down
Binary file added src/main/resources/color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/main/resources/color_19.png
Binary file not shown.
Binary file added src/main/resources/contrast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/main/resources/contrast_19.png
Binary file not shown.
Binary file removed src/main/resources/contrast_20.png
Binary file not shown.
Binary file removed src/main/resources/contrast_24.png
Binary file not shown.
Binary file removed src/main/resources/contrast_30.png
Binary file not shown.
Binary file added src/main/resources/delete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/main/resources/delete_19.png
Binary file not shown.
Binary file added src/main/resources/focus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/main/resources/focus_19.png
Binary file not shown.
Binary file added src/main/resources/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/main/resources/settings_19.png
Binary file not shown.

0 comments on commit 1b653d2

Please sign in to comment.