2323package net .preibisch .mvrecon .fiji .spimdata .imgloaders ;
2424
2525import java .util .Arrays ;
26- import java .util .HashMap ;
2726import java .util .Map ;
27+ import java .util .concurrent .ConcurrentHashMap ;
28+ import java .util .concurrent .ConcurrentMap ;
2829
2930import org .janelia .saalfeldlab .n5 .DataType ;
3031import org .janelia .saalfeldlab .n5 .N5Reader ;
3132import org .janelia .saalfeldlab .n5 .universe .metadata .ome .ngff .v04 .OmeNgffMultiScaleMetadata ;
3233import org .janelia .saalfeldlab .n5 .universe .metadata .ome .ngff .v04 .OmeNgffMultiScaleMetadata .OmeNgffDataset ;
3334import org .janelia .saalfeldlab .n5 .universe .metadata .ome .ngff .v04 .coordinateTransformations .CoordinateTransformation ;
3435import org .janelia .saalfeldlab .n5 .universe .metadata .ome .ngff .v04 .coordinateTransformations .ScaleCoordinateTransformation ;
36+ import org .janelia .saalfeldlab .n5 .universe .metadata .ome .ngff .v04 .coordinateTransformations .TranslationCoordinateTransformation ;
3537
3638import bdv .img .n5 .N5Properties ;
3739import mpicbg .spim .data .generic .sequence .AbstractSequenceDescription ;
@@ -49,7 +51,8 @@ public class AllenOMEZarrProperties implements N5Properties
4951 // N5Properties.getDatasetPath should require an N5Reader so that the dataset path could always be retrieved correctly (e.g., "s0", "s1", "s2" or "0", "1", "2")
5052 // To work around this problem for now, first time we retrieve the view setup we cache it so that next time
5153 // the dataset path is needed - we use the cached value.
52- private final Map < ViewId , OmeNgffMultiScaleMetadata > viewIdToOmeMetadata = new HashMap <>();
54+ // TODO: Remove this and the method that populates it, once the signature for N5Properties.getDatasetPath was updated to use the N5 Reader
55+ private final ConcurrentMap < ViewId , OmeNgffMultiScaleMetadata > viewIdToOmeMetadata = new ConcurrentHashMap <>();
5356
5457 public AllenOMEZarrProperties (
5558 final AbstractSequenceDescription < ?, ?, ? > sequenceDescription ,
@@ -143,6 +146,25 @@ private static double[][] getMipMapResolutions( final AllenOMEZarrProperties n5p
143146 mipMapResolutions [ i ][ d ] = Math .round (mipMapResolutions [ i ][ d ]*10000 )/10000d ; // round to the 5th digit
144147 }
145148 }
149+ if ( c instanceof TranslationCoordinateTransformation )
150+ {
151+ final TranslationCoordinateTransformation t = ( TranslationCoordinateTransformation ) c ;
152+
153+ if (firstScale == null ) {
154+ throw new IllegalStateException ("Expected first scale to be set before the translation for level " + i + " dataset is processed" );
155+ }
156+
157+ for ( int d = 0 ; d < mipMapResolutions [ i ].length ; ++d )
158+ {
159+ // at this point firstScale should be available
160+ double pxTranslation = t .getTranslation ()[ d ] / firstScale [ d ];
161+ double pxTranslationCorrection = (pxTranslation + 0.5 ) / mipMapResolutions [i ][d ] - 0.5 ;
162+ if (Math .abs (pxTranslationCorrection ) >= 0.5 ) {
163+ System .out .printf ("Pixel translation[%d][%d]=%f (=%fpx) and the pixel correction %f is more than 0.5px\n " ,
164+ i , d , t .getTranslation ()[ d ], pxTranslation , pxTranslationCorrection );
165+ }
166+ }
167+ }
146168 }
147169 }
148170
@@ -153,17 +175,14 @@ private String getMultiscaleDatasetPathOrDefault( N5Reader n5, int timepointId,
153175 {
154176 OmeNgffMultiScaleMetadata omeNgffMultiScaleMetadata = getViewSetupMultiscaleMetadata (n5 , timepointId , setupId );
155177
156- String viewSetupPath = getPath ( setupId , timepointId );
157- String datasetPath ;
158-
159- if ( omeNgffMultiScaleMetadata != null ) {
160- // get the first scale path from the metadata
161- datasetPath = omeNgffMultiScaleMetadata .datasets [level ].path ;
162- } else {
163- // use the default level value
164- datasetPath = String .valueOf ( level );
178+ if (omeNgffMultiScaleMetadata == null ) {
179+ throw new IllegalStateException ("OME multiscale metadata could not be cached for (tp, setup) = (" +
180+ timepointId + "," + setupId + ") - current N5Reader is " + n5 );
165181 }
166182
183+ String viewSetupPath = getPath ( setupId , timepointId );
184+ // get the first scale path from the metadata
185+ String datasetPath = omeNgffMultiScaleMetadata .datasets [level ].path ;
167186 return String .format ( "%s/%s" , viewSetupPath , datasetPath );
168187 }
169188
0 commit comments