|
| 1 | +package org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertArrayEquals; |
| 4 | +import static org.junit.Assert.assertTrue; |
| 5 | + |
| 6 | +import java.net.URI; |
| 7 | +import java.nio.file.Paths; |
| 8 | +import java.util.Optional; |
| 9 | + |
| 10 | +import org.janelia.saalfeldlab.n5.DataType; |
| 11 | +import org.janelia.saalfeldlab.n5.DatasetAttributes; |
| 12 | +import org.janelia.saalfeldlab.n5.N5Reader; |
| 13 | +import org.janelia.saalfeldlab.n5.RawCompression; |
| 14 | +import org.janelia.saalfeldlab.n5.universe.N5Factory; |
| 15 | +import org.janelia.saalfeldlab.n5.universe.N5TreeNode; |
| 16 | +import org.janelia.saalfeldlab.n5.universe.metadata.N5SingleScaleMetadata; |
| 17 | +import org.junit.Test; |
| 18 | + |
| 19 | +import net.imglib2.realtransform.AffineGet; |
| 20 | +import net.imglib2.realtransform.AffineTransform3D; |
| 21 | +import net.imglib2.realtransform.ScaleAndTranslation; |
| 22 | + |
| 23 | +public class CoordinateTransformParsingTest { |
| 24 | + |
| 25 | + private static final double EPS = 1E-6; |
| 26 | + |
| 27 | + @Test |
| 28 | + public void testCoordinateTransformParsing() { |
| 29 | + |
| 30 | + URI rootF = Paths.get("src", "test", "resources", "metadata.zarr").toUri(); |
| 31 | + final N5Reader zarr = new N5Factory().openReader(rootF.toString()); |
| 32 | + |
| 33 | + final OmeNgffMetadataParser grpParser = new OmeNgffMetadataParser(); |
| 34 | + test(grpParser.parseMetadata(zarr, setupNode("coordTforms/ss", "s0")), |
| 35 | + new double[]{4, 4}, |
| 36 | + new double[]{0, 0}); |
| 37 | + |
| 38 | + test(grpParser.parseMetadata(zarr, setupNode("coordTforms/st", "s0")), |
| 39 | + new double[]{2, 2}, |
| 40 | + new double[]{10, 10}); |
| 41 | + |
| 42 | + test(grpParser.parseMetadata(zarr, setupNode("coordTforms/ts", "s0")), |
| 43 | + new double[]{2, 2}, |
| 44 | + new double[]{20, 20}); |
| 45 | + |
| 46 | + test(grpParser.parseMetadata(zarr, setupNode("coordTforms/tt", "s0")), |
| 47 | + new double[]{1, 1}, |
| 48 | + new double[]{20, 20}); |
| 49 | + } |
| 50 | + |
| 51 | + private void test(final Optional<OmeNgffMetadata> metaOpt, final double[] expectedScale, final double[] expectedTranslation) { |
| 52 | + |
| 53 | + assertTrue("ss not parsable", metaOpt.isPresent()); |
| 54 | + |
| 55 | + final OmeNgffMetadata meta = metaOpt.get(); |
| 56 | + final AffineGet[] tforms = meta.spatialTransforms(); |
| 57 | + assertTrue("ss has one transform", tforms.length == 1); |
| 58 | + |
| 59 | + final ScaleAndTranslation tform = (ScaleAndTranslation)tforms[0]; |
| 60 | + assertArrayEquals(expectedScale, tform.getScaleCopy(), EPS); |
| 61 | + assertArrayEquals(expectedTranslation, tform.getTranslationCopy(), EPS); |
| 62 | + } |
| 63 | + |
| 64 | + private N5TreeNode setupNode(final String path, final String childPath) { |
| 65 | + |
| 66 | + final N5TreeNode node = new N5TreeNode(path); |
| 67 | + final N5TreeNode child = new N5TreeNode(path + "/" + childPath); |
| 68 | + final DatasetAttributes attrs = new DatasetAttributes(new long[]{4, 4}, new int[]{4, 4}, DataType.UINT8, new RawCompression()); |
| 69 | + child.setMetadata(new N5SingleScaleMetadata(path + "/" + childPath, new AffineTransform3D(), |
| 70 | + new double[]{1, 1}, new double[]{1, 1}, new double[]{0, 0}, "", attrs, false)); |
| 71 | + |
| 72 | + node.add(child); |
| 73 | + return node; |
| 74 | + } |
| 75 | + |
| 76 | +} |
0 commit comments