Skip to content

Commit

Permalink
Effectively don't use Display.sourceAndConverters() anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Jun 19, 2024
1 parent 3145a99 commit 1ab1dbc
Show file tree
Hide file tree
Showing 20 changed files with 489 additions and 78 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<groupId>org.embl.mobie</groupId>
<artifactId>mobie-viewer-fiji</artifactId>
<version>5.0.6</version>
<version>5.0.7</version>

<!-- force javadoc generation to fetch errors: -->
<!-- mvn javadoc:javadoc | grep error -->
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/embl/mobie/MoBIE.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private void openImagesAndLabels( List< ImageFileSources > images, List< LabelFi

new FileSourcesDataSetter( images, labels, regionTable ).addDataAndDisplaysAndViews( dataset );

initUIandShowView( null ); //dataset.views().keySet().iterator().next() );
initUiAndShowView( null ); //dataset.views().keySet().iterator().next() );
}

public MoBIE( String projectName, ImageData< ? > imageData, ImageData< ? > labelData, @Nullable StorageLocation tableStorageLocation, @Nullable TableDataFormat tableDataFormat )
Expand All @@ -230,7 +230,7 @@ public MoBIE( String projectName, ImageData< ? > imageData, ImageData< ? > label
tableStorageLocation,
tableDataFormat ).addData( dataset, settings );

initUIandShowView( null );
initUiAndShowView( null );
}

private void initImageJAndMoBIE()
Expand Down Expand Up @@ -260,10 +260,10 @@ private void openHCSDataset( double wellMargin, double siteMargin, @Nullable Vox
initProject( "HCS" );
final Plate plate = new Plate( projectLocation, voxelDimensions );
new HCSPlateAdder( plate, wellMargin, siteMargin ).addPlateToDataset( dataset );
initUIandShowView( dataset.views().keySet().iterator().next() );
initUiAndShowView( dataset.views().keySet().iterator().next() );
}

private void initUIandShowView( @Nullable String view )
private void initUiAndShowView( @Nullable String view )
{
buildUI();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void run()
IJ.log( "Voxel size: " + Arrays.toString( source.getVoxelDimensions().dimensionsAsDoubleArray() ) );

Image< ? > image = DataStore.sourceToImage().get( sac );
ArrayList< Transformation > transformations = TransformHelper.fetchAllTransformations( image );
ArrayList< Transformation > transformations = TransformHelper.fetchAllImageTransformations( image );

transformations.forEach( transformation ->
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public void close( boolean closeImgLoader )
moBIE.closeSourceAndConverter( sourceAndConverter, closeImgLoader );
}
display.images().clear();
display.sourceAndConverters().clear();

sliceViewer.updateTimepointSlider();
}
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/org/embl/mobie/lib/bdv/view/SliceViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import bdv.util.BdvHandle;
import bdv.viewer.SourceAndConverter;
import ij.IJ;
import net.imglib2.realtransform.AffineTransform3D;
import org.embl.mobie.DataStore;
import org.embl.mobie.command.context.*;
Expand Down Expand Up @@ -205,7 +206,12 @@ public static BdvHandle createBdv( boolean is2D, String frameTitle )
final MobieSerializableBdvOptions sOptions = new MobieSerializableBdvOptions();
sOptions.is2D = is2D;
sOptions.frameTitle = frameTitle;
sOptions.interpolate = !is2D;
sOptions.interpolate = false;
IJ.log("BigDataViewer (BDV) initialised.");
IJ.log("BDV navigation mode: " + ( is2D ? "2D" : "3D" ));
IJ.log("BDV interpolation: Nearest neighbour (Press \"I\" in BDV window to change this)" );
IJ.log("" );

IBdvSupplier bdvSupplier = new MobieBdvSupplier( sOptions );
//SourceAndConverterServices.getBdvDisplayService().setDefaultBdvSupplier( bdvSupplier );
//BdvHandle bdvHandle = SourceAndConverterServices.getBdvDisplayService().getNewBdv();
Expand All @@ -217,13 +223,12 @@ public Window getWindow()
return SwingUtilities.getWindowAncestor( bdvHandle.getViewerPanel() );
}

public void show( Image< ? > image, SourceAndConverter< ? > sourceAndConverter, AbstractDisplay display )
public void show( Image< ? > image, SourceAndConverter< ? > sourceAndConverter, AbstractDisplay< ? > display )
{
// register
// register sac
SourceAndConverterServices.getSourceAndConverterService().register( sourceAndConverter );
display.sourceAndConverters().add( sourceAndConverter );

// link to image
// link sac to image
DataStore.sourceToImage().forcePut( sourceAndConverter, image );

// blending mode
Expand All @@ -248,7 +253,7 @@ public void updateTimepointSlider()
if ( bdvHandle.getViewerPanel().state() == null ) return;

final List< SourceAndConverter< ? > > sacs = bdvHandle.getViewerPanel().state().getSources();
if ( sacs.size() == 0 ) return;
if ( sacs.isEmpty() ) return;

int maxNumTimePoints = 1;
for ( SourceAndConverter< ? > sac : sacs )
Expand All @@ -257,8 +262,8 @@ public void updateTimepointSlider()
if ( image instanceof RegionAnnotationImage )
continue; // https://github.com/mobie/mobie-viewer-fiji/issues/975

int numTimepoints = SourceHelper.getNumTimePoints( sac.getSpimSource() );
if ( numTimepoints > maxNumTimePoints ) maxNumTimePoints = numTimepoints;
int numTimePoints = SourceHelper.getNumTimePoints( sac.getSpimSource() );
if ( numTimePoints > maxNumTimePoints ) maxNumTimePoints = numTimePoints;
}
bdvHandle.getViewerPanel().state().setNumTimepoints( maxNumTimePoints );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@
package org.embl.mobie.lib.serialize.display;

import bdv.viewer.SourceAndConverter;
import org.embl.mobie.DataStore;
import org.embl.mobie.lib.bdv.blend.BlendingMode;
import org.embl.mobie.lib.bdv.view.SliceViewer;
import org.embl.mobie.lib.image.Image;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public abstract class AbstractDisplay< T > implements Display< T >
{
Expand All @@ -45,8 +48,7 @@ public abstract class AbstractDisplay< T > implements Display< T >
protected BlendingMode blendingMode; // Do not set default to avoid serialisation for AnnotationDisplays

// Runtime
private transient List< Image< T > > images = new ArrayList<>();
private transient List< SourceAndConverter< T > > sourceAndConverters = new ArrayList<>();
private final transient List< Image< T > > images = new ArrayList<>();
public transient SliceViewer sliceViewer;

@Override
Expand Down Expand Up @@ -79,7 +81,9 @@ public List< Image< T > > images()
@Override
public List< SourceAndConverter< T > > sourceAndConverters()
{
return sourceAndConverters;
return Collections.unmodifiableList( ( List ) images.stream()
.map( image -> DataStore.sourceToImage().inverse().get( image ) )
.collect( Collectors.toList() ) );
}

public void setOpacity( double opacity )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* with shared display settings.
*
* Currently, everything that we display in MoBIE
* is a display. This implies that it must be
* is a Display. This implies that it must be
* modelled as an Image, which essentially is a Source.
* This is in line with BDV, which internally also
* models everything as a Source.
Expand All @@ -58,6 +58,8 @@ public interface Display< T >
BlendingMode getBlendingMode();
double getOpacity();
boolean isVisible();

// TODO: https://github.com/mobie/mobie-viewer-fiji/issues/1162
List< Image< T > > images();
List< SourceAndConverter< T > > sourceAndConverters();
}
36 changes: 19 additions & 17 deletions src/main/java/org/embl/mobie/lib/transform/TransformHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ else if ( numDimensions == 3 )
}
}

public static ArrayList< Transformation > fetchAllTransformations( Image< ? > image )
public static ArrayList< Transformation > fetchAllImageTransformations( Image< ? > image )
{
ArrayList< Transformation > transformations = new ArrayList<>();
collectTransformations( image, transformations );
Expand Down Expand Up @@ -419,14 +419,14 @@ private static void collectTransformations( Image< ? > image, Collection< Transf
}


@Deprecated // use fetchAllTransformations( Image< ? > image ) instead
public static ArrayList< Transformation > fetchAllTransformations( Source< ? > source )
{
ArrayList< Transformation > transformations = new ArrayList<>();
collectTransformations( source, transformations );
Collections.reverse( transformations ); // first transformation first
return transformations;
}
// @Deprecated // use fetchAllTransformations( Image< ? > image ) instead
// public static ArrayList< Transformation > fetchAllSourceTransformations( Source< ? > source )
// {
// ArrayList< Transformation > transformations = new ArrayList<>();
// collectTransformations( source, transformations );
// Collections.reverse( transformations ); // first transformation first
// return transformations;
// }

private static void collectTransformations( Source< ? > source, Collection< Transformation > transformations )
{
Expand Down Expand Up @@ -487,19 +487,21 @@ else if ( source instanceof RealTransformedSource )
}
}

public static ArrayList< Transformation > fetchAddedTransformations( Image< ? > image )
public static ArrayList< Transformation > fetchAddedImageTransformations( Image< ? > image )
{
ArrayList< Transformation > allTransformations = fetchAllTransformations( image );
ArrayList< Transformation > allTransformations = fetchAllImageTransformations( image );
allTransformations.remove( 0 ); // in MoBIE this is part of the raw image itself
return allTransformations;
}

public static ArrayList< Transformation > fetchAddedTransformations( Source< ? > source )
{
ArrayList< Transformation > allTransformations = fetchAllTransformations( source );
allTransformations.remove( 0 ); // in MoBIE this is part of the raw image itself
return allTransformations;
}
// @Deprecated
// public static ArrayList< Transformation > fetchAddedSourceTransformations( Source< ? > source )
// {
// ArrayList< Transformation > allTransformations = fetchAllSourceTransformations( source );
// if ( ! allTransformations.isEmpty() )
// allTransformations.remove( 0 ); // in MoBIE this is part of the raw image itself
// return allTransformations;
// }

// Wrap the input sourcePair into new TransformedSources,
// because otherwise, if the incremental transformations of the input TransformedSources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import net.imglib2.RealInterval;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.util.LinAlgHelpers;
import org.embl.mobie.DataStore;
import org.embl.mobie.lib.serialize.display.Display;
import org.embl.mobie.lib.transform.TransformHelper;

Expand All @@ -48,6 +49,7 @@ public class MoBIEViewerTransformAdjuster {

public MoBIEViewerTransformAdjuster( BdvHandle bdvHandle, Display< ? > display) {
this.bdvHandle = bdvHandle;
// TODO: It may be better to use display.images() here instead, but not sure
this.sources = display.sourceAndConverters().stream().map( sac -> sac.getSpimSource() ).collect( Collectors.toList() );
}

Expand Down
73 changes: 37 additions & 36 deletions src/main/java/org/embl/mobie/lib/view/ViewManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static View createTransformedImageView(
Transformation transformation,
String viewDescription )
{
ArrayList< Transformation > transformations = TransformHelper.fetchAddedTransformations( image );
ArrayList< Transformation > transformations = TransformHelper.fetchAddedImageTransformations( image );
transformations.add( transformation );

Display< ? > display;
Expand Down Expand Up @@ -138,34 +138,34 @@ public static View createTransformedImageView(
return view;
}

@Deprecated // use createTransformedImageView instead
public static void createTransformedSourceView(
SourceAndConverter< ? > sac,
String imageName,
Transformation transformation,
String viewDescription )
{
// TODO: Use TransformHelper.fetchAddedTransformations( Image<?> image ) instead
// TODO: Make this work for label images https://github.com/mobie/mobie-viewer-fiji/issues/1126
ArrayList< Transformation > transformations = TransformHelper.fetchAddedTransformations( sac.getSpimSource() );
transformations.add( transformation );

ImageDisplay< ? > imageDisplay = new ImageDisplay<>( imageName, imageName );
imageDisplay.setDisplaySettings( sac );

View view = new View(
imageName,
null, // to be determined by the user in below dialog
Collections.singletonList( imageDisplay ),
transformations,
null,
false,
viewDescription );

MoBIE.getInstance().getViewManager().getViewsSaver().saveViewDialog( view );

MoBIE.getInstance().getViewManager().show( view );
}
// @Deprecated // use createTransformedImageView instead
// public static void createTransformedSourceView(
// SourceAndConverter< ? > sac,
// String imageName,
// Transformation transformation,
// String viewDescription )
// {
// // TODO: Use TransformHelper.fetchAddedTransformations( Image<?> image ) instead
// // TODO: Make this work for label images https://github.com/mobie/mobie-viewer-fiji/issues/1126
// ArrayList< Transformation > transformations = TransformHelper.fetchAddedSourceTransformations( sac.getSpimSource() );
// transformations.add( transformation );
//
// ImageDisplay< ? > imageDisplay = new ImageDisplay<>( imageName, imageName );
// imageDisplay.setDisplaySettings( sac );
//
// View view = new View(
// imageName,
// null, // to be determined by the user in below dialog
// Collections.singletonList( imageDisplay ),
// transformations,
// null,
// false,
// viewDescription );
//
// MoBIE.getInstance().getViewManager().getViewsSaver().saveViewDialog( view );
//
// MoBIE.getInstance().getViewManager().show( view );
// }

private void initScatterPlotView( AbstractAnnotationDisplay< ? > display )
{
Expand Down Expand Up @@ -193,14 +193,14 @@ public SliceViewer getSliceViewer()

public ViewSaver getViewsSaver() { return viewSaver; }

private void addImageTransforms( List< Transformation > transformations, List< ? extends SourceAndConverter< ? >> sourceAndConverters )
private void addImageTransforms( List< Transformation > transformations,
List< ? extends Image< ? > > images )
{
for ( SourceAndConverter< ? > sourceAndConverter : sourceAndConverters )
images.forEach( image ->
{
Source< ? > source = sourceAndConverter.getSpimSource();
ArrayList< Transformation > fetchedTransformations = TransformHelper.fetchAddedTransformations( source );
transformations.addAll( fetchedTransformations );
}
ArrayList< Transformation > imageTransformations = TransformHelper.fetchAddedImageTransformations( image );
transformations.addAll( imageTransformations );
});
}

public View createViewFromCurrentState()
Expand All @@ -221,7 +221,8 @@ else if ( display instanceof SpotDisplay )
else
throw new UnsupportedOperationException( "Serialisation of a " + display.getClass().getName() + " is not yet supported." );

addImageTransforms( transformations, display.sourceAndConverters() );

addImageTransforms( transformations, display.images() );
}

// the parameters that are null must be later set via the view's setter methods
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/embl/mobie/lib/view/save/ViewSaver.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ public boolean saveViewDialog( View view )
final GenericDialog gd = new GenericDialog("Save view " + ( view.getName() == null ? "" : view.getName()) );

gd.addChoice("Save to", new String[]{ FileLocation.CurrentProject.toString(), FileLocation.ExternalJSONFile.toString() }, saveToProjectOrFile );
gd.addFileField( "External JSON file", externalJsonPath, 70 );
gd.addFileField( "( External JSON file )", externalJsonPath, 70 );
gd.addMessage( "" );
if ( view.getName() == null )
gd.addStringField("View name", "my-new-view-name", 35 );
gd.addStringField( "View description", view.getDescription() != null ? view.getDescription() : "My view description....", 70 );
gd.addCheckbox("Make view exclusive", view.isExclusive() != null ? view.isExclusive() : false );
gd.addMessage( "" );
gd.addChoice("Selection group", getSelectionGroupChoices(), uiSelectionChoice );
gd.addStringField("New selection group", "my-new-group", 30 );
gd.addStringField("( New selection group )", "my-new-group", 30 );

gd.showDialog();

Expand Down
Loading

0 comments on commit 1ab1dbc

Please sign in to comment.