diff --git a/src/main/java/org/embl/mobie/MoBIESettings.java b/src/main/java/org/embl/mobie/MoBIESettings.java index ca841b909..692cd458e 100644 --- a/src/main/java/org/embl/mobie/MoBIESettings.java +++ b/src/main/java/org/embl/mobie/MoBIESettings.java @@ -107,12 +107,19 @@ public MoBIESettings removeSpatialCalibration( Boolean removeSpatialCalibration return this; } + public MoBIESettings appendGroovyCode( String groovyCode ) + { + this.values.groovyScript += groovyCode; + return this; + } + public MoBIESettings openedFromCLI( Boolean cli ) { this.values.openedFromCLI = cli; return this; } + public static class Values { private String[] s3AccessAndSecretKey; @@ -126,6 +133,7 @@ public static class Values private String view = View.DEFAULT; private Boolean removeSpatialCalibration = false; private Boolean openedFromCLI = false; // started from CLI + private String groovyScript = ""; public Boolean getRemoveSpatialCalibration() { @@ -186,5 +194,10 @@ public Boolean isOpenedFromCLI() { return openedFromCLI; } + + public String getGroovyScript() + { + return groovyScript; + } } } diff --git a/src/main/java/org/embl/mobie/command/open/OpenMultipleImagesAndLabelsCommand.java b/src/main/java/org/embl/mobie/command/open/OpenMultipleImagesAndLabelsCommand.java index 222ed54ee..ae2123771 100644 --- a/src/main/java/org/embl/mobie/command/open/OpenMultipleImagesAndLabelsCommand.java +++ b/src/main/java/org/embl/mobie/command/open/OpenMultipleImagesAndLabelsCommand.java @@ -93,6 +93,9 @@ public void run() final MoBIESettings settings = new MoBIESettings(); settings.removeSpatialCalibration( removeSpatialCalibration ); + String groovyCode = generateGroovyScript(); + settings.appendGroovyCode( groovyCode ); +// System.out.println( groovyCode ); try { @@ -100,7 +103,43 @@ public void run() } catch ( IOException e ) { - e.printStackTrace(); + throw new RuntimeException( e ); } } + + public String generateGroovyScript() { + StringBuilder sb = new StringBuilder(); + + sb.append("import org.embl.mobie.command.open.OpenMultipleImagesAndLabelsCommand\n"); + sb.append("import java.io.File\n\n"); + + sb.append("OpenMultipleImagesAndLabelsCommand command = new OpenMultipleImagesAndLabelsCommand()\n"); + + if (image0 != null) sb.append(String.format("command.image0 = new File(\"%s\")\n", + image0.getAbsolutePath())); + if (image1 != null) sb.append(String.format("command.image1 = new File(\"%s\")\n", + image1.getAbsolutePath())); + if (image2 != null) sb.append(String.format("command.image2 = new File(\"%s\")\n", + image2.getAbsolutePath())); + if (image3 != null) sb.append(String.format("command.image3 = new File(\"%s\")\n", + image3.getAbsolutePath())); + + if (labels0 != null) sb.append(String.format("command.labels0 = new File(\"%s\")\n", + labels0.getAbsolutePath())); + if (labels1 != null) sb.append(String.format("command.labels1 = new File(\"%s\")\n", + labels1.getAbsolutePath())); + + if (table0 != null) sb.append(String.format("command.table0 = new File(\"%s\")\n", + table0.getAbsolutePath())); + if (table1 != null) sb.append(String.format("command.table1 = new File(\"%s\")\n", + table1.getAbsolutePath())); + + if (removeSpatialCalibration != null) { + sb.append("command.removeSpatialCalibration = ").append(removeSpatialCalibration).append("\n"); + } + + sb.append("\ncommand.run()\n"); + + return sb.toString(); + } } diff --git a/src/main/java/org/embl/mobie/command/view/ViewerTransformLoggerCommand.java b/src/main/java/org/embl/mobie/command/view/ViewerTransformLoggerCommand.java index edbb74e4e..ba8cb0463 100644 --- a/src/main/java/org/embl/mobie/command/view/ViewerTransformLoggerCommand.java +++ b/src/main/java/org/embl/mobie/command/view/ViewerTransformLoggerCommand.java @@ -39,7 +39,6 @@ import org.embl.mobie.lib.transform.viewer.NormalVectorViewerTransform; import org.embl.mobie.lib.transform.NormalizedAffineViewerTransform; import org.embl.mobie.lib.transform.viewer.PositionViewerTransform; -import org.embl.mobie.lib.transform.TransformHelper; import net.imglib2.realtransform.AffineTransform3D; import org.scijava.plugin.Parameter; import org.scijava.plugin.Plugin; @@ -53,30 +52,29 @@ public class ViewerTransformLoggerCommand implements BdvPlaygroundActionCommand public static final String NAME = "Log Current Location"; @Parameter - BdvHandle bdv; + BdvHandle bdvHandle; @Override public void run() { new Thread( () -> { - final int timepoint = bdv.getViewerPanel().state().getCurrentTimepoint(); - final double[] position = BdvPlaygroundHelper.getWindowCentreInCalibratedUnits( bdv ); + final int timepoint = bdvHandle.getViewerPanel().state().getCurrentTimepoint(); + final double[] position = BdvPlaygroundHelper.getWindowCentreInCalibratedUnits( bdvHandle ); // position final PositionViewerTransform positionViewerTransform = new PositionViewerTransform( position, timepoint ); // affine final AffineTransform3D affineTransform3D = new AffineTransform3D(); - bdv.getViewerPanel().state().getViewerTransform( affineTransform3D ); + bdvHandle.getViewerPanel().state().getViewerTransform( affineTransform3D ); final AffineViewerTransform affineViewerTransform = new AffineViewerTransform( affineTransform3D.getRowPackedCopy(), timepoint ); // normalized affine - final AffineTransform3D normalisedViewerTransform = TransformHelper.createNormalisedViewerTransform( bdv.getViewerPanel() ); - final NormalizedAffineViewerTransform normalizedAffineViewerTransform = new NormalizedAffineViewerTransform( normalisedViewerTransform.getRowPackedCopy(), timepoint ); + final NormalizedAffineViewerTransform normalizedAffineViewerTransform = new NormalizedAffineViewerTransform( bdvHandle ); // normal vector - double[] currentNormalVector = BdvUtils.getCurrentViewNormalVector( bdv ); + double[] currentNormalVector = BdvUtils.getCurrentViewNormalVector( bdvHandle ); final NormalVectorViewerTransform normalVectorViewerTransform = new NormalVectorViewerTransform( currentNormalVector, timepoint ); // print diff --git a/src/main/java/org/embl/mobie/lib/SpimDataAdder.java b/src/main/java/org/embl/mobie/lib/SpimDataAdder.java index 474a60e3b..73edc340c 100644 --- a/src/main/java/org/embl/mobie/lib/SpimDataAdder.java +++ b/src/main/java/org/embl/mobie/lib/SpimDataAdder.java @@ -143,7 +143,7 @@ private void addImageView( AbstractSpimData< ? > spimData, int imageIndex, Strin } final ImageDisplay< ? > imageDisplay = new ImageDisplay<>( imageName, Arrays.asList( imageName ), color, contrastLimits ); - final View view = new View( imageName, "images", Arrays.asList( imageDisplay ), null, false ); + final View view = new View( imageName, "images", Arrays.asList( imageDisplay ), null, null, false, null ); dataset.views().put( view.getName(), view ); } @@ -155,7 +155,7 @@ private void addSegmentationView( AbstractSpimData< ? > spimData, int setupId, S final double pixelWidth = viewSetup.getVoxelSize().dimension( 0 ); display.setResolution3dView( new Double[]{ pixelWidth, pixelWidth, pixelWidth } ); - final View view = new View( name, "segmentations", Arrays.asList( display ), null, false ); + final View view = new View( name, "segmentations", Arrays.asList( display ), null, null, false, null ); dataset.views().put( view.getName(), view ); } diff --git a/src/main/java/org/embl/mobie/lib/create/DatasetJsonCreator.java b/src/main/java/org/embl/mobie/lib/create/DatasetSerializer.java similarity index 92% rename from src/main/java/org/embl/mobie/lib/create/DatasetJsonCreator.java rename to src/main/java/org/embl/mobie/lib/create/DatasetSerializer.java index bf311d019..38b4f04ac 100644 --- a/src/main/java/org/embl/mobie/lib/create/DatasetJsonCreator.java +++ b/src/main/java/org/embl/mobie/lib/create/DatasetSerializer.java @@ -57,7 +57,8 @@ /** * Class to create and modify the metadata stored in dataset Json files */ -public class DatasetJsonCreator { +public class DatasetSerializer +{ ProjectCreator projectCreator; @@ -66,7 +67,7 @@ public class DatasetJsonCreator { * stored in dataset Json files * @param projectCreator projectCreator */ - public DatasetJsonCreator( ProjectCreator projectCreator ) { + public DatasetSerializer( ProjectCreator projectCreator ) { this.projectCreator = projectCreator; } @@ -94,9 +95,15 @@ public void addDataset( String datasetName, boolean is2D ) { * images from the viewer? * @param sourceTransform affine transform of image view */ - public void addImage(String imageName, String datasetName, + public void addImage(String imageName, + String datasetName, String uiSelectionGroup, - ImageDataFormat imageDataFormat, double[] contrastLimits, String colour, boolean exclusive, AffineTransform3D sourceTransform ) { + ImageDataFormat imageDataFormat, + double[] contrastLimits, + String colour, + boolean exclusive, + AffineTransform3D sourceTransform ) + { Dataset dataset = fetchDataset( datasetName ); addNewImageSource( dataset, imageName, imageDataFormat ); @@ -146,7 +153,8 @@ public void addSegmentation(String imageName, String datasetName, String uiSelec * @param datasetName dataset name * @param is2D whether dataset only contains 2D images */ - public void makeDataset2D( String datasetName, boolean is2D ) { + public void makeDataset2D( String datasetName, boolean is2D ) + { Dataset dataset = projectCreator.getDataset( datasetName ); dataset.is2D( is2D ); writeDatasetJson( datasetName, dataset ); @@ -158,7 +166,8 @@ private Dataset fetchDataset( String datasetName ) return dataset; } - private void addNewImageSource( Dataset dataset, String imageName, ImageDataFormat imageDataFormat ) { + private void addNewImageSource( Dataset dataset, String imageName, ImageDataFormat imageDataFormat ) + { Map< ImageDataFormat, StorageLocation > imageDataLocations; ImageDataSource imageSource = new ImageDataSource(); imageDataLocations = makeImageDataLocations( imageDataFormat, imageName ); @@ -166,7 +175,8 @@ private void addNewImageSource( Dataset dataset, String imageName, ImageDataForm dataset.sources().put( imageName, imageSource ); } - private void addNewSegmentationSource( Dataset dataset, String imageName, ImageDataFormat imageDataFormat ) { + private void addNewSegmentationSource( Dataset dataset, String imageName, ImageDataFormat imageDataFormat ) + { Map< ImageDataFormat, StorageLocation > imageDataLocations; SegmentationDataSource annotatedLabelMaskSource = new SegmentationDataSource(); @@ -182,7 +192,8 @@ private void addNewSegmentationSource( Dataset dataset, String imageName, ImageD } private Map< ImageDataFormat, StorageLocation > makeImageDataLocations( ImageDataFormat imageDataFormat, - String imageName ) { + String imageName ) + { Map< ImageDataFormat, StorageLocation > imageDataLocations = new HashMap<>(); StorageLocation imageStorageLocation = new StorageLocation(); if ( imageDataFormat == ImageDataFormat.OmeZarr ) { @@ -199,29 +210,34 @@ private Map< ImageDataFormat, StorageLocation > makeImageDataLocations( ImageDat private void addNewImageView( Dataset dataset, String imageName, String uiSelectionGroup, double[] contrastLimits, String colour, boolean exclusive, - AffineTransform3D sourceTransform ) { + AffineTransform3D sourceTransform ) + { View view = createImageView( imageName, uiSelectionGroup, exclusive, contrastLimits, colour, sourceTransform ); dataset.views().put( imageName, view ); } - private void addNewSegmentationView( Dataset dataset, String imageName, String uiSelectionGroup, boolean exclusive, AffineTransform3D sourceTransform ) { + private void addNewSegmentationView( Dataset dataset, String imageName, String uiSelectionGroup, boolean exclusive, AffineTransform3D sourceTransform ) + { View view = createSegmentationView( imageName, uiSelectionGroup, exclusive, sourceTransform ); dataset.views().put( imageName, view ); } private void addNewDefaultImageView( Dataset dataset, String imageName, double[] contrastLimits, String colour, - AffineTransform3D sourceTransform ) { + AffineTransform3D sourceTransform ) + { View view = createImageView( imageName, "bookmark", true, contrastLimits, colour, sourceTransform ); dataset.views().put( View.DEFAULT, view ); } - private void addNewDefaultSegmentationView( Dataset dataset, String imageName, AffineTransform3D sourceTransform ) { + private void addNewDefaultSegmentationView( Dataset dataset, String imageName, AffineTransform3D sourceTransform ) + { View view = createSegmentationView( imageName, "bookmark", true, sourceTransform ); dataset.views().put( View.DEFAULT, view ); } - private List< Transformation > createSourceTransformerList( AffineTransform3D sourceTransform, List sources ) { + private List< Transformation > createSourceTransformerList( AffineTransform3D sourceTransform, List sources ) + { List< Transformation > imageTransformationList = new ArrayList<>(); Transformation imageTransformation = new AffineTransformation( "affine", sourceTransform.getRowPackedCopy(), sources ); imageTransformationList.add( imageTransformation ); @@ -239,16 +255,17 @@ private View createImageView( String imageName, String uiSelectionGroup, boolean View view; if ( sourceTransform.isIdentity() ) { - view = new View( imageName, uiSelectionGroup, displays, null, null, isExclusive); + view = new View( imageName, uiSelectionGroup, displays, null, null, isExclusive, null ); } else { List< Transformation > imageTransformationList = createSourceTransformerList( sourceTransform, sources ); - view = new View( imageName, uiSelectionGroup, displays, imageTransformationList, null, isExclusive ); + view = new View( imageName, uiSelectionGroup, displays, imageTransformationList, null, isExclusive, null ); } return view; } - private View createSegmentationView( String imageName, String uiSelectionGroup, boolean isExclusive, AffineTransform3D sourceTransform ) { + private View createSegmentationView( String imageName, String uiSelectionGroup, boolean isExclusive, AffineTransform3D sourceTransform ) + { ArrayList< Display< ? > > displays = new ArrayList<>(); ArrayList sources = new ArrayList<>(); sources.add( imageName ); @@ -257,10 +274,10 @@ private View createSegmentationView( String imageName, String uiSelectionGroup, displays.add( segmentationDisplay ); if ( sourceTransform.isIdentity() ) { - return new View( imageName, uiSelectionGroup, displays, null, null, isExclusive ); + return new View( imageName, uiSelectionGroup, displays, null, null, isExclusive, null ); } else { List< Transformation > imageTransformationList = createSourceTransformerList( sourceTransform, sources ); - return new View( imageName, uiSelectionGroup, displays, imageTransformationList, null, isExclusive ); + return new View( imageName, uiSelectionGroup, displays, imageTransformationList, null, isExclusive, null ); } } @@ -269,7 +286,8 @@ private View createSegmentationView( String imageName, String uiSelectionGroup, * @param datasetName dataset name * @param dataset dataset */ - public void writeDatasetJson ( String datasetName, Dataset dataset ) { + public void writeDatasetJson ( String datasetName, Dataset dataset ) + { try { String datasetJsonPath = IOHelper.combinePath( projectCreator.getProjectLocation().getAbsolutePath(), datasetName, "dataset.json" ); diff --git a/src/main/java/org/embl/mobie/lib/create/ImagesCreator.java b/src/main/java/org/embl/mobie/lib/create/ImagesCreator.java index ad26a5bad..af4338a33 100644 --- a/src/main/java/org/embl/mobie/lib/create/ImagesCreator.java +++ b/src/main/java/org/embl/mobie/lib/create/ImagesCreator.java @@ -34,7 +34,6 @@ import de.embl.cba.tables.Tables; import ij.IJ; import ij.ImagePlus; -import ij.gui.Overlay; import ij.process.LUT; import mpicbg.spim.data.SpimData; import mpicbg.spim.data.SpimDataException; @@ -645,15 +644,15 @@ private SpimData tryOpenSpimData( ImageDataFormat imageDataFormat, String filePa } private void updateTableAndJsonsForNewImage ( String imageName, String datasetName, String uiSelectionGroup, ImageDataFormat imageDataFormat, double[] contrastLimits, String colour, boolean exclusive, AffineTransform3D sourceTransform ) { - DatasetJsonCreator datasetJsonCreator = projectCreator.getDatasetJsonCreator(); - datasetJsonCreator.addImage( imageName, datasetName, uiSelectionGroup, + DatasetSerializer datasetSerializer = projectCreator.getDatasetJsonCreator(); + datasetSerializer.addImage( imageName, datasetName, uiSelectionGroup, imageDataFormat, contrastLimits, colour, exclusive, sourceTransform ); } private void updateTableAndJsonsForNewSegmentation( String imageName, String datasetName, String uiSelectionGroup, ImageDataFormat imageDataFormat, boolean exclusive, AffineTransform3D sourceTransform ) { addDefaultTableForImage( imageName, datasetName, imageDataFormat ); - DatasetJsonCreator datasetJsonCreator = projectCreator.getDatasetJsonCreator(); - datasetJsonCreator.addSegmentation( imageName, datasetName, uiSelectionGroup, imageDataFormat, exclusive, sourceTransform ); + DatasetSerializer datasetSerializer = projectCreator.getDatasetJsonCreator(); + datasetSerializer.addSegmentation( imageName, datasetName, uiSelectionGroup, imageDataFormat, exclusive, sourceTransform ); } private void copyImage ( ImageDataFormat imageFormat, SpimData spimData, diff --git a/src/main/java/org/embl/mobie/lib/create/ProjectCreator.java b/src/main/java/org/embl/mobie/lib/create/ProjectCreator.java index aac673569..305c432a8 100644 --- a/src/main/java/org/embl/mobie/lib/create/ProjectCreator.java +++ b/src/main/java/org/embl/mobie/lib/create/ProjectCreator.java @@ -68,7 +68,7 @@ public class ProjectCreator { private final DatasetsCreator datasetsCreator; private final ImagesCreator imagesCreator; - private final DatasetJsonCreator datasetJsonCreator; + private final DatasetSerializer datasetSerializer; private final ProjectJsonCreator projectJsonCreator; private final RemoteMetadataCreator remoteMetadataCreator; @@ -103,7 +103,7 @@ public ProjectCreator( File projectLocation ) throws IOException { } this.datasetsCreator = new DatasetsCreator( this ); - this.datasetJsonCreator = new DatasetJsonCreator( this ); + this.datasetSerializer = new DatasetSerializer( this ); this.projectJsonCreator = new ProjectJsonCreator( this ); this.imagesCreator = new ImagesCreator( this ); this.remoteMetadataCreator = new RemoteMetadataCreator( this ); @@ -216,8 +216,8 @@ public ImagesCreator getImagesCreator() { return imagesCreator; } - public DatasetJsonCreator getDatasetJsonCreator() { - return datasetJsonCreator; + public DatasetSerializer getDatasetJsonCreator() { + return datasetSerializer; } public ProjectJsonCreator getProjectJsonCreator() { return projectJsonCreator; } diff --git a/src/main/java/org/embl/mobie/lib/files/FileSourcesDataSetter.java b/src/main/java/org/embl/mobie/lib/files/FileSourcesDataSetter.java index 37f662dd1..78558898e 100644 --- a/src/main/java/org/embl/mobie/lib/files/FileSourcesDataSetter.java +++ b/src/main/java/org/embl/mobie/lib/files/FileSourcesDataSetter.java @@ -243,7 +243,7 @@ else if ( sources.getGridType().equals( GridType.Transformed ) ) // // FIXME: Maybe the viewerTransform could be something else? final ImageZoomViewerTransform viewerTransform = new ImageZoomViewerTransform( transformations.get( 0 ).getSources().get( 0 ), 0 ); - final View gridView = new View( "all images", "data", displays, transformations, viewerTransform, false ); + final View gridView = new View( "all images", "data", displays, transformations, viewerTransform, false, null ); //gridView.overlayNames( true ); // FIXME: Timepoint bug! dataset.views().put( gridView.getName(), gridView ); } diff --git a/src/main/java/org/embl/mobie/lib/hcs/HCSDataAdder.java b/src/main/java/org/embl/mobie/lib/hcs/HCSDataAdder.java index 185252f7c..b86fabac6 100644 --- a/src/main/java/org/embl/mobie/lib/hcs/HCSDataAdder.java +++ b/src/main/java/org/embl/mobie/lib/hcs/HCSDataAdder.java @@ -200,7 +200,7 @@ public void addData( Dataset dataset ) final ArrayList< String > wells = new ArrayList<>( wellDisplay.sources.keySet() ); Collections.sort( wells ); final ImageZoomViewerTransform viewerTransform = new ImageZoomViewerTransform( wells.get( 0 ), 0 ); - final View view = new View( plate.getName(), "plate", displays, imageTransforms, viewerTransform, true ); + final View view = new View( plate.getName(), "plate", displays, imageTransforms, viewerTransform, true, null ); dataset.views().put( view.getName(), view ); } diff --git a/src/main/java/org/embl/mobie/lib/serialize/View.java b/src/main/java/org/embl/mobie/lib/serialize/View.java index 26423d892..227c65abd 100644 --- a/src/main/java/org/embl/mobie/lib/serialize/View.java +++ b/src/main/java/org/embl/mobie/lib/serialize/View.java @@ -57,23 +57,30 @@ public class View private boolean isExclusive = false; - // Runtime + private String description = null; // TODO: make part of the spec + + // Runtime + // private transient String name; private transient boolean overlayNames = false; // TODO add to JSON spec? - - public View( String name, String uiSelectionGroup, List< Display< ? > > sourceDisplays, List< Transformation > sourceTransforms, boolean isExclusive ) { - this( name, uiSelectionGroup, sourceDisplays, sourceTransforms, null, isExclusive); - } - public View( String name, String uiSelectionGroup, List< Display< ? > > sourceDisplays, List< Transformation > sourceTransforms, @Nullable ViewerTransform viewerTransform, boolean isExclusive ) { + public View( String name, + String uiSelectionGroup, + List< Display< ? > > sourceDisplays, + List< Transformation > sourceTransforms, + @Nullable ViewerTransform viewerTransform, + boolean isExclusive, + @Nullable String description + ) { this.name = name; this.uiSelectionGroup = uiSelectionGroup; this.sourceDisplays = sourceDisplays; this.sourceTransforms = sourceTransforms; this.viewerTransform = viewerTransform; this.isExclusive = isExclusive; + this.description = description; } // map of data source name to the @@ -176,4 +183,9 @@ public void overlayNames( boolean overlayNames ) { this.overlayNames = overlayNames; } + + public String getDescription() + { + return description; + } } diff --git a/src/main/java/org/embl/mobie/lib/transform/NormalizedAffineViewerTransform.java b/src/main/java/org/embl/mobie/lib/transform/NormalizedAffineViewerTransform.java index 29d6841bd..083fb26bf 100644 --- a/src/main/java/org/embl/mobie/lib/transform/NormalizedAffineViewerTransform.java +++ b/src/main/java/org/embl/mobie/lib/transform/NormalizedAffineViewerTransform.java @@ -28,6 +28,8 @@ */ package org.embl.mobie.lib.transform; +import bdv.util.BdvHandle; +import net.imglib2.realtransform.AffineTransform3D; import org.embl.mobie.lib.transform.viewer.ViewerTransform; public class NormalizedAffineViewerTransform implements ViewerTransform @@ -36,6 +38,12 @@ public class NormalizedAffineViewerTransform implements ViewerTransform private double[] normalizedAffine; private Integer timepoint; + public NormalizedAffineViewerTransform( BdvHandle bdvHandle ) + { + normalizedAffine = TransformHelper.createNormalisedViewerTransform( bdvHandle.getViewerPanel() ).getRowPackedCopy(); + timepoint = bdvHandle.getViewerPanel().state().getCurrentTimepoint(); + } + public NormalizedAffineViewerTransform( double[] parameters, int timepoint ) { this.normalizedAffine = parameters; 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 4185191ba..324ffd432 100644 --- a/src/main/java/org/embl/mobie/lib/view/ViewManager.java +++ b/src/main/java/org/embl/mobie/lib/view/ViewManager.java @@ -156,7 +156,7 @@ private void addImageTransforms( List< Transformation > imageTransforms, List< ? } } - public View createCurrentView( String uiSelectionGroup, boolean isExclusive, boolean includeViewerTransform ) + public View createViewFromCurrentState( String uiSelectionGroup, boolean isExclusive, boolean includeViewerTransform, String description ) { // Create serialisable copies of the current displays List< Display< ? > > displays = new ArrayList<>(); @@ -178,17 +178,9 @@ else if ( display instanceof SpotDisplay ) addImageTransforms( transformations, display.sourceAndConverters() ); } - if ( includeViewerTransform ) - { - final BdvHandle bdvHandle = sliceViewer.getBdvHandle(); - AffineTransform3D normalisedViewTransform = TransformHelper.createNormalisedViewerTransform( bdvHandle.getViewerPanel() ); - final NormalizedAffineViewerTransform transform = new NormalizedAffineViewerTransform( normalisedViewTransform.getRowPackedCopy(), bdvHandle.getViewerPanel().state().getCurrentTimepoint() ); - return new View( "", uiSelectionGroup, displays, transformations, transform, isExclusive); - } - else - { - return new View( "", uiSelectionGroup, displays, transformations, isExclusive ); - } + NormalizedAffineViewerTransform normalizedAffineViewerTransform = includeViewerTransform ? + new NormalizedAffineViewerTransform( sliceViewer.getBdvHandle() ) : null; + return new View( "", uiSelectionGroup, displays, transformations, normalizedAffineViewerTransform, isExclusive, description ); } public synchronized void show( String viewName ) @@ -202,6 +194,8 @@ public synchronized void show( View view ) { final long startTime = System.currentTimeMillis(); IJ.log( "Opening view: " + view.getName() ); + if ( view.getDescription() != null ) + IJ.log( "Description: " + view.getDescription() ); if ( view.isExclusive() ) { 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 0bbb6c0cf..cd43b81e0 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 @@ -107,6 +107,7 @@ public void viewSettingsDialog( SaveMethod saveMethod, MoBIEHelper.FileLocation if ( saveMethod == SaveMethod.saveAsNewView ) { gd.addStringField("View name:", "", 25 ); + gd.addStringField( "View description:", "", 50 ); } String[] currentUiSelectionGroups = moBIE.getUserInterface().getUISelectionGroupNames(); @@ -130,8 +131,10 @@ public void viewSettingsDialog( SaveMethod saveMethod, MoBIEHelper.FileLocation if (!gd.wasCanceled()) { String viewName = null; + String viewDescription = ""; if( saveMethod == SaveMethod.saveAsNewView ) { viewName = UserInterfaceHelper.tidyString( gd.getNextString() ); + viewDescription = gd.getNextString(); if ( viewName == null ) { return; } @@ -155,7 +158,7 @@ public void viewSettingsDialog( SaveMethod saveMethod, MoBIEHelper.FileLocation uiSelectionGroup = ProjectCreatorHelper.makeNewUiSelectionGroup(currentUiSelectionGroups); } - View currentView = moBIE.getViewManager().createCurrentView(uiSelectionGroup, exclusive, includeViewerTransform); + View currentView = moBIE.getViewManager().createViewFromCurrentState(uiSelectionGroup, exclusive, includeViewerTransform, viewDescription); if ( uiSelectionGroup != null && currentView != null ) { if ( fileLocation == MoBIEHelper.FileLocation.Project && saveMethod == SaveMethod.saveAsNewView ) { diff --git a/src/test/java/org/embl/mobie/lib/serialize/DatasetJsonParserTest.java b/src/test/java/org/embl/mobie/lib/serialize/DatasetJsonParserTest.java index 676c23d73..377e2dd59 100644 --- a/src/test/java/org/embl/mobie/lib/serialize/DatasetJsonParserTest.java +++ b/src/test/java/org/embl/mobie/lib/serialize/DatasetJsonParserTest.java @@ -87,7 +87,7 @@ public void savePlatyView() throws IOException moBIE.getViewManager().show( views.get("Suppl. Fig. 2A: Neuron" ) ); // grab the current view and save it - View view = moBIE.getViewManager().createCurrentView( uiSelectionGroup, isExclusive, true ); + View view = moBIE.getViewManager().createViewFromCurrentState( uiSelectionGroup, isExclusive, true, "" ); dataset.views().put( viewName, view ); String datasetJSONPath = new File( tempDir, datasetJsonName ).getAbsolutePath();