Skip to content

Commit

Permalink
Merge pull request #1046 from mobie/issue1044
Browse files Browse the repository at this point in the history
Issue1044
  • Loading branch information
tischi authored Aug 1, 2023
2 parents f81a11a + cc25e02 commit 5e9646d
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 62 deletions.
13 changes: 7 additions & 6 deletions src/main/java/org/embl/mobie/lib/AnnotatedLabelImageCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,26 @@

public class AnnotatedLabelImageCreator
{
private final MoBIE moBIE;
private AnnotationLabelImage< TableSawAnnotatedSegment > annotatedLabelImage;

public AnnotatedLabelImageCreator( MoBIE moBIE, SegmentationDataSource dataSource, Image< ? > image )
{
this.moBIE = moBIE;

if ( dataSource.tableData != null )
{
//System.out.println(dataSource.getName() + ": initialising.." );

final StorageLocation tableLocation = moBIE.getTableLocation( dataSource.tableData );
final TableDataFormat tableFormat = moBIE.getTableDataFormat( dataSource.tableData );

//System.out.println( dataSource.getName() + ": pre-init: " + dataSource.preInit() );

Table table = dataSource.preInit() ?
TableOpener.open( tableLocation, tableFormat ) : null;

SegmentColumnNames segmentColumnNames = table != null ?
TableDataFormat.getSegmentColumnNames( table.columnNames() ) : null;
//SegmentColumnNames segmentColumnNames = table != null ?
// TableDataFormat.getSegmentColumnNames( table.columnNames() ) : null;

final TableSawAnnotatedSegmentCreator annotationCreator = new TableSawAnnotatedSegmentCreator( segmentColumnNames, table );
final TableSawAnnotatedSegmentCreator annotationCreator = new TableSawAnnotatedSegmentCreator( table );

final TableSawAnnotationTableModel< TableSawAnnotatedSegment > tableModel = new TableSawAnnotationTableModel( dataSource.getName(), annotationCreator, tableLocation, tableFormat, table );

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/embl/mobie/lib/annotation/Annotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ public interface Annotation extends Location
// For adding manual annotations
void setString( String columnName, String value );

// For merging tables.
String[] idColumns();

// Transform the spatial coordinates of this annotation.
// Note that there are also methods to transform annotations,
// which create a copy of the annotation;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/embl/mobie/lib/image/StitchedImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,12 @@ private void setPositions( List< ? extends Image< T > > images, List< int[] > po
this.positions = new ArrayList<>();
for ( int[] position : positions )
{
final int[] thisPosition = new int[ 2 ];
final int[] zeroMinPosition = new int[ 2 ];
for ( int d = 0; d < 2; d++ )
{
thisPosition[ d ] = position[ d ] - min[ d ];
zeroMinPosition[ d ] = position[ d ] - min[ d ];
}
this.positions.add( thisPosition );
this.positions.add( zeroMinPosition );
}
}
}
Expand Down Expand Up @@ -490,8 +490,8 @@ protected Map< Integer, List< RandomAccessibleInterval< V > > > stitchVolatileTi
{
final V background = volatileType.createVariable();
background.setValid( true );
final FunctionRandomAccessible< V > stichedTimepointAtLevel = new FunctionRandomAccessible( 3, new VolatileValueFromTilesFetcherSupplier( tileStore, t, level, background ).get(), () -> volatileType.createVariable() );
final IntervalView< V > rai = Views.interval( stichedTimepointAtLevel, getInterval( level ) );
final FunctionRandomAccessible< V > stitchedTimepointAtLevel = new FunctionRandomAccessible( 3, new VolatileValueFromTilesFetcherSupplier( tileStore, t, level, background ).get(), () -> volatileType.createVariable() );
final IntervalView< V > rai = Views.interval( stitchedTimepointAtLevel, getInterval( level ) );
stitched.get( t ).add( rai );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public abstract class AbstractGridTransformation implements Transformation
{
// Serialization

public List< int[] > positions;
public List< int[] > positions; // x,y positions of the image tiles

public double margin = 0.1; // 0.1;
public double margin = 0.1;

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@

public class MergedGridTransformation extends AbstractGridTransformation
{
// Serialization TODO: make fields private and add getter and setter methods
// Serialization

public List< String > sources; // required

private String mergedGridSourceName = "merged image"; // required => name of corresponding StitchedImage

public String metadataSource; // optional, this improves performance (a lot)

public boolean centerAtOrigin = false; // TODO: should actually be true, but: https://github.com/mobie/mobie-viewer-fiji/issues/685#issuecomment-1108179599

private String mergedGridSourceName = "merged image"; // required => name of corresponding StitchedImage

// Runtime

public transient int timepoints = 1; // the number of timepoints that the sources span

public transient boolean lazyLoadTables = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public void loadTableChunk( String tableChunk )
for ( AnnotationTableModel< A > tableModel : tableModels )
tableModel.loadTableChunk( tableChunk );

// TODO: it is not logical that this method does not trigger
// an annotation listener...
for ( AnnotationListener< A > listener : listeners.list )
listener.columnsAdded( null );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,6 @@ public void setString( String columnName, String value )
throw new UnsupportedOperationException( "Adding values to " + this.getClass() + " is not implemented." );
}

@Override
public String[] idColumns()
{
return idColumns;
}

@Override
public void transform( AffineTransform3D affineTransform3D )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,6 @@ public String source()
return source;
}

@Override
public String[] idColumns()
{
return idColumns;
}

@Override
public void transform( AffineTransform3D affineTransform3D )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.embl.mobie.lib.table.ColumnNames;
import tech.tablesaw.api.Table;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand All @@ -40,6 +41,7 @@ public class TableSawAnnotatedRegionCreator implements TableSawAnnotationCreator
private final int timePointColumnIndex;
private final double relativeDilation;
private int regionIdColumnIndex;
private ArrayList< String > idColumns;

public TableSawAnnotatedRegionCreator( Table table, Map< String, List< String > > regionIdToImageNames, double relativeDilation )
{
Expand All @@ -48,6 +50,9 @@ public TableSawAnnotatedRegionCreator( Table table, Map< String, List< String >
this.regionIdToImageNames = regionIdToImageNames;
regionIdColumnIndex = columnNames.indexOf( ColumnNames.REGION_ID );
timePointColumnIndex = columnNames.indexOf( ColumnNames.TIMEPOINT );
idColumns = new ArrayList<>();
idColumns.add( ColumnNames.REGION_ID );
idColumns.add( ColumnNames.TIMEPOINT );
}

@Override
Expand All @@ -71,4 +76,10 @@ public int[] removeColumns()
{
return new int[ 0 ];
}

@Override
public List< String > getIDColumns()
{
return idColumns;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,6 @@ public String source()
return source;
}

@Override
public String[] idColumns()
{
return idColumns;
}

@Override
public void transform( AffineTransform3D affineTransform3D )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import tech.tablesaw.api.Table;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
Expand All @@ -51,12 +52,11 @@ public class TableSawAnnotatedSegmentCreator implements TableSawAnnotationCreato
private AtomicBoolean columnsInitialised = new AtomicBoolean( false );
private boolean is3D;
private boolean hasBoundingBox;
private ArrayList< String > idColumns;

public TableSawAnnotatedSegmentCreator(
@Nullable SegmentColumnNames segmentColumnNames,
@Nullable Table table )
public TableSawAnnotatedSegmentCreator( @Nullable Table table )
{
this.segmentColumnNames = segmentColumnNames;
//this.segmentColumnNames = segmentColumnNames;
if ( table != null )
initColumns( table );
}
Expand All @@ -67,8 +67,12 @@ private synchronized void initColumns( Table table )

final List< String > columnNames = table.columnNames();

if ( segmentColumnNames == null )
segmentColumnNames = TableDataFormat.getSegmentColumnNames( columnNames );
segmentColumnNames = TableDataFormat.getSegmentColumnNames( columnNames );

idColumns = new ArrayList<>();
idColumns.add( segmentColumnNames.labelIdColumn() );
idColumns.add( segmentColumnNames.timePointColumn() );
idColumns.add( segmentColumnNames.labelImageColumn() );

labelIdColumnIndex = columnNames.indexOf( segmentColumnNames.labelIdColumn() );
if ( labelIdColumnIndex == -1 )
Expand All @@ -94,6 +98,7 @@ private synchronized void initColumns( Table table )

hasBoundingBox = bbMinColumnIndices[ 0 ] > -1;


}

@Override
Expand Down Expand Up @@ -153,4 +158,10 @@ private FinalRealInterval boundingBox( Table table, int rowIndex )

return boundingBox;
}

@Override
public List< String > getIDColumns()
{
return idColumns;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@ public String source()
return source;
}

@Override
public String[] idColumns()
{
return idColumns;
}

@Override
public void transform( AffineTransform3D affineTransform3D )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.embl.mobie.lib.table.ColumnNames;
import tech.tablesaw.api.Table;

import java.util.ArrayList;
import java.util.List;

public class TableSawAnnotatedSpotCreator implements TableSawAnnotationCreator< TableSawAnnotatedSpot >
Expand All @@ -40,6 +41,7 @@ public class TableSawAnnotatedSpotCreator implements TableSawAnnotationCreator<
private final int yColumnIndex;
private final int zColumnIndex;
private int timePointColumnIndex;
private ArrayList< String > idColumns;

public TableSawAnnotatedSpotCreator( Table table )
{
Expand All @@ -49,6 +51,9 @@ public TableSawAnnotatedSpotCreator( Table table )
yColumnIndex = columnNames.indexOf( ColumnNames.SPOT_Y );
zColumnIndex = columnNames.indexOf( ColumnNames.SPOT_Z );
timePointColumnIndex = columnNames.indexOf( ColumnNames.TIMEPOINT );
idColumns = new ArrayList<>();
idColumns.add( ColumnNames.SPOT_ID );
idColumns.add( ColumnNames.TIMEPOINT );
}

@Override
Expand Down Expand Up @@ -77,4 +82,10 @@ public int[] removeColumns()
{
return new int[]{ xColumnIndex, yColumnIndex, zColumnIndex };
}

@Override
public List< String > getIDColumns()
{
return idColumns;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@

import org.embl.mobie.lib.annotation.Annotation;

import java.util.List;


public interface TableSawAnnotationCreator< A extends Annotation >
{
A create( TableSawAnnotationTableModel< A > tableModel, int rowIndex );

int[] removeColumns();

List< String > getIDColumns();
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,16 @@ private void joinTable( Table additionalTable )
{
// join additional table
// some columns, e.g. timepoint, are optional and thus
// are only used for merging if they are actually present
// may be missing in the parent table;
// thus we only use columns for merging that are actually present
final List< String > columnNames = table.columnNames();
final List< String > mergeByColumnNames = Arrays.stream( annotation( 0 ).idColumns() ).filter( column -> columnNames.contains( column ) ).collect( Collectors.toList() );
//final String[] idColumns = annotation( 0 ).idColumns();
final List< String > idColumns = annotationCreator.getIDColumns();
final List< String > mergeByColumnNames = idColumns.stream().filter( column -> columnNames.contains( column ) ).collect( Collectors.toList() );

// note that the below joining changes the table object,
// the below table merging changes the table object,
// thus other classes that need that table object
// need to retrieve the new one using the {@code getTable()}
// method
// need to retrieve the new table using {@code getTable()}
try
{
final List< String > additionalColumnNames = additionalTable.columnNames().stream().filter( col -> ! mergeByColumnNames.contains( col ) ).collect( Collectors.toList() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,6 @@ public void setString( String columnName, String value )
annotatedSegment.setString( columnName, value );
}

@Override
public String[] idColumns()
{
return annotatedSegment.idColumns();
}

@Override
public void transform( AffineTransform3D affineTransform3D )
{
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/debug/DebugIssue1044.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package debug;

import net.imagej.ImageJ;
import org.embl.mobie.MoBIE;
import org.embl.mobie.MoBIESettings;

import java.io.IOException;

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

new MoBIE("/Users/tischer/Downloads/minimal-mobie/minimal-mobie-project", MoBIESettings.settings().view( "segmentations" ) );// .getViewManager().show( "cell-segmentation" );

}
}

0 comments on commit 5e9646d

Please sign in to comment.