Skip to content

Commit

Permalink
Add view description
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Jan 5, 2024
1 parent 7756015 commit 2d952a9
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 61 deletions.
13 changes: 13 additions & 0 deletions src/main/java/org/embl/mobie/MoBIESettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
{
Expand Down Expand Up @@ -186,5 +194,10 @@ public Boolean isOpenedFromCLI()
{
return openedFromCLI;
}

public String getGroovyScript()
{
return groovyScript;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,53 @@ public void run()

final MoBIESettings settings = new MoBIESettings();
settings.removeSpatialCalibration( removeSpatialCalibration );
String groovyCode = generateGroovyScript();
settings.appendGroovyCode( groovyCode );
// System.out.println( groovyCode );

try
{
new MoBIE( imageList, labelsList, tablesList, null, gridType, settings );
}
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/embl/mobie/lib/SpimDataAdder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand All @@ -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 );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
/**
* Class to create and modify the metadata stored in dataset Json files
*/
public class DatasetJsonCreator {
public class DatasetSerializer
{

ProjectCreator projectCreator;

Expand All @@ -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;
}

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -158,15 +166,17 @@ 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 );
imageSource.imageData = imageDataLocations;
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();
Expand All @@ -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 ) {
Expand All @@ -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<String> sources ) {
private List< Transformation > createSourceTransformerList( AffineTransform3D sourceTransform, List<String> sources )
{
List< Transformation > imageTransformationList = new ArrayList<>();
Transformation imageTransformation = new AffineTransformation( "affine", sourceTransform.getRowPackedCopy(), sources );
imageTransformationList.add( imageTransformation );
Expand All @@ -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<String> sources = new ArrayList<>();
sources.add( imageName );
Expand All @@ -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 );
}
}

Expand All @@ -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" );
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/embl/mobie/lib/create/ImagesCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/embl/mobie/lib/create/ProjectCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -216,8 +216,8 @@ public ImagesCreator getImagesCreator() {
return imagesCreator;
}

public DatasetJsonCreator getDatasetJsonCreator() {
return datasetJsonCreator;
public DatasetSerializer getDatasetJsonCreator() {
return datasetSerializer;
}

public ProjectJsonCreator getProjectJsonCreator() { return projectJsonCreator; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/embl/mobie/lib/hcs/HCSDataAdder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down
Loading

0 comments on commit 2d952a9

Please sign in to comment.