Repository: mobie/mobie-viewer-fiji (language: python)

Issue:
grid view for sources of different sizes
@martinschorb could you please make a grid view for me where the first source is smaller than the other ones? I need this for testing my latest changes.


Discussion / hints:

Fix patch:
diff --git a/src/main/java/org/embl/mobie/viewer/transform/TransformHelper.java b/src/main/java/org/embl/mobie/viewer/transform/TransformHelper.java
index 3f1385714..89ed34680 100644
--- a/src/main/java/org/embl/mobie/viewer/transform/TransformHelper.java
+++ b/src/main/java/org/embl/mobie/viewer/transform/TransformHelper.java
@@ -9,7 +9,10 @@
 import net.imglib2.realtransform.AffineTransform3D;
 import net.imglib2.util.Intervals;
 
+import java.util.Collection;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 public class TransformHelper
 {
@@ -66,4 +69,27 @@ public static AffineTransform3D createTranslationTransform3D( double translation
 		translationTransform.translate( translationX, translationY, 0 );
 		return translationTransform;
 	}
+
+	public static double[] computeSourceUnionRealDimensions( List< SourceAndConverter< ? > > sources, double relativeMargin )
+	{
+		RealInterval bounds = unionRealInterval( sources.stream().map( sac -> sac.getSpimSource() ).collect( Collectors.toList() ));
+		final double[] realDimensions = new double[ 2 ];
+		for ( int d = 0; d < 2; d++ )
+			realDimensions[ d ] = ( 1.0 + 2.0 * relativeMargin ) * ( bounds.realMax( d ) - bounds.realMin( d ) );
+		return realDimensions;
+	}
+
+	public static double[] getMaximalSourceUnionRealDimensions( Map< String, SourceAndConverter< ? > > sourceNameToSourceAndConverter, Collection< List< String > > sourceNamesList )
+	{
+		double[] maximalDimensions = new double[ 2 ];
+		for ( List< String > sourceNames : sourceNamesList )
+		{
+			final List< SourceAndConverter< ? > > sourceAndConverters = sourceNames.stream().map( name -> sourceNameToSourceAndConverter.get( name ) ).collect( Collectors.toList() );
+			final double[] realDimensions = computeSourceUnionRealDimensions( sourceAndConverters, TransformedGridSourceTransformer.RELATIVE_CELL_MARGIN );
+			for ( int d = 0; d < 2; d++ )
+				maximalDimensions[ d ] = realDimensions[ d ] > maximalDimensions[ d ] ? realDimensions[ d ] : maximalDimensions[ d ];
+		}
+
+		return maximalDimensions;
+	}
 }
diff --git a/src/main/java/org/embl/mobie/viewer/transform/TransformedGridSourceTransformer.java b/src/main/java/org/embl/mobie/viewer/transform/TransformedGridSourceTransformer.java
index 671fe68cf..9ba6de81c 100644
--- a/src/main/java/org/embl/mobie/viewer/transform/TransformedGridSourceTransformer.java
+++ b/src/main/java/org/embl/mobie/viewer/transform/TransformedGridSourceTransformer.java
@@ -4,7 +4,6 @@
 import org.embl.mobie.viewer.MoBIE;
 import org.embl.mobie.viewer.Utils;
 import org.embl.mobie.viewer.playground.SourceAffineTransformer;
-import net.imglib2.RealInterval;
 import net.imglib2.realtransform.AffineTransform3D;
 import org.apache.commons.lang.ArrayUtils;
 
@@ -14,7 +13,6 @@
 import java.util.Map;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
-import java.util.stream.Collectors;
 
 public class TransformedGridSourceTransformer extends AbstractSourceTransformer
 {
@@ -37,9 +35,9 @@ public void transform( Map< String, SourceAndConverter< ? > > sourceNameToSource
 		if ( positions == null )
 			autoSetPositions();
 
-		final List< SourceAndConverter< ? > > referenceSources = getReferenceSources( sourceNameToSourceAndConverter );
+		final double[] cellRealDimensions = TransformHelper.getMaximalSourceUnionRealDimensions( sourceNameToSourceAndConverter, sources.values() );
 
-		transform( sourceNameToSourceAndConverter, referenceSources );
+		transform( sourceNameToSourceAndConverter, cellRealDimensions );
 	}
 
 	@Override
@@ -51,10 +49,8 @@ public List< String > getSources()
 		return allSources;
 	}
 
-	private void transform( Map< String, SourceAndConverter< ? > > sourceNameToSourceAndConverter, List< SourceAndConverter< ? > > referenceSources )
+	private void transform( Map< String, SourceAndConverter< ? > > sourceNameToSourceAndConverter, double[] cellRealDimensions )
 	{
-		final double[] cellRealDimensions = computeGridCellRealDimensions( referenceSources, RELATIVE_CELL_MARGIN );
-
 		final long start = System.currentTimeMillis();
 
 		final int nThreads = MoBIE.N_THREADS;
@@ -76,15 +72,6 @@ private void transform( Map< String, SourceAndConverter< ? > > sourceNameToSourc
 		System.out.println( "Transformed " + sourceNameToSourceAndConverter.size() + " image source(s) in " + (System.currentTimeMillis() - start) + " ms, using " + nThreads + " thread(s)." );
 	}
 
-	public static double[] computeGridCellRealDimensions( List< SourceAndConverter< ? > > sources, double relativeCellMargin )
-	{
-		RealInterval bounds = TransformHelper.unionRealInterval( sources.stream().map( sac -> sac.getSpimSource() ).collect( Collectors.toList() ));
-		final double[] cellDimensions = new double[ 2 ];
-		for ( int d = 0; d < 2; d++ )
-			cellDimensions[ d ] = ( 1.0 + 2.0 * relativeCellMargin ) * ( bounds.realMax( d ) - bounds.realMin( d ) );
-		return cellDimensions;
-	}
-
 	public static void translate( Map< String, SourceAndConverter< ? > > sourceNameToSourceAndConverter, List< String > sourceNames, List< String > sourceNamesAfterTransform, boolean centerAtOrigin, double translationX, double translationY )
 	{
 		for ( String sourceName : sourceNames )
@@ -116,7 +103,7 @@ public static SourceAffineTransformer createSourceAffineTransformer( String sour
 		}
 	}
 
-	private List< SourceAndConverter< ? > > getReferenceSources( Map< String, SourceAndConverter< ? > > sourceNameToSourceAndConverter )
+	private List< SourceAndConverter< ? > > getReferenceSources( Map< String, SourceAndConverter< ? > > sourceNameToSourceAndConverter, LinkedHashMap< String, List< String > > sources )
 	{
 		final List< String > sourceNamesAtFirstGridPosition = sources.get( gridIds.get( 0 ) );
 
@@ -136,7 +123,7 @@ public static SourceAffineTransformer createSourceAffineTransformer( String sour
 		}
 		else
 		{
-			throw new UnsupportedOperationException( "None of the sources specified at the first grid position could not be found at the list of the sources that are to be transformed. Names of sources at first grid position: " + ArrayUtils.toString( sourceNamesAtFirstGridPosition ) );
+			throw new UnsupportedOperationException( "None of the sources specified at the first grid position could be found at the list of the sources that are to be transformed. Names of sources at first grid position: " + ArrayUtils.toString( sourceNamesAtFirstGridPosition ) );
 		}
 	}
 


Test patch:
diff --git a/src/test/java/projects/OpenRemoteCentriolesBranch.java b/src/test/java/projects/OpenRemoteCentriolesBranch.java
index 72bb63ca2..4458a5837 100644
--- a/src/test/java/projects/OpenRemoteCentriolesBranch.java
+++ b/src/test/java/projects/OpenRemoteCentriolesBranch.java
@@ -16,7 +16,7 @@ public static void main( String[] args )
 
 		try {
 			new MoBIE("https://github.com/mobie/centrioles-tomo-datasets",
-					MoBIESettings.settings().gitProjectBranch( "grid-test" ).imageDataFormat( ImageDataFormat.BdvN5S3 ) );
+					MoBIESettings.settings().gitProjectBranch( "grid-test2" ).imageDataFormat( ImageDataFormat.BdvN5S3 ) );
 		} catch (IOException e) {
 			e.printStackTrace();
 		}