diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f0f5d5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +**/.classpath +**/.project +**/.settings +**/target +.DS_Store +.classpath +.project +.settings +.factorypath +.idea +target +*.iml +*.class +*~ +*.orig +# For Fiji # +*.jar diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..6825ed1 --- /dev/null +++ b/pom.xml @@ -0,0 +1,90 @@ + + + 4.0.0 + + ome + ome-ngff-java + 0.0.0-SNAPSHOT + + https://github.com/ome/ome-ngff-java + OME NGFF Java + Java code for OME NGFF metadata + 2022 + + Open Microscopy Environment + http://www.openmicroscopy.org/ + + + Trac + https://trac.openmicroscopy.org/ome + + + + + ??? + repo + + + + + + tischi + Christian Tischer + + lead + developer + debugger + reviewer + support + maintainer + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.0 + + -Xmx4024m + + + + + + + + central + Central Repository + https://repo.maven.apache.org/maven2 + + + ome + OME Artifactory + https://artifacts.openmicroscopy.org/artifactory/maven/ + + + + + + com.google.guava + guava + 10.0.1 + + + com.google.code.gson + gson + 2.9.1 + + + diff --git a/src/main/java/ome/ngff/MultiscalesV04.java b/src/main/java/ome/ngff/MultiscalesV04.java new file mode 100644 index 0000000..80429be --- /dev/null +++ b/src/main/java/ome/ngff/MultiscalesV04.java @@ -0,0 +1,127 @@ +package ome.ngff; + +import com.google.common.collect.Lists; +import com.google.gson.JsonElement; + +import java.util.Arrays; +import java.util.List; + +public class MultiscalesV04 +{ + // key in json for multiscales + public static final String MULTI_SCALE_KEY = "multiscales"; + + // Serialisation + private String version; + private String name; + private String type; + private Axis[] axes; // from v0.4+ within JSON + private Dataset[] datasets; + private CoordinateTransformations[] coordinateTransformations; // from v0.4+ within JSON + + // Runtime + + // Simply contains the {@codeAxes[] axes} + // but in reversed order to accommodate + // the Java array ordering of the image data. + private List< Axis > axisList; + private int numDimensions; + + public MultiscalesV04() { + } + + public static class Dataset { + public String path; + public CoordinateTransformations[] coordinateTransformations; + } + + public static class CoordinateTransformations { + public String type; + public double[] scale; + public double[] translation; + public String path; + } + + public static class Axis + { + public static final String CHANNEL_TYPE = "channel"; + public static final String TIME_TYPE = "time"; + public static final String SPATIAL_TYPE = "space"; + + public String name; + public String type; + public String unit; + } + + public void init() + { + axisList = Lists.reverse( Arrays.asList( axes ) ); + numDimensions = axisList.size(); + } + + // TODO Can this be done with a JSONAdapter ? + public void applyVersionFixes( JsonElement multiscales ) + { + String version = multiscales.getAsJsonObject().get("version").getAsString(); + if ( version.equals("0.3") ) { + JsonElement axes = multiscales.getAsJsonObject().get("axes"); + // FIXME + // - populate Axes[] + // - populate coordinateTransformations[] + throw new RuntimeException("Parsing version 0.3 not yet implemented."); + } else if ( version.equals("0.4") ) { + // This should just work automatically + } else { + JsonElement axes = multiscales.getAsJsonObject().get("axes"); + // FIXME + // - populate Axes[] + // - populate coordinateTransformations[] + throw new RuntimeException("Parsing version "+ version + " is not yet implemented."); + } + } + + public int getChannelAxisIndex() + { + for ( int d = 0; d < numDimensions; d++ ) + if ( axisList.get( d ).type.equals( Axis.CHANNEL_TYPE ) ) + return d; + return -1; + } + + public int getTimePointAxisIndex() + { + for ( int d = 0; d < numDimensions; d++ ) + if ( axisList.get( d ).type.equals( Axis.TIME_TYPE ) ) + return d; + return -1; + } + + public int getSpatialAxisIndex( String axisName ) + { + for ( int d = 0; d < numDimensions; d++ ) + if ( axisList.get( d ).type.equals( Axis.SPATIAL_TYPE ) + && axisList.get( d ).name.equals( axisName ) ) + return d; + return -1; + } + + public List< Axis > getAxes() + { + return axisList; + } + + public CoordinateTransformations[] getCoordinateTransformations() + { + return coordinateTransformations; + } + + public Dataset[] getDatasets() + { + return datasets; + } + + public int numDimensions() + { + return numDimensions; + } +}