Skip to content

Commit

Permalink
Add support for GridType.None
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Jun 14, 2024
1 parent 3e65fef commit 31668b6
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 12 deletions.
7 changes: 7 additions & 0 deletions src/main/java/org/embl/mobie/MoBIE.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ public MoBIE( String tablePath, List< String > imageColumns, List< String > labe

this.settings = settings;

// TODO: if the gridType is None we may want to rather use SourcesFromPathsCreator( )
// where we prefetch the paths from the table based on the image type
// https://github.com/mobie/mobie-viewer-fiji/issues/1151
// in fact then the table layout is different as each row can have a different data type
// Old table: image_path, segmentation_path (one-to-one relation of an image and a segmentation)
// New Table: path, image_type (no relation of an image and a segmentation needed, could be defined by having the same view_id)
// Both can be useful and I guess we should keep on supporting both
final SourcesFromTableCreator sourcesCreator = new SourcesFromTableCreator( tablePath, imageColumns, labelColumns, root, pathMapping, grid );

final List< ImageFileSources > imageSources = sourcesCreator.getImageSources();
Expand Down
81 changes: 73 additions & 8 deletions src/main/java/org/embl/mobie/lib/files/FileSourcesDataSetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public class FileSourcesDataSetter
private final List< LabelFileSources > labels;
private final Table regionTable;

public FileSourcesDataSetter( List< ImageFileSources > images, List< LabelFileSources > labels, Table regionTable )
public FileSourcesDataSetter( List< ImageFileSources > images,
List< LabelFileSources > labels,
Table regionTable )
{
this.images = images;
this.labels = labels;
Expand Down Expand Up @@ -112,23 +114,86 @@ public void addDataAndDisplaysAndViews( Dataset dataset )
}
}

addGridView( dataset, allSources, regionTable );
// note that currently the way they are constructed
// all sources will have the same grid type
// thus it suffices to check the first one
// ( obviously this smells as if this logic could be improved )
if ( allSources.get( 0 ).getGridType().equals( GridType.None ) )
{
addIndividualViews( dataset, allSources );
}
else
{
// create a grid view for all sources
// assuming that they all live in the same grid
addGridView( dataset, allSources );
}
}

// This assumes that all the individual views are similar
// that are part of the same ImageFileSources, as they get the same initial metadata
// in terms of number of channels, timepoints and contrast limits
private void addIndividualViews( Dataset dataset, ArrayList< ImageFileSources > fileSourcesList )
{
for ( ImageFileSources sources : fileSourcesList )
{
for ( String source : sources.getSources() )
{
final List< Display< ? > > displays = new ArrayList<>();
final List< Transformation > transformations = new ArrayList<>();

if ( sources instanceof LabelFileSources )
{
// SegmentationDisplay
final SegmentationDisplay< AnnotatedSegment > segmentationDisplay
= new SegmentationDisplay<>( source, Collections.singletonList( source ) );
final int numLabelTables = ( ( LabelFileSources ) sources ).getNumLabelTables();
segmentationDisplay.setShowTable( numLabelTables > 0 );
displays.add( segmentationDisplay );
}
else
{
// ImageDisplay
final Metadata metadata = sources.getMetadata();
ImageDisplay< ? > imageDisplay = new ImageDisplay<>( source,
Collections.singletonList( source ),
metadata.color,
metadata.contrastLimits );
displays.add( imageDisplay );
}

// construct and add the view
//
final ImageZoomViewerTransform viewerTransform = new ImageZoomViewerTransform( source, 0 );
final View view = new View(
source,
"data",
displays,
null,
viewerTransform,
false,
null );

dataset.views().put( view.getName(), view );
}
}

}

private void addGridView( Dataset dataset, ArrayList< ImageFileSources > allSources, Table regionTable )
private void addGridView( Dataset dataset, ArrayList< ImageFileSources > fileSourcesList )
{
RegionDisplay< AnnotatedRegion > regionDisplay = null;
final List< Display< ? > > displays = new ArrayList<>();
final List< Transformation > transformations = new ArrayList<>();

for ( ImageFileSources sources : allSources )
for ( ImageFileSources sources : fileSourcesList )
{
List< String > sourceNames = sources.getSources();
final int numRegions = sourceNames.size();

if ( regionDisplay == null )
{
// init RegionDisplay
// init RegionDisplay for allSources, assuming that they all should live in the same grid
regionDisplay = new RegionDisplay<>( regionTable.name() );

// add table
Expand Down Expand Up @@ -170,10 +235,10 @@ private void addGridView( Dataset dataset, ArrayList< ImageFileSources > allSour
//System.out.println("Region: " + regionName + "; source: " + sourceNames.get( regionIndex ) );
}

if ( sources.getSources().size() == 1 )
if ( sources.getSources().size() == 1 ) // no need to build a grid view
{
String source = sources.getSources().get( 0 );
// no need to build a grid view

if ( sources instanceof LabelFileSources )
{
// SegmentationDisplay
Expand Down Expand Up @@ -273,7 +338,7 @@ else if ( sources.getGridType().equals( GridType.Transformed ) )

// construct and add the view
//
final ImageZoomViewerTransform viewerTransform = new ImageZoomViewerTransform( allSources.get( 0 ).getSources().get( 0 ), 0 );
final ImageZoomViewerTransform viewerTransform = new ImageZoomViewerTransform( fileSourcesList.get( 0 ).getSources().get( 0 ), 0 );
final View view = new View( "all images", "data", displays, transformations, viewerTransform, false, null );
dataset.views().put( view.getName(), view );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public ImageFileSources( String name, String pathRegex, Integer channelIndex, St
}

// TODO: how to deal with the inconsistent metadata (e.g. number of time-points)?
// FIXME: We don't always want to prefetch this as this is expensive..
setMetadata( channelIndex );

// TODO: move this out to a separate function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@

public class SourcesFromPathsCreator
{
private List< ImageFileSources > imageSources;
private List< LabelFileSources > labelSources;
private Table regionTable;
private final List< ImageFileSources > imageSources;
private final List< LabelFileSources > labelSources;

public SourcesFromPathsCreator( List < String > imagePaths, List < String > labelPaths, List < String > labelTablePaths, String root, GridType grid )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public AffineTransform3D getSingleSourceTransform()
}

// TODO: This does not seem to work well if one of the sources
// contains a rotation: https://github.com/mobie/mobie-viewer-fiji/issues/1153
// contains a rotation: https://github.com/mobie/mobie-viewer-fiji/issues/1154
// For debugging this also a single source would suffice.
public AffineTransform3D getMultiSourceTransform() {
SynchronizedViewerState state = bdvHandle.getViewerPanel().state();
final RealInterval mask = TransformHelper.createMask( sources, state.getCurrentTimepoint() );
Expand Down
51 changes: 51 additions & 0 deletions src/test/java/projects/OpenLocalTestTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*-
* #%L
* Fiji viewer for MoBIE projects
* %%
* Copyright (C) 2018 - 2024 EMBL
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package projects;

import net.imagej.ImageJ;
import org.embl.mobie.command.open.OpenTableCommand;
import org.embl.mobie.lib.transform.GridType;

import java.io.File;
import java.io.IOException;

public class OpenLocalTestTable
{
public static void main( String[] args ) throws IOException
{
final ImageJ imageJ = new ImageJ();
imageJ.ui().showUI();

OpenTableCommand command = new OpenTableCommand();
command.table = new File("/Users/tischer/Desktop/mobie-table-test/table.csv");
command.gridType = GridType.None;
command.images = "Path";
command.run();
}
}

0 comments on commit 31668b6

Please sign in to comment.