diff --git a/algorithms/core/pom.xml b/algorithms/core/pom.xml index 9e157ce575..9968753b35 100644 --- a/algorithms/core/pom.xml +++ b/algorithms/core/pom.xml @@ -23,7 +23,7 @@ junit junit - 4.8.1 + ${junit.version} test diff --git a/algorithms/gpl/pom.xml b/algorithms/gpl/pom.xml index 7345b8ced8..2f397b24a1 100644 --- a/algorithms/gpl/pom.xml +++ b/algorithms/gpl/pom.xml @@ -32,6 +32,11 @@ imglib2-algorithms ${project.version} + + ${project.groupId} + imglib2-meta + ${project.version} + @@ -55,7 +60,7 @@ junit junit - 4.8.1 + ${junit.version} test diff --git a/algorithms/gpl/src/main/java/net/imglib2/algorithm/region/localneighborhood/Utils.java b/algorithms/gpl/src/main/java/net/imglib2/algorithm/region/localneighborhood/Utils.java index c02a05d4fc..355dd65bc7 100644 --- a/algorithms/gpl/src/main/java/net/imglib2/algorithm/region/localneighborhood/Utils.java +++ b/algorithms/gpl/src/main/java/net/imglib2/algorithm/region/localneighborhood/Utils.java @@ -27,7 +27,8 @@ package net.imglib2.algorithm.region.localneighborhood; import net.imglib2.meta.Axes; -import net.imglib2.meta.Metadata; +import net.imglib2.meta.CalibratedAxis; +import net.imglib2.meta.CalibratedSpace; import net.imglib2.util.Util; /** @@ -38,19 +39,22 @@ public class Utils { /** - * Return the xyz calibration stored in an {@link Metadata} in a 3-elements - * double array. Calibration is ordered as X, Y, Z. If one axis is not found, - * then the calibration for this axis takes the value of 1. + * Return the xyz calibration stored in a {@link CalibratedSpace} in a + * 3-elements double array. Calibration is ordered as X, Y, Z. If one axis is + * not found, then the calibration for this axis takes the value of 1. */ - public static final double[] getSpatialCalibration(final Metadata img) { + public static final double[] getSpatialCalibration( + final CalibratedSpace space) + { final double[] calibration = Util.getArrayFromValue(1d, 3); - for (int d = 0; d < img.numDimensions(); d++) { - if (img.axis(d).equals(Axes.X)) { - calibration[0] = img.calibration(d); - } else if (img.axis(d).equals(Axes.Y)) { - calibration[1] = img.calibration(d); - } else if (img.axis(d).equals(Axes.Z)) { - calibration[2] = img.calibration(d); + for (int d = 0; d < space.numDimensions(); d++) { + final CalibratedAxis axis = space.axis(d); + if (axis.type() == Axes.X) { + calibration[0] = axis.calibration(); + } else if (axis.type() == Axes.Y) { + calibration[1] = axis.calibration(); + } else if (axis.type() == Axes.Z) { + calibration[2] = axis.calibration(); } } return calibration; diff --git a/algorithms/legacy/pom.xml b/algorithms/legacy/pom.xml index 21b3b28095..2c1865d032 100644 --- a/algorithms/legacy/pom.xml +++ b/algorithms/legacy/pom.xml @@ -56,7 +56,7 @@ junit junit - 4.8.1 + ${junit.version} test diff --git a/core/pom.xml b/core/pom.xml index 4b7825da0e..cf434650b4 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -17,7 +17,7 @@ junit junit - 4.8.1 + ${junit.version} test diff --git a/core/src/main/java/net/imglib2/AbstractAnnotatedSpace.java b/core/src/main/java/net/imglib2/AbstractAnnotatedSpace.java new file mode 100644 index 0000000000..71d9078390 --- /dev/null +++ b/core/src/main/java/net/imglib2/AbstractAnnotatedSpace.java @@ -0,0 +1,98 @@ +/* + * #%L + * ImgLib2: a general-purpose, multidimensional image processing library. + * %% + * Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia, + * Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves + * Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris, + * Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier, + * Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are + * those of the authors and should not be interpreted as representing official + * policies, either expressed or implied, of any organization. + * #L% + */ + +package net.imglib2; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Abstract base class for {@link AnnotatedSpace} implementations. + * + * @author Curtis Rueden + */ +public abstract class AbstractAnnotatedSpace implements + AnnotatedSpace +{ + + private final List axisList; + + public AbstractAnnotatedSpace(final int numDims) { + axisList = new ArrayList(numDims); + // We have no way of knowing the axes to populate, so we fill with nulls. + for (int d = 0; d < numDims; d++) { + axisList.add(null); + } + } + + public AbstractAnnotatedSpace(final A... axes) { + axisList = Arrays.asList(axes); + } + + public AbstractAnnotatedSpace(final List axes) { + axisList = new ArrayList(axes.size()); + axisList.addAll(axes); + } + + // -- AnnotatedSpace methods -- + + @Override + public A axis(final int d) { + return axisList.get(d); + } + + @Override + public void axes(final A[] axes) { + for (int d = 0; d < axes.length; d++) { + axes[d] = axis(d); + } + } + + @Override + public void setAxis(final A axis, final int d) { + axisList.set(d, axis); + } + + // -- EuclideanSpace methods -- + + @Override + public int numDimensions() { + return axisList.size(); + } + +} diff --git a/core/src/main/java/net/imglib2/AnnotatedSpace.java b/core/src/main/java/net/imglib2/AnnotatedSpace.java new file mode 100644 index 0000000000..d180817109 --- /dev/null +++ b/core/src/main/java/net/imglib2/AnnotatedSpace.java @@ -0,0 +1,64 @@ +/* + * #%L + * ImgLib2: a general-purpose, multidimensional image processing library. + * %% + * Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia, + * Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves + * Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris, + * Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier, + * Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are + * those of the authors and should not be interpreted as representing official + * policies, either expressed or implied, of any organization. + * #L% + */ + +package net.imglib2; + +/** + * A Euclidean space with associated metadata about each dimension of the space. + * The nature of the metadata is left intentionally open-ended; at the topmost + * level, the {@link Axis} interface provides no additional information about a + * dimensional axis, but it can be extended to do so. + *

+ * One potential use of the {@link Axis} objects is to store calibration and + * unit information (see the {@code imglib2-meta} project), but any desired + * information about the space's dimensions could conceivably be attached. + *

+ * + * @author Curtis Rueden + */ +public interface AnnotatedSpace
extends EuclideanSpace { + + /** Gets the axis associated with the given dimension of the space. */ + A axis(int d); + + /** Copies the space's axes into the given array. */ + void axes(A[] axes); + + /** Sets the dimensional axis associated with the given dimension. */ + void setAxis(A axis, int d); + +} \ No newline at end of file diff --git a/core/src/main/java/net/imglib2/Axis.java b/core/src/main/java/net/imglib2/Axis.java new file mode 100644 index 0000000000..91e738dae2 --- /dev/null +++ b/core/src/main/java/net/imglib2/Axis.java @@ -0,0 +1,56 @@ +/* + * #%L + * ImgLib2: a general-purpose, multidimensional image processing library. + * %% + * Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia, + * Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves + * Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris, + * Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier, + * Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are + * those of the authors and should not be interpreted as representing official + * policies, either expressed or implied, of any organization. + * #L% + */ + +package net.imglib2; + +/** + * A dimensional axis of an {@link AnnotatedSpace}. + *

+ * This interface does not define any explicit API, but serves as an extension + * point for annotated {@link EuclideanSpace}s: subtypes of {@code Axis} can be + * defined to include concepts such as axis names, labels and calibrations, and + * then assigned to the axes of a {@link AnnotatedSpace}. + *

+ *

+ * See the {@code imglib2-meta} project for an example. + *

+ * + * @author Curtis Rueden + */ +public interface Axis { + // NB: Marker interface. +} diff --git a/core/src/main/java/net/imglib2/EuclideanSpace.java b/core/src/main/java/net/imglib2/EuclideanSpace.java index 036b7a1b8a..1ddf6a7b63 100644 --- a/core/src/main/java/net/imglib2/EuclideanSpace.java +++ b/core/src/main/java/net/imglib2/EuclideanSpace.java @@ -38,10 +38,10 @@ package net.imglib2; /** - * + * {Rn}: an N-dimensional Euclidean space. + * * @author Stephan Preibisch * @author Stephan Saalfeld - * @author Stephan Saalfeld */ public interface EuclideanSpace { diff --git a/core/src/main/java/net/imglib2/FinalInterval.java b/core/src/main/java/net/imglib2/FinalInterval.java index 11069910b5..b2bf2389ed 100644 --- a/core/src/main/java/net/imglib2/FinalInterval.java +++ b/core/src/main/java/net/imglib2/FinalInterval.java @@ -47,7 +47,7 @@ public final class FinalInterval extends AbstractInterval { /** - * Creates a {@link AbstractInterval} from another {@link Interval} + * Creates an Interval from another {@link Interval} * * @param interval - another {@link Interval} */ diff --git a/core/src/main/java/net/imglib2/RandomAccessible.java b/core/src/main/java/net/imglib2/RandomAccessible.java index 0901d48808..24ae6e4c07 100644 --- a/core/src/main/java/net/imglib2/RandomAccessible.java +++ b/core/src/main/java/net/imglib2/RandomAccessible.java @@ -50,7 +50,6 @@ * * @author Stephan Saalfeld * @author Tobias Pietzsch - * @author Stephan Saalfeld */ public interface RandomAccessible< T > extends EuclideanSpace { diff --git a/core/src/main/java/net/imglib2/RealRandomAccessible.java b/core/src/main/java/net/imglib2/RealRandomAccessible.java index 110e92df7f..bb3d1851cc 100644 --- a/core/src/main/java/net/imglib2/RealRandomAccessible.java +++ b/core/src/main/java/net/imglib2/RealRandomAccessible.java @@ -43,9 +43,12 @@ *

A function over real space that can create a random access * {@link Sampler}.

* - * + *

If your algorithm takes a RealRandomAccessible, this + * usually means that you expect that the domain is infinite. + * (In contrast to this, {@link RealRandomAccessibleRealInterval}s have a + * finite domain.)

+ * * @author Stephan Saalfeld - * @author Stephan Saalfeld */ public interface RealRandomAccessible< T > extends EuclideanSpace { diff --git a/examples/pom.xml b/examples/pom.xml index 07dccd4a7f..7823324970 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -41,6 +41,11 @@ imglib2-io ${project.version}
+ + ${project.groupId} + imglib2-meta + ${project.version} + ${project.groupId} imglib2-realtransform diff --git a/examples/src/main/java/interactive/InteractiveImageViewerExample.java b/examples/src/main/java/interactive/InteractiveImageViewerExample.java index e3ea4e1575..efad1ad123 100644 --- a/examples/src/main/java/interactive/InteractiveImageViewerExample.java +++ b/examples/src/main/java/interactive/InteractiveImageViewerExample.java @@ -42,11 +42,11 @@ import net.imglib2.RandomAccessible; import net.imglib2.RandomAccessibleInterval; import net.imglib2.display.RealARGBConverter; -import net.imglib2.img.ImgPlus; import net.imglib2.img.array.ArrayImgFactory; import net.imglib2.io.ImgIOException; import net.imglib2.io.ImgOpener; import net.imglib2.meta.CalibratedSpace; +import net.imglib2.meta.ImgPlus; import net.imglib2.realtransform.AffineTransform2D; import net.imglib2.realtransform.AffineTransform3D; import net.imglib2.type.NativeType; @@ -101,8 +101,8 @@ public static < T extends RealType< T > & NativeType< T > > void show( final Ran double yScale = 1; if ( interval instanceof CalibratedSpace ) { - final CalibratedSpace cs = ( CalibratedSpace ) interval; - yScale = cs.calibration( 1 ) / cs.calibration( 0 ); + final CalibratedSpace cs = ( CalibratedSpace ) interval; + yScale = cs.axis( 1 ).calibration() / cs.axis( 0 ).calibration(); if ( Double.isNaN( yScale ) || Double.isInfinite( yScale ) ) yScale = 1; } @@ -130,9 +130,9 @@ else if ( n == 3 ) double zScale = 1; if ( interval instanceof CalibratedSpace ) { - final CalibratedSpace cs = ( CalibratedSpace ) interval; - yScale = cs.calibration( 1 ) / cs.calibration( 0 ); - zScale = cs.calibration( 2 ) / cs.calibration( 0 ); + final CalibratedSpace cs = ( CalibratedSpace ) interval; + yScale = cs.axis( 1 ).calibration() / cs.axis( 0 ).calibration(); + zScale = cs.axis( 2 ).calibration() / cs.axis( 0 ).calibration(); if ( Double.isNaN( yScale ) || Double.isInfinite( yScale ) ) yScale = 1; if ( Double.isNaN( zScale ) || Double.isInfinite( zScale ) ) diff --git a/ij/pom.xml b/ij/pom.xml index f4fafb8e20..e456feb010 100644 --- a/ij/pom.xml +++ b/ij/pom.xml @@ -24,6 +24,11 @@ imglib2 ${project.version} + + ${project.groupId} + imglib2-meta + ${project.version} + @@ -41,7 +46,7 @@ junit junit - 4.8.1 + ${junit.version} test diff --git a/ij/src/main/java/net/imglib2/img/ImagePlusAdapter.java b/ij/src/main/java/net/imglib2/img/ImagePlusAdapter.java index f6203464e2..2bbba9ae0a 100644 --- a/ij/src/main/java/net/imglib2/img/ImagePlusAdapter.java +++ b/ij/src/main/java/net/imglib2/img/ImagePlusAdapter.java @@ -48,6 +48,7 @@ import net.imglib2.img.imageplus.IntImagePlus; import net.imglib2.img.imageplus.ShortImagePlus; import net.imglib2.meta.Axes; +import net.imglib2.meta.ImgPlus; import net.imglib2.type.NativeType; import net.imglib2.type.Type; import net.imglib2.type.numeric.ARGBType; @@ -156,17 +157,17 @@ protected static < T extends NumericType< T > & NativeType< T > > void setAxesFr int currentDim = 2; if (imp.getNChannels() > 1) { - image.setAxis(Axes.CHANNEL, currentDim); + image.axis(currentDim).setType(Axes.CHANNEL); currentDim++; } if (imp.getNSlices() > 1) { - image.setAxis(Axes.Z, currentDim); + image.axis(currentDim).setType(Axes.Z); currentDim++; } if (imp.getNFrames() > 1) { - image.setAxis(Axes.TIME, currentDim); + image.axis(currentDim).setType(Axes.TIME); } } @@ -211,7 +212,9 @@ protected static < T extends NumericType< T > & NativeType< T > > void setCalibr } - image.setCalibration( spacing ); + for (int i = 0; i < spacing.length; i++) { + image.axis(i).setCalibration(spacing[i]); + } } public static ByteImagePlus wrapByte( final ImagePlus imp ) diff --git a/ij/src/main/java/net/imglib2/img/display/imagej/ImageJFunctions.java b/ij/src/main/java/net/imglib2/img/display/imagej/ImageJFunctions.java index cf28970ff6..3a0dba1740 100644 --- a/ij/src/main/java/net/imglib2/img/display/imagej/ImageJFunctions.java +++ b/ij/src/main/java/net/imglib2/img/display/imagej/ImageJFunctions.java @@ -53,8 +53,8 @@ import net.imglib2.display.RealUnsignedShortConverter; import net.imglib2.img.ImagePlusAdapter; import net.imglib2.img.Img; -import net.imglib2.img.ImgPlus; import net.imglib2.meta.Axes; +import net.imglib2.meta.ImgPlus; import net.imglib2.type.NativeType; import net.imglib2.type.numeric.ARGBType; import net.imglib2.type.numeric.ComplexType; @@ -175,24 +175,24 @@ else if ( ComplexType.class.isInstance( t ) ) final ImgPlus imgplus = (ImgPlus) img; final Calibration impcal = target.getCalibration(); - final int xaxis = imgplus.getAxisIndex(Axes.X); + final int xaxis = imgplus.dimensionIndex(Axes.X); if (xaxis >= 0) { - impcal.pixelWidth = imgplus.calibration(xaxis); + impcal.pixelWidth = imgplus.axis(xaxis).calibration(); } - final int yaxis = imgplus.getAxisIndex(Axes.Y); + final int yaxis = imgplus.dimensionIndex(Axes.Y); if (yaxis >= 0) { - impcal.pixelHeight = imgplus.calibration(yaxis); + impcal.pixelHeight = imgplus.axis(yaxis).calibration(); } - final int zaxis = imgplus.getAxisIndex(Axes.Z); + final int zaxis = imgplus.dimensionIndex(Axes.Z); if (zaxis >= 0) { - impcal.pixelDepth = imgplus.calibration(zaxis); + impcal.pixelDepth = imgplus.axis(zaxis).calibration(); } - final int taxis = imgplus.getAxisIndex(Axes.TIME); + final int taxis = imgplus.dimensionIndex(Axes.TIME); if (taxis >= 0) { - impcal.frameInterval = imgplus.calibration(taxis); + impcal.frameInterval = imgplus.axis(taxis).calibration(); } target.setTitle( imgplus.getName() ); } diff --git a/ij/src/test/java/net/imglib2/img/ImagePlusAdapterTest.java b/ij/src/test/java/net/imglib2/img/ImagePlusAdapterTest.java index 620913ea37..c965a03c8a 100644 --- a/ij/src/test/java/net/imglib2/img/ImagePlusAdapterTest.java +++ b/ij/src/test/java/net/imglib2/img/ImagePlusAdapterTest.java @@ -42,6 +42,7 @@ import ij.gui.NewImage; import ij.measure.Calibration; import net.imglib2.meta.Axes; +import net.imglib2.meta.ImgPlus; import net.imglib2.type.NativeType; import net.imglib2.type.numeric.NumericType; @@ -141,12 +142,12 @@ public void testDimensionality() { if (d < expectedNumDimensions && img.axis(d).equals(Axes.CHANNEL)) { // Then the calibration should be 1, - assertEquals( 1f, img.calibration(skipDim), Float.MIN_VALUE); + assertEquals( 1f, img.axis(skipDim).calibration(), Float.MIN_VALUE); } else { // otherwise it should be what we set. - assertEquals( calibration[i][d], img.calibration(skipDim), Float.MIN_VALUE); + assertEquals( calibration[i][d], img.axis(skipDim).calibration(), Float.MIN_VALUE); } skipDim++; diff --git a/io/pom.xml b/io/pom.xml index 21f0e17397..a20bdba160 100644 --- a/io/pom.xml +++ b/io/pom.xml @@ -19,6 +19,11 @@ imglib2 ${project.version} + + ${project.groupId} + imglib2-meta + ${project.version} + ${bio-formats.groupId} @@ -46,7 +51,7 @@ junit junit - 4.8.1 + ${junit.version} test diff --git a/io/src/main/java/net/imglib2/io/ImgIOUtils.java b/io/src/main/java/net/imglib2/io/ImgIOUtils.java index fc678e1547..23a5397b9d 100644 --- a/io/src/main/java/net/imglib2/io/ImgIOUtils.java +++ b/io/src/main/java/net/imglib2/io/ImgIOUtils.java @@ -49,7 +49,6 @@ import loci.formats.FormatTools; import net.imglib2.img.Img; -import net.imglib2.img.ImgPlus; import net.imglib2.img.basictypeaccess.PlanarAccess; import net.imglib2.img.basictypeaccess.array.ArrayDataAccess; import net.imglib2.img.basictypeaccess.array.ByteArray; @@ -59,6 +58,7 @@ import net.imglib2.img.basictypeaccess.array.IntArray; import net.imglib2.img.basictypeaccess.array.LongArray; import net.imglib2.img.basictypeaccess.array.ShortArray; +import net.imglib2.meta.ImgPlus; import net.imglib2.type.numeric.RealType; import net.imglib2.type.numeric.integer.ByteType; import net.imglib2.type.numeric.integer.IntType; diff --git a/io/src/main/java/net/imglib2/io/ImgOpener.java b/io/src/main/java/net/imglib2/io/ImgOpener.java index 5255ac2a89..a76b9212ec 100644 --- a/io/src/main/java/net/imglib2/io/ImgOpener.java +++ b/io/src/main/java/net/imglib2/io/ImgOpener.java @@ -65,7 +65,6 @@ import net.imglib2.exception.IncompatibleTypeException; import net.imglib2.img.Img; import net.imglib2.img.ImgFactory; -import net.imglib2.img.ImgPlus; import net.imglib2.img.array.ArrayImg; import net.imglib2.img.array.ArrayImgFactory; import net.imglib2.img.basictypeaccess.PlanarAccess; @@ -75,6 +74,7 @@ import net.imglib2.img.planar.PlanarImgFactory; import net.imglib2.meta.Axes; import net.imglib2.meta.AxisType; +import net.imglib2.meta.ImgPlus; import net.imglib2.type.NativeType; import net.imglib2.type.Type; import net.imglib2.type.numeric.RealType; diff --git a/io/src/main/java/net/imglib2/io/ImgSaver.java b/io/src/main/java/net/imglib2/io/ImgSaver.java index 6b63d67456..90ec84d5e6 100644 --- a/io/src/main/java/net/imglib2/io/ImgSaver.java +++ b/io/src/main/java/net/imglib2/io/ImgSaver.java @@ -60,11 +60,11 @@ import net.imglib2.exception.ImgLibException; import net.imglib2.exception.IncompatibleTypeException; import net.imglib2.img.Img; -import net.imglib2.img.ImgPlus; import net.imglib2.img.basictypeaccess.PlanarAccess; import net.imglib2.img.planar.PlanarImg; import net.imglib2.meta.Axes; import net.imglib2.meta.AxisType; +import net.imglib2.meta.ImgPlus; import net.imglib2.type.NativeType; import net.imglib2.type.numeric.RealType; import ome.xml.model.primitives.PositiveFloat; @@ -115,8 +115,7 @@ public & NativeType> boolean isCompressible( final ImgPlus img) { - final AxisType[] axes = new AxisType[img.numDimensions()]; - img.axes(axes); + final AxisType[] axes = getAxes(img); final long[] axisLengths = new long[5]; final long[] oldLengths = new long[img.numDimensions()]; @@ -644,8 +643,7 @@ private & NativeType> void populateMeta( // TODO is there some way to consolidate this with the isCompressible // method? - final AxisType[] axes = new AxisType[img.numDimensions()]; - img.axes(axes); + final AxisType[] axes = getAxes(img); String dimOrder = ""; @@ -660,15 +658,15 @@ private & NativeType> void populateMeta( PositiveFloat physicalSize = null; if (Axes.X.equals(axis)) { - physicalSize = new PositiveFloat(img.calibration(i)); + physicalSize = new PositiveFloat(img.axis(i).calibration()); meta.setPixelsPhysicalSizeX(physicalSize, w.getSeries()); } else if (Axes.Y.equals(axis)) { - physicalSize = new PositiveFloat(img.calibration(i)); + physicalSize = new PositiveFloat(img.axis(i).calibration()); meta.setPixelsPhysicalSizeY(physicalSize, w.getSeries()); } else if (Axes.Z.equals(axis)) { - physicalSize = new PositiveFloat(img.calibration(i)); + physicalSize = new PositiveFloat(img.axis(i).calibration()); meta.setPixelsPhysicalSizeZ(physicalSize, w.getSeries()); } } @@ -713,6 +711,16 @@ else if (Axes.Z.equals(axis)) { } } + private & NativeType> AxisType[] getAxes( + final ImgPlus img) + { + final AxisType[] axes = new AxisType[img.numDimensions()]; + for (int d = 0; d < axes.length; d++) { + axes[d] = img.axis(d).type(); + } + return axes; + } + private OMEXMLService createOMEXMLService() { try { return new ServiceFactory().getInstance(OMEXMLService.class); diff --git a/io/src/test/java/net/imglib2/io/ReadImage.java b/io/src/test/java/net/imglib2/io/ReadImage.java index dbb8a53b35..cbf891ab3d 100644 --- a/io/src/test/java/net/imglib2/io/ReadImage.java +++ b/io/src/test/java/net/imglib2/io/ReadImage.java @@ -41,9 +41,9 @@ import net.imglib2.exception.IncompatibleTypeException; import net.imglib2.img.Img; import net.imglib2.img.ImgFactory; -import net.imglib2.img.ImgPlus; import net.imglib2.img.array.ArrayImgFactory; import net.imglib2.img.planar.PlanarImgFactory; +import net.imglib2.meta.ImgPlus; import net.imglib2.type.NativeType; import net.imglib2.type.numeric.RealType; import net.imglib2.type.numeric.real.FloatType; diff --git a/meta/pom.xml b/meta/pom.xml new file mode 100644 index 0000000000..80e92fb900 --- /dev/null +++ b/meta/pom.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + + + net.imglib2 + pom-imglib2 + 2.0.0-SNAPSHOT + + + imglib2-meta + + ImgLib2 Metadata Extensions + ImgLib2 classes which provide additional metadata associated with N-dimensional image data structures. + + + + ${project.groupId} + imglib2 + ${project.version} + + + + junit + junit + ${junit.version} + test + + + + + ${basedir}/../.. + + + + + + maven-jar-plugin + + + + net.imglib2.meta + + + + + + + + + + + imagej.releases + http://maven.imagej.net/content/repositories/releases + + + imagej.snapshots + http://maven.imagej.net/content/repositories/snapshots + + + + diff --git a/meta/src/main/java/net/imglib2/meta/AbstractCalibratedSpace.java b/meta/src/main/java/net/imglib2/meta/AbstractCalibratedSpace.java new file mode 100644 index 0000000000..79fe35ea9d --- /dev/null +++ b/meta/src/main/java/net/imglib2/meta/AbstractCalibratedSpace.java @@ -0,0 +1,119 @@ +/* + * #%L + * ImgLib2: a general-purpose, multidimensional image processing library. + * %% + * Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia, + * Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves + * Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris, + * Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier, + * Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are + * those of the authors and should not be interpreted as representing official + * policies, either expressed or implied, of any organization. + * #L% + */ + +package net.imglib2.meta; + +import java.util.List; + +/** + * Abstract base class for {@link CalibratedSpace}. + * + * @author Curtis Rueden + */ +public abstract class AbstractCalibratedSpace + extends + AbstractTypedSpace implements CalibratedSpace +{ + + private final double[] calibration; + + public AbstractCalibratedSpace(final int numDims) { + super(numDims); + calibration = new double[numDims]; + for (int i = 0; i < calibration.length; i++) + calibration[i] = Double.NaN; + } + + public AbstractCalibratedSpace(final A... axes) { + super(axes); + calibration = new double[axes.length]; + for (int i = 0; i < calibration.length; i++) + calibration[i] = Double.NaN; + } + + public AbstractCalibratedSpace(final List axes) { + super(axes); + calibration = new double[axes.size()]; + for (int i = 0; i < calibration.length; i++) + calibration[i] = Double.NaN; + } + + @Override + public double calibration(int d) { + return calibration[d]; + } + + @Override + public void calibration(double[] cal) { + for (int i = 0; i < cal.length; i++) + cal[i] = calibration(i); + } + + @Override + public void calibration(float[] cal) { + for (int i = 0; i < cal.length; i++) + cal[i] = (float) calibration(i); + } + + @Override + public void setCalibration(double cal, int d) { + calibration[d] = cal; + } + + @Override + public void setCalibration(double[] cal) { + for (int i = 0; i < cal.length; i++) + setCalibration(cal[i], i); + } + + @Override + public void setCalibration(float[] cal) { + for (int i = 0; i < cal.length; i++) + setCalibration(cal[i], i); + } + + @Override + public String unit(int d) { + return axis(d).unit(); + } + + @Override + public void setUnit(String unit, int d) { + axis(d).setUnit(unit); + } + +} diff --git a/meta/src/main/java/net/imglib2/meta/AbstractTypedSpace.java b/meta/src/main/java/net/imglib2/meta/AbstractTypedSpace.java new file mode 100644 index 0000000000..51be10ca6c --- /dev/null +++ b/meta/src/main/java/net/imglib2/meta/AbstractTypedSpace.java @@ -0,0 +1,75 @@ +/* + * #%L + * ImgLib2: a general-purpose, multidimensional image processing library. + * %% + * Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia, + * Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves + * Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris, + * Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier, + * Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are + * those of the authors and should not be interpreted as representing official + * policies, either expressed or implied, of any organization. + * #L% + */ + +package net.imglib2.meta; + +import java.util.List; + +import net.imglib2.AbstractAnnotatedSpace; + +/** + * Abstract base class for {@link TypedSpace}. + * + * @author Curtis Rueden + */ +public abstract class AbstractTypedSpace extends + AbstractAnnotatedSpace implements TypedSpace +{ + + public AbstractTypedSpace(final int numDims) { + super(numDims); + } + + public AbstractTypedSpace(final A... axes) { + super(axes); + } + + public AbstractTypedSpace(final List axes) { + super(axes); + } + + // -- TypedSpace methods -- + + @Override + public int dimensionIndex(final AxisType axisType) { + for (int d=0; dFrequency dimensional type, representing a dimension * consisting of frequencies. */ - FREQUENCY("Frequency"), - - /** Represents an unknown dimensional type. */ - UNKNOWN("Unknown"); + FREQUENCY("Frequency"); private static Hashtable axes = new Hashtable(); @@ -127,14 +118,21 @@ public enum Axes implements AxisType { public synchronized static AxisType get(final String label) { AxisType axis = axes.get(label); if (axis == null) { - axis = new CustomAxisType(label); + axis = new CustomType(label); axes.put(label, axis); } return axis; } - public static boolean isXY(final AxisType dimLabel) { - return dimLabel == Axes.X || dimLabel == Axes.Y; + /** + * Gets an "unknown" axis type. + *

+ * Always returns a new object, which is not part of the extended enumeration. + * In this way, two unknown axis types are never equal. + *

+ */ + public static AxisType unknown() { + return new CustomType("Unknown"); } private String label; @@ -143,7 +141,7 @@ private Axes(final String label) { this.label = label; } - // -- Axis methods -- + // -- AxisType methods -- @Override public String getLabel() { @@ -171,14 +169,20 @@ public String toString() { /** * A custom dimensional axis type, for describing the dimensional axes of a - * {@link CalibratedSpace} object (such as an {@link ImgPlus}). + * {@link TypedSpace} object. */ - public static class CustomAxisType implements AxisType { + public static class CustomType implements AxisType { private final String label; + private final boolean spatial; - public CustomAxisType(final String label) { + public CustomType(final String label) { + this(label, false); + } + + public CustomType(final String label, final boolean spatial) { this.label = label; + this.spatial = spatial; } // -- Axis methods -- @@ -195,7 +199,7 @@ public boolean isXY() { @Override public boolean isSpatial() { - return false; + return spatial; } // -- Object methods -- diff --git a/core/src/main/java/net/imglib2/meta/AxisType.java b/meta/src/main/java/net/imglib2/meta/AxisType.java similarity index 91% rename from core/src/main/java/net/imglib2/meta/AxisType.java rename to meta/src/main/java/net/imglib2/meta/AxisType.java index 4bd68d14cc..b48f3ce8cb 100644 --- a/core/src/main/java/net/imglib2/meta/AxisType.java +++ b/meta/src/main/java/net/imglib2/meta/AxisType.java @@ -37,16 +37,11 @@ package net.imglib2.meta; -import net.imglib2.img.ImgPlus; - /** * A dimensional axis type, for describing the dimensions of a - * {@link CalibratedSpace} object (such as an {@link ImgPlus}). + * {@link TypedSpace}. * - * - * @author Stephan Preibisch - * @author Stephan Saalfeld - * @author Curtis Rueden ctrueden at wisc.edu + * @author Curtis Rueden */ public interface AxisType { diff --git a/meta/src/main/java/net/imglib2/meta/CalibratedAxis.java b/meta/src/main/java/net/imglib2/meta/CalibratedAxis.java new file mode 100644 index 0000000000..b2e4bbdb15 --- /dev/null +++ b/meta/src/main/java/net/imglib2/meta/CalibratedAxis.java @@ -0,0 +1,60 @@ +/* + * #%L + * ImgLib2: a general-purpose, multidimensional image processing library. + * %% + * Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia, + * Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves + * Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris, + * Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier, + * Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are + * those of the authors and should not be interpreted as representing official + * policies, either expressed or implied, of any organization. + * #L% + */ + +package net.imglib2.meta; + +/** + * An axis with an associated {@link AxisType}, unit and calibration. + * + * @author Curtis Rueden + * @see TypedAxis + */ +public interface CalibratedAxis extends TypedAxis { + + /** Gets the dimension's unit. */ + String unit(); + + /** Gets the dimension's calibration value. */ + double calibration(); + + /** Sets the dimension's unit. */ + void setUnit(String unit); + + /** Sets the dimension's image calibration. */ + void setCalibration(double cal); + +} diff --git a/meta/src/main/java/net/imglib2/meta/CalibratedSpace.java b/meta/src/main/java/net/imglib2/meta/CalibratedSpace.java new file mode 100644 index 0000000000..78118a1eb2 --- /dev/null +++ b/meta/src/main/java/net/imglib2/meta/CalibratedSpace.java @@ -0,0 +1,73 @@ +/* + * #%L + * ImgLib2: a general-purpose, multidimensional image processing library. + * %% + * Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia, + * Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves + * Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris, + * Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier, + * Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are + * those of the authors and should not be interpreted as representing official + * policies, either expressed or implied, of any organization. + * #L% + */ + +package net.imglib2.meta; + +/** + * A Euclidean space whose dimensions have units and calibrations. + * + * @author Curtis Rueden + * @see CalibratedAxis + */ +public interface CalibratedSpace
extends + TypedSpace +{ + /** Gets the space's physical calibration at the given dimension. */ + double calibration(int d); + + /** Copies the space's physical calibration into the given array. */ + void calibration(double[] cal); + + /** Copies the space's physical calibration into the given array. */ + void calibration(float[] cal); + + /** Sets the physical calibration for the given dimension. */ + void setCalibration(double cal, int d); + + /** Sets the physical calibration for all dimensions. */ + void setCalibration(double[] cal); + + /** Sets the physical calibration for all dimensions. */ + void setCalibration(float[] cal); + + /** Gets the physical unit for the given dimension. */ + String unit(int d); + + /** Sets the physical unit for the given dimension. */ + void setUnit(String unit, int d); + +} diff --git a/meta/src/main/java/net/imglib2/meta/CombinedRealInterval.java b/meta/src/main/java/net/imglib2/meta/CombinedRealInterval.java new file mode 100644 index 0000000000..9f3ffc2abf --- /dev/null +++ b/meta/src/main/java/net/imglib2/meta/CombinedRealInterval.java @@ -0,0 +1,145 @@ +/* + * #%L + * ImgLib2: a general-purpose, multidimensional image processing library. + * %% + * Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia, + * Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves + * Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris, + * Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier, + * Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are + * those of the authors and should not be interpreted as representing official + * policies, either expressed or implied, of any organization. + * #L% + */ + +package net.imglib2.meta; + +import java.util.HashMap; + +import net.imglib2.RealInterval; +import net.imglib2.RealPositionable; + +/** + * A {@code CombinedRealInterval} is a {@link RealInterval} (specifically a + * {@link TypedRealInterval}) which is a union of other + * {@link TypedRealInterval}s. Dimensions with the same {@link AxisType} are + * combined; see {@link CombinedSpace} for further details. + *

+ * The {@link #realMin} of a dimension will be the lower bound of all + * constituent interval {@link #realMin}s for dimensions of that type. + * Similarly, the {@link #realMax} of a dimension will be the upper bound of all + * constituent interval {@link #realMax}s. + *

+ *

+ * In the case of {@link TypedUnitRealInterval}s, no reconciliation is done to + * ensure that overlapping axes have equal units or calibrations; it is assumed + * that each axis has already been standardized to a common calibration via the + * {@link CalibratedViews#recalibrate} method. + *

+ * + * @author Curtis Rueden + */ +public class CombinedRealInterval
> + extends CombinedSpace implements TypedRealInterval +{ + + /** Combined min and max values for each axis. */ + private final HashMap minMax = + new HashMap(); + + // -- CombinedRealInterval methods -- + + @Override + public void update() { + minMax.clear(); + super.update(); + for (final TypedRealInterval interval : this) { + for (int d = 0; d < interval.numDimensions(); d++) { + final AxisType axisType = interval.axis(d).type(); + if (!minMax.containsKey(axisType)) { + // new axis; add to the hash + minMax.put(axisType, new MinMax()); + } + final MinMax mm = minMax.get(axisType); + mm.expand(interval.realMin(d), interval.realMax(d)); + } + } + } + + // -- RealInterval methods -- + + @Override + public double realMin(final int d) { + return minMax.get(axis(d).type()).min(); + } + + @Override + public void realMin(final double[] min) { + for (int i = 0; i < min.length; i++) + min[i] = realMin(i); + } + + @Override + public void realMin(final RealPositionable min) { + for (int i = 0; i < min.numDimensions(); i++) + min.setPosition(realMin(i), i); + } + + @Override + public double realMax(final int d) { + return minMax.get(axis(d).type()).max(); + } + + @Override + public void realMax(final double[] max) { + for (int i = 0; i < max.length; i++) + max[i] = realMax(i); + } + + @Override + public void realMax(final RealPositionable max) { + for (int i = 0; i < max.numDimensions(); i++) + max.setPosition(realMax(i), i); + } + + // -- Helper classes -- + + protected class MinMax { + + private double minMin = Double.POSITIVE_INFINITY; + private double maxMax = Double.NEGATIVE_INFINITY; + + public void expand(final double min, final double max) { + if (min < minMin) minMin = min; + if (max > maxMax) maxMax = max; + } + + public double min() { return minMin; } + public double max() { return maxMax; } + + } + +} diff --git a/meta/src/main/java/net/imglib2/meta/CombinedSpace.java b/meta/src/main/java/net/imglib2/meta/CombinedSpace.java new file mode 100644 index 0000000000..ebd89d2b40 --- /dev/null +++ b/meta/src/main/java/net/imglib2/meta/CombinedSpace.java @@ -0,0 +1,127 @@ +/* + * #%L + * ImgLib2: a general-purpose, multidimensional image processing library. + * %% + * Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia, + * Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves + * Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris, + * Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier, + * Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are + * those of the authors and should not be interpreted as representing official + * policies, either expressed or implied, of any organization. + * #L% + */ + +package net.imglib2.meta; + +import java.util.ArrayList; + +import net.imglib2.EuclideanSpace; + +/** + * A {@code CombinedSpace} is a {@link EuclideanSpace} (specifically a + * {@link TypedSpace}) which is a union of other {@link TypedSpace}s. Common + * axes are merged as appropriate by matching the {@link AxisType}s of each + * {@link TypedAxis}. + *

+ * For example, combining three spaces with dimensions (X, Y, Z, CHANNEL), + * (X, Y, CHANNEL, TIME) and (X, Z, LIFETIME, TIME) will result in a coordinate + * space with dimensions (X, Y, Z, CHANNEL, TIME, LIFETIME). + *

+ * + * @author Curtis Rueden + */ +public class CombinedSpace
> + extends ArrayList implements TypedSpace +{ + + /** List of axis types for the combined space. */ + private final ArrayList axisTypes = new ArrayList(); + + // -- CombinedSpace methods -- + + /** Recomputes the combined space based on its current constituents. */ + public void update() { + axisTypes.clear(); + for (final TypedSpace space : this) { + for (int d = 0; d < space.numDimensions(); d++) { + final AxisType axisType = space.axis(d).type(); + if (!axisTypes.contains(axisType)) { + // new axis; add to the list + axisTypes.add(axisType); + } + } + } + } + + // -- TypedSpace methods -- + + @Override + public int dimensionIndex(final AxisType axis) { + return axisTypes.indexOf(axis); + } + + // -- AnnotatedSpace methods -- + + @Override + public A axis(final int d) { + final AxisType type = axisTypes.get(d); + + // find the first axis of a constituent space that matches the type + for (final TypedSpace space : this) { + final int id = space.dimensionIndex(type); + if (id < 0) continue; + return space.axis(id); + } + throw new IllegalStateException("No compatible constituent space"); + } + + @Override + public void axes(final A[] axes) { + for (int i = 0; i < axes.length; i++) + axes[i] = axis(i); + } + + @Override + public void setAxis(final A axis, final int d) { + final AxisType type = axisTypes.get(d); + + // assign the axis to all constituent spaces of matching type + for (final TypedSpace space : this) { + final int id = space.dimensionIndex(type); + if (id < 0) continue; + space.setAxis(axis, id); + } + } + + // -- EuclideanSpace methods -- + + @Override + public int numDimensions() { + return axisTypes.size(); + } + +} diff --git a/meta/src/main/java/net/imglib2/meta/DefaultCalibratedAxis.java b/meta/src/main/java/net/imglib2/meta/DefaultCalibratedAxis.java new file mode 100644 index 0000000000..8ab4a132a6 --- /dev/null +++ b/meta/src/main/java/net/imglib2/meta/DefaultCalibratedAxis.java @@ -0,0 +1,90 @@ +/* + * #%L + * ImgLib2: a general-purpose, multidimensional image processing library. + * %% + * Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia, + * Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves + * Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris, + * Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier, + * Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are + * those of the authors and should not be interpreted as representing official + * policies, either expressed or implied, of any organization. + * #L% + */ + +package net.imglib2.meta; + +/** + * Simple, default {@link CalibratedAxis} implementation. + * + * @author Curtis Rueden + */ +public class DefaultCalibratedAxis extends DefaultTypedAxis implements + CalibratedAxis +{ + + private String unit; + private double cal; + + public DefaultCalibratedAxis() { + this(Axes.unknown()); + } + + public DefaultCalibratedAxis(final AxisType type) { + this(type, "pixel", 1); + } + + public DefaultCalibratedAxis(final AxisType type, final String unit, + final double cal) + { + super(type); + setUnit(unit); + setCalibration(cal); + } + + // -- UnitAxis methods -- + + @Override + public double calibration() { + return cal; + } + + @Override + public String unit() { + return unit; + } + + @Override + public void setCalibration(final double cal) { + this.cal = cal; + } + + @Override + public void setUnit(final String unit) { + this.unit = unit; + } + +} diff --git a/meta/src/main/java/net/imglib2/meta/DefaultCalibratedSpace.java b/meta/src/main/java/net/imglib2/meta/DefaultCalibratedSpace.java new file mode 100644 index 0000000000..eabf591bf3 --- /dev/null +++ b/meta/src/main/java/net/imglib2/meta/DefaultCalibratedSpace.java @@ -0,0 +1,66 @@ +/* + * #%L + * ImgLib2: a general-purpose, multidimensional image processing library. + * %% + * Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia, + * Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves + * Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris, + * Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier, + * Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are + * those of the authors and should not be interpreted as representing official + * policies, either expressed or implied, of any organization. + * #L% + */ + +package net.imglib2.meta; + +import java.util.List; + +/** + * Simple, default {@link CalibratedSpace} implementation. + * + * @author Curtis Rueden + */ +public class DefaultCalibratedSpace extends + AbstractCalibratedSpace +{ + + public DefaultCalibratedSpace(final int numDims) { + super(numDims); + for (int d = 0; d < numDims; d++) { + setAxis(new DefaultCalibratedAxis(), d); + } + } + + public DefaultCalibratedSpace(final CalibratedAxis... axes) { + super(axes); + } + + public DefaultCalibratedSpace(final List axes) { + super(axes); + } + +} diff --git a/ops/src/main/java/net/imglib2/ops/util/metadata/NamedImpl.java b/meta/src/main/java/net/imglib2/meta/DefaultNamed.java similarity index 91% rename from ops/src/main/java/net/imglib2/ops/util/metadata/NamedImpl.java rename to meta/src/main/java/net/imglib2/meta/DefaultNamed.java index ce19606eb5..9b3982f644 100644 --- a/ops/src/main/java/net/imglib2/ops/util/metadata/NamedImpl.java +++ b/meta/src/main/java/net/imglib2/meta/DefaultNamed.java @@ -35,23 +35,22 @@ * #L% */ -package net.imglib2.ops.util.metadata; - -import net.imglib2.meta.Named; +package net.imglib2.meta; /** + * A simple, default implementation of {@link Named}. * * @author Martin Horn (University of Konstanz) */ -public class NamedImpl implements Named { +public class DefaultNamed implements Named { private String m_name = ""; - public NamedImpl() { + public DefaultNamed() { } - public NamedImpl(String name) { + public DefaultNamed(String name) { m_name = name; } @@ -60,7 +59,7 @@ public NamedImpl(String name) { * * @param name */ - public NamedImpl(Named name) { + public DefaultNamed(Named name) { m_name = name.getName(); } diff --git a/ops/src/main/java/net/imglib2/ops/util/metadata/CalibratedSpaceImpl.java b/meta/src/main/java/net/imglib2/meta/DefaultOldCalibratedSpace.java similarity index 87% rename from ops/src/main/java/net/imglib2/ops/util/metadata/CalibratedSpaceImpl.java rename to meta/src/main/java/net/imglib2/meta/DefaultOldCalibratedSpace.java index 562d146996..3615ffe3ec 100644 --- a/ops/src/main/java/net/imglib2/ops/util/metadata/CalibratedSpaceImpl.java +++ b/meta/src/main/java/net/imglib2/meta/DefaultOldCalibratedSpace.java @@ -35,30 +35,30 @@ * #L% */ -package net.imglib2.ops.util.metadata; +package net.imglib2.meta; import java.util.Arrays; -import net.imglib2.meta.Axes; -import net.imglib2.meta.AxisType; -import net.imglib2.meta.CalibratedSpace; - /** + * A simple, default implementation of {@link OldCalibratedSpace}. + * * @author Martin Horn (University of Konstanz) + * @deprecated Use {@link DefaultCalibratedSpace}. */ -public class CalibratedSpaceImpl implements CalibratedSpace { +@Deprecated +public class DefaultOldCalibratedSpace implements OldCalibratedSpace { private final AxisType[] m_axes; private final double[] m_cal; - public CalibratedSpaceImpl(int numDims) { + public DefaultOldCalibratedSpace(int numDims) { m_axes = new AxisType[numDims]; - Arrays.fill(m_axes, Axes.UNKNOWN); + Arrays.fill(m_axes, Axes.unknown()); m_cal = new double[numDims]; } - public CalibratedSpaceImpl(String... axisLabels) { + public DefaultOldCalibratedSpace(String... axisLabels) { m_axes = new AxisType[axisLabels.length]; for (int i = 0; i < m_axes.length; i++) { m_axes[i] = Axes.get(axisLabels[i]); @@ -66,12 +66,12 @@ public CalibratedSpaceImpl(String... axisLabels) { m_cal = new double[axisLabels.length]; } - public CalibratedSpaceImpl(AxisType[] axes, double[] calibration) { + public DefaultOldCalibratedSpace(AxisType[] axes, double[] calibration) { m_axes = axes; m_cal = calibration; } - public CalibratedSpaceImpl(CalibratedSpace axes) { + public DefaultOldCalibratedSpace(OldCalibratedSpace axes) { m_axes = new AxisType[axes.numDimensions()]; m_cal = new double[axes.numDimensions()]; axes.axes(m_axes); @@ -79,7 +79,7 @@ public CalibratedSpaceImpl(CalibratedSpace axes) { } - public CalibratedSpaceImpl(String[] axisLabels, double[] calibration) { + public DefaultOldCalibratedSpace(String[] axisLabels, double[] calibration) { m_axes = new AxisType[axisLabels.length]; m_cal = calibration.clone(); diff --git a/ops/src/main/java/net/imglib2/ops/util/metadata/SourcedImpl.java b/meta/src/main/java/net/imglib2/meta/DefaultSourced.java similarity index 90% rename from ops/src/main/java/net/imglib2/ops/util/metadata/SourcedImpl.java rename to meta/src/main/java/net/imglib2/meta/DefaultSourced.java index 895e0e16b4..b8cf81f596 100644 --- a/ops/src/main/java/net/imglib2/ops/util/metadata/SourcedImpl.java +++ b/meta/src/main/java/net/imglib2/meta/DefaultSourced.java @@ -35,25 +35,25 @@ * #L% */ -package net.imglib2.ops.util.metadata; - -import net.imglib2.meta.Sourced; +package net.imglib2.meta; /** + * A simple, default implementation of {@link Sourced}. + * * @author Christian Dietz (University of Konstanz) */ -public class SourcedImpl implements Sourced { +public class DefaultSourced implements Sourced { private String m_source = ""; - public SourcedImpl() { + public DefaultSourced() { } - public SourcedImpl(String source) { + public DefaultSourced(String source) { m_source = source; } - public SourcedImpl(Sourced sourced) { + public DefaultSourced(Sourced sourced) { m_source = sourced.getSource(); } diff --git a/meta/src/main/java/net/imglib2/meta/DefaultTypedAxis.java b/meta/src/main/java/net/imglib2/meta/DefaultTypedAxis.java new file mode 100644 index 0000000000..50e64efe03 --- /dev/null +++ b/meta/src/main/java/net/imglib2/meta/DefaultTypedAxis.java @@ -0,0 +1,69 @@ +/* + * #%L + * ImgLib2: a general-purpose, multidimensional image processing library. + * %% + * Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia, + * Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves + * Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris, + * Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier, + * Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are + * those of the authors and should not be interpreted as representing official + * policies, either expressed or implied, of any organization. + * #L% + */ + +package net.imglib2.meta; + +/** + * Simple, default {@link TypedAxis} implementation. + * + * @author Curtis Rueden + */ +public class DefaultTypedAxis implements TypedAxis { + + private AxisType type; + + public DefaultTypedAxis() { + this(Axes.unknown()); + } + + public DefaultTypedAxis(final AxisType type) { + setType(type); + } + + // -- TypedAxis methods -- + + @Override + public AxisType type() { + return type; + } + + @Override + public void setType(AxisType type) { + this.type = type; + } + +} diff --git a/meta/src/main/java/net/imglib2/meta/DefaultTypedSpace.java b/meta/src/main/java/net/imglib2/meta/DefaultTypedSpace.java new file mode 100644 index 0000000000..8aae7d3ca8 --- /dev/null +++ b/meta/src/main/java/net/imglib2/meta/DefaultTypedSpace.java @@ -0,0 +1,64 @@ +/* + * #%L + * ImgLib2: a general-purpose, multidimensional image processing library. + * %% + * Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia, + * Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves + * Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris, + * Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier, + * Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are + * those of the authors and should not be interpreted as representing official + * policies, either expressed or implied, of any organization. + * #L% + */ + +package net.imglib2.meta; + +import java.util.List; + +/** + * Simple, default {@link TypedSpace} implementation. + * + * @author Curtis Rueden + */ +public class DefaultTypedSpace extends AbstractTypedSpace { + + public DefaultTypedSpace(final int numDims) { + super(numDims); + for (int d = 0; d < numDims; d++) { + setAxis(new DefaultTypedAxis(), d); + } + } + + public DefaultTypedSpace(final TypedAxis... axes) { + super(axes); + } + + public DefaultTypedSpace(final List axes) { + super(axes); + } + +} diff --git a/core/src/main/java/net/imglib2/meta/ImageMetadata.java b/meta/src/main/java/net/imglib2/meta/ImageMetadata.java similarity index 100% rename from core/src/main/java/net/imglib2/meta/ImageMetadata.java rename to meta/src/main/java/net/imglib2/meta/ImageMetadata.java diff --git a/core/src/main/java/net/imglib2/img/ImgPlus.java b/meta/src/main/java/net/imglib2/meta/ImgPlus.java similarity index 76% rename from core/src/main/java/net/imglib2/img/ImgPlus.java rename to meta/src/main/java/net/imglib2/meta/ImgPlus.java index 9b29011c8c..8c13a5f502 100644 --- a/core/src/main/java/net/imglib2/img/ImgPlus.java +++ b/meta/src/main/java/net/imglib2/meta/ImgPlus.java @@ -35,7 +35,7 @@ * #L% */ -package net.imglib2.img; +package net.imglib2.meta; import java.util.ArrayList; import java.util.Iterator; @@ -47,20 +47,18 @@ import net.imglib2.RandomAccess; import net.imglib2.RealPositionable; import net.imglib2.display.ColorTable; -import net.imglib2.meta.Axes; -import net.imglib2.meta.AxisType; -import net.imglib2.meta.Metadata; +import net.imglib2.img.Img; +import net.imglib2.img.ImgFactory; /** * A simple container for storing an {@link Img} together with its metadata. * Metadata includes name, dimensional axes and calibration information. * - * - * @author Stephan Preibisch - * @author Stephan Saalfeld - * @author Curtis Rueden ctrueden at wisc.edu + * @author Curtis Rueden */ -public class ImgPlus implements Img, Metadata { +public class ImgPlus extends DefaultCalibratedSpace implements Img, + Metadata +{ /** The name assigned to the ImgPlus if none is provided. */ private static final String DEFAULT_NAME = "Untitled"; @@ -69,8 +67,6 @@ public class ImgPlus implements Img, Metadata { private String name; private String source = ""; - private final AxisType[] axes; - private final double[] cal; private int validBits; private ArrayList channelMin; @@ -94,8 +90,8 @@ public ImgPlus(final Img img, final String name, final AxisType[] axes) { } public ImgPlus(final Img img, final Metadata metadata) { - this(img, metadata.getName(), getAxes(img, metadata), getCalibration(img, - metadata)); + this(img, metadata.getName(), getAxisTypes(img, metadata), + getCalibration(img, metadata)); validBits = metadata.getValidBits(); compositeChannelCount = metadata.getCompositeChannelCount(); final int count = metadata.getColorTableCount(); @@ -104,13 +100,37 @@ public ImgPlus(final Img img, final Metadata metadata) { } } - public ImgPlus(final Img img, final String name, final AxisType[] axes, - final double[] cal) + public ImgPlus(final Img img, final String name, + final AxisType[] axisTypes, final double[] cal) { + super(img.numDimensions()); + + // NB: Do not call numDimensions() here! Calling an instance method from a + // constructor can have bizarre and unintuitive results in complex class + // hierarchies. For example, suppose a subclass overrides the behavior of + // numDimensions() in such a way that it only functions correctly after its + // own constructor finishes executing. Then calling numDimensions() here in + // the superclass (before the subclass's constructor has finished executing) + // will behave improperly. + final int numDims = img.numDimensions(); + this.img = img; this.name = validateName(name); - this.axes = validateAxes(img.numDimensions(), axes); - this.cal = validateCalibration(img.numDimensions(), cal); + final AxisType[] validTypes = + validateAxisTypes(numDims, axisTypes); + if (numDims != validTypes.length) { + throw new IllegalArgumentException("Axis type count does not match " + + "dimensionality: " + validTypes.length + " != " + numDims); + } + final double[] validCal = validateCalibration(numDims, cal); + if (numDims != validCal.length) { + throw new IllegalArgumentException("Calibration count does not match " + + "dimensionality: " + validCal.length + " != " + numDims); + } + for (int d = 0; d < numDims; d++) { + axis(d).setType(validTypes[d]); + axis(d).setCalibration(validCal[d]); + } channelMin = new ArrayList(); channelMax = new ArrayList(); colorTable = new ArrayList(); @@ -119,11 +139,12 @@ public ImgPlus(final Img img, final String name, final AxisType[] axes, // -- ImgPlus methods -- + @Deprecated public Img getImg() { return img; } - // -- Img methods -- + // -- RandomAccessible methods -- @Override public RandomAccess randomAccess() { @@ -135,10 +156,7 @@ public RandomAccess randomAccess(final Interval interval) { return img.randomAccess(interval); } - @Override - public int numDimensions() { - return img.numDimensions(); - } + // -- Interval methods -- @Override public long min(final int d) { @@ -170,6 +188,8 @@ public void max(final Positionable max) { img.max(max); } + // -- Dimensions methods -- + @Override public void dimensions(final long[] dimensions) { img.dimensions(dimensions); @@ -180,6 +200,8 @@ public long dimension(final int d) { return img.dimension(d); } + // -- RealInterval methods -- + @Override public double realMin(final int d) { return img.realMin(d); @@ -210,6 +232,8 @@ public void realMax(final RealPositionable max) { img.realMax(max); } + // -- IterableInterval methods -- + @Override public Cursor cursor() { return img.cursor(); @@ -220,6 +244,8 @@ public Cursor localizingCursor() { return img.localizingCursor(); } + // -- IterableRealInterval methods -- + @Override public long size() { return img.size(); @@ -242,17 +268,26 @@ public boolean equalIterationOrder( final IterableRealInterval< ? > f ) return iterationOrder().equals( f.iterationOrder() ); } + // -- Iterable methods -- + @Override public Iterator iterator() { return img.iterator(); } + // -- Img methods -- + @Override public ImgFactory factory() { return img.factory(); } - // -- Metadata methods -- + @Override + public ImgPlus copy() { + return new ImgPlus(img.copy(), this); + } + + // -- Named methods -- @Override public String getName() { @@ -264,63 +299,7 @@ public void setName(final String name) { this.name = name; } - @Override - public int getAxisIndex(final AxisType axis) { - for (int i = 0; i < axes.length; i++) { - if (axes[i] == axis) return i; - } - return -1; - } - - @Override - public AxisType axis(final int d) { - return axes[d]; - } - - @Override - public void axes(final AxisType[] target) { - for (int i = 0; i < target.length; i++) - target[i] = axes[i]; - } - - @Override - public void setAxis(final AxisType axis, final int d) { - axes[d] = axis; - } - - @Override - public double calibration(final int d) { - return cal[d]; - } - - @Override - public void calibration(final double[] target) { - for (int i = 0; i < target.length; i++) - target[i] = cal[i]; - } - - @Override - public void calibration(final float[] target) { - for (int i = 0; i < target.length; i++) - target[i] = (float)cal[i]; - } - - @Override - public void setCalibration(final double value, final int d) { - cal[d] = value; - } - - @Override - public void setCalibration(final double[] cal) { - for ( int d = 0; d < cal.length; ++d ) - this.cal[d] = cal[ d ]; - } - - @Override - public void setCalibration(final float[] cal) { - for ( int d = 0; d < cal.length; ++d ) - this.cal[d] = cal[ d ]; - } + // -- ImageMetadata methods -- @Override public int getValidBits() { @@ -403,16 +382,18 @@ public int getColorTableCount() { return colorTable.size(); } + // -- Sourced methods -- + @Override public String getSource() { return source; } - + @Override public void setSource(String source) { this.source = source; } - + // -- Utility methods -- /** Ensures the given {@link Img} is an ImgPlus, wrapping if necessary. */ @@ -436,26 +417,28 @@ private static String validateName(final String name) { return name; } - /** Ensures the given axis labels are valid. */ - private static AxisType[] validateAxes(final int numDims, final AxisType[] axes) { - if (axes != null && numDims == axes.length) return axes; - final AxisType[] validAxes = new AxisType[numDims]; - for (int i = 0; i < validAxes.length; i++) { - if (axes != null && axes.length > i) validAxes[i] = axes[i]; + /** Ensures the given axis types are valid. */ + private static AxisType[] validateAxisTypes(final int numDims, + final AxisType[] types) + { + if (types != null && numDims == types.length) return types; + final AxisType[] valid = new AxisType[numDims]; + for (int i = 0; i < valid.length; i++) { + if (types != null && types.length > i) valid[i] = types[i]; else { switch (i) { case 0: - validAxes[i] = Axes.X; + valid[i] = Axes.X; break; case 1: - validAxes[i] = Axes.Y; + valid[i] = Axes.Y; break; default: - validAxes[i] = Axes.UNKNOWN; + valid[i] = Axes.unknown(); } } } - return validAxes; + return valid; } /** Ensures the given calibration values are valid. */ @@ -463,20 +446,22 @@ private static double[] validateCalibration(final int numDims, final double[] cal) { if (cal != null && numDims == cal.length) return cal; - final double[] validCal = new double[numDims]; - for (int i = 0; i < validCal.length; i++) { - if (cal != null && cal.length > i) validCal[i] = cal[i]; - else validCal[i] = 1; + final double[] valid = new double[numDims]; + for (int i = 0; i < valid.length; i++) { + if (cal != null && cal.length > i) valid[i] = cal[i]; + else valid[i] = 1; } - return validCal; + return valid; } - private static AxisType[] getAxes(final Img img, final Metadata metadata) { - final AxisType[] axes = new AxisType[img.numDimensions()]; - for (int i = 0; i < axes.length; i++) { - axes[i] = metadata.axis(i); + private static AxisType[] getAxisTypes(final Img img, + final Metadata metadata) + { + final AxisType[] types = new AxisType[img.numDimensions()]; + for (int i = 0; i < types.length; i++) { + types[i] = metadata.axis(i).type(); } - return axes; + return types; } private static double[] getCalibration(final Img img, @@ -484,14 +469,9 @@ private static double[] getCalibration(final Img img, { final double[] cal = new double[img.numDimensions()]; for (int i = 0; i < cal.length; i++) { - cal[i] = metadata.calibration(i); + cal[i] = metadata.axis(i).calibration(); } return cal; } - @Override - public ImgPlus copy() { - return new ImgPlus(img.copy(), this); - } - } diff --git a/core/src/main/java/net/imglib2/meta/Metadata.java b/meta/src/main/java/net/imglib2/meta/Metadata.java similarity index 84% rename from core/src/main/java/net/imglib2/meta/Metadata.java rename to meta/src/main/java/net/imglib2/meta/Metadata.java index 28fb66466a..9708a568d2 100644 --- a/core/src/main/java/net/imglib2/meta/Metadata.java +++ b/meta/src/main/java/net/imglib2/meta/Metadata.java @@ -37,18 +37,14 @@ package net.imglib2.meta; -import net.imglib2.img.Img; -import net.imglib2.img.ImgPlus; - /** - * An interface for defining metadata that goes along with an {@link Img}, - * including name, dimensional axes and calibration information. + * An interface which collects all metadata associated with an {@link ImgPlus}. * - * @see ImgPlus - * @author Stephan Preibisch - * @author Stephan Saalfeld * @author Curtis Rueden + * @see ImgPlus */ -public interface Metadata extends Named, Sourced, CalibratedSpace, ImageMetadata { - // marker interface - no implementation needed +public interface Metadata extends Named, Sourced, + CalibratedSpace, ImageMetadata +{ + // NB: Marker interface. } diff --git a/core/src/main/java/net/imglib2/meta/Named.java b/meta/src/main/java/net/imglib2/meta/Named.java similarity index 100% rename from core/src/main/java/net/imglib2/meta/Named.java rename to meta/src/main/java/net/imglib2/meta/Named.java diff --git a/core/src/main/java/net/imglib2/meta/CalibratedSpace.java b/meta/src/main/java/net/imglib2/meta/OldCalibratedSpace.java similarity index 96% rename from core/src/main/java/net/imglib2/meta/CalibratedSpace.java rename to meta/src/main/java/net/imglib2/meta/OldCalibratedSpace.java index 96d7d2dd8e..131deba1c6 100644 --- a/core/src/main/java/net/imglib2/meta/CalibratedSpace.java +++ b/meta/src/main/java/net/imglib2/meta/OldCalibratedSpace.java @@ -47,8 +47,10 @@ * @author Stephan Preibisch * @author Stephan Saalfeld * @author Lee Kamentsky + * @deprecated Use {@link CalibratedSpace}. */ -public interface CalibratedSpace extends EuclideanSpace { +@Deprecated +public interface OldCalibratedSpace extends EuclideanSpace { /** Gets the dimensional index of the axis with the given type. */ int getAxisIndex(final AxisType axis); diff --git a/core/src/main/java/net/imglib2/meta/Sourced.java b/meta/src/main/java/net/imglib2/meta/Sourced.java similarity index 100% rename from core/src/main/java/net/imglib2/meta/Sourced.java rename to meta/src/main/java/net/imglib2/meta/Sourced.java diff --git a/meta/src/main/java/net/imglib2/meta/TypedAxis.java b/meta/src/main/java/net/imglib2/meta/TypedAxis.java new file mode 100644 index 0000000000..be6ef6f4c1 --- /dev/null +++ b/meta/src/main/java/net/imglib2/meta/TypedAxis.java @@ -0,0 +1,56 @@ +/* + * #%L + * ImgLib2: a general-purpose, multidimensional image processing library. + * %% + * Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia, + * Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves + * Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris, + * Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier, + * Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are + * those of the authors and should not be interpreted as representing official + * policies, either expressed or implied, of any organization. + * #L% + */ + +package net.imglib2.meta; + +import net.imglib2.Axis; + +/** + * An axis with an associated {@link AxisType}. + * + * @author Curtis Rueden + * @see TypedSpace + */ +public interface TypedAxis extends Axis { + + /** Gets the type of the axis. */ + AxisType type(); + + /** Sets the type of the axis. */ + void setType(AxisType type); + +} diff --git a/meta/src/main/java/net/imglib2/meta/TypedRealInterval.java b/meta/src/main/java/net/imglib2/meta/TypedRealInterval.java new file mode 100644 index 0000000000..f92cadc7dc --- /dev/null +++ b/meta/src/main/java/net/imglib2/meta/TypedRealInterval.java @@ -0,0 +1,51 @@ +/* + * #%L + * ImgLib2: a general-purpose, multidimensional image processing library. + * %% + * Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia, + * Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves + * Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris, + * Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier, + * Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are + * those of the authors and should not be interpreted as representing official + * policies, either expressed or implied, of any organization. + * #L% + */ + +package net.imglib2.meta; + +import net.imglib2.RealInterval; + +/** + * A {@link RealInterval} over a {@link TypedSpace}. + * + * @author Curtis Rueden + */ +public interface TypedRealInterval extends RealInterval, + TypedSpace +{ + // NB: Marker interface. +} diff --git a/meta/src/main/java/net/imglib2/meta/TypedSpace.java b/meta/src/main/java/net/imglib2/meta/TypedSpace.java new file mode 100644 index 0000000000..73be0aa183 --- /dev/null +++ b/meta/src/main/java/net/imglib2/meta/TypedSpace.java @@ -0,0 +1,59 @@ +/* + * #%L + * ImgLib2: a general-purpose, multidimensional image processing library. + * %% + * Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia, + * Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves + * Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris, + * Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier, + * Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are + * those of the authors and should not be interpreted as representing official + * policies, either expressed or implied, of any organization. + * #L% + */ + +package net.imglib2.meta; + +import net.imglib2.AnnotatedSpace; + +/** + * A Euclidean space with typed dimensional axes. + * + * @author Curtis Rueden + * @see TypedAxis + */ +public interface TypedSpace extends AnnotatedSpace { + + /** + * Gets the dimensional index of the axis with the given type. + *

+ * Note that by convention, each {@link AxisType} may only be used in a + * single dimension of the space. + *

+ */ + int dimensionIndex(final AxisType axisType); + +} diff --git a/core/src/main/java/net/imglib2/view/HyperSliceImgPlus.java b/meta/src/main/java/net/imglib2/meta/view/HyperSliceImgPlus.java similarity index 98% rename from core/src/main/java/net/imglib2/view/HyperSliceImgPlus.java rename to meta/src/main/java/net/imglib2/meta/view/HyperSliceImgPlus.java index d6d304c3e0..e3a0b8a684 100644 --- a/core/src/main/java/net/imglib2/view/HyperSliceImgPlus.java +++ b/meta/src/main/java/net/imglib2/meta/view/HyperSliceImgPlus.java @@ -35,7 +35,7 @@ * #L% */ -package net.imglib2.view; +package net.imglib2.meta.view; import java.util.Iterator; @@ -49,10 +49,13 @@ import net.imglib2.RealPositionable; import net.imglib2.img.Img; import net.imglib2.img.ImgFactory; -import net.imglib2.img.ImgPlus; -import net.imglib2.meta.Axes; import net.imglib2.meta.AxisType; +import net.imglib2.meta.Axes; +import net.imglib2.meta.ImgPlus; import net.imglib2.transform.integer.MixedTransform; +import net.imglib2.view.MixedTransformView; +import net.imglib2.view.TransformBuilder; +import net.imglib2.view.Views; /** * This class offers access to a n-1-dimensional view of a source {@link ImgPlus}, @@ -126,7 +129,6 @@ public HyperSliceImgPlus( ImgPlus< T > source, final int d, final long pos ) { component[ e ] = e; min[ e ] = source.min( e ); max[ e ] = source.max( e ); - setCalibration( source.calibration(e), e); setAxis( source.axis(e), e); } else if ( e > d ) { @@ -135,7 +137,6 @@ public HyperSliceImgPlus( ImgPlus< T > source, final int d, final long pos ) { component[ e ] = e - 1; min[ e - 1] = source.min( e ); max[ e - 1] = source.max( e ); - setCalibration( source.calibration(e), e-1); setAxis( source.axis(e), e-1); } else { @@ -159,7 +160,6 @@ public HyperSliceImgPlus( ImgPlus< T > source, final int d, final long pos ) { int index = 0; for (int i = 0; i < m; i++) { if (i != d) { - setCalibration( source.calibration(i) , index ); setAxis( source.axis(i), index); index++; } diff --git a/core/src/test/java/net/imglib2/view/HyperSliceImgPlusTest.java b/meta/src/test/java/net/imglib2/meta/view/HyperSliceImgPlusTest.java similarity index 90% rename from core/src/test/java/net/imglib2/view/HyperSliceImgPlusTest.java rename to meta/src/test/java/net/imglib2/meta/view/HyperSliceImgPlusTest.java index 648cd5c823..9a32b8c330 100644 --- a/core/src/test/java/net/imglib2/view/HyperSliceImgPlusTest.java +++ b/meta/src/test/java/net/imglib2/meta/view/HyperSliceImgPlusTest.java @@ -35,18 +35,18 @@ * #L% */ -package net.imglib2.view; +package net.imglib2.meta.view; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import net.imglib2.Cursor; import net.imglib2.Localizable; import net.imglib2.RandomAccess; -import net.imglib2.img.ImgPlus; import net.imglib2.img.array.ArrayImg; import net.imglib2.img.array.ArrayImgFactory; import net.imglib2.meta.Axes; import net.imglib2.meta.AxisType; +import net.imglib2.meta.ImgPlus; import net.imglib2.type.numeric.integer.UnsignedByteType; import net.imglib2.util.Util; @@ -54,13 +54,14 @@ import org.junit.Test; /** + * Unit tests for {@link HyperSliceImgPlus}. + * * @author Jean-Yves Tinevez - * */ public class HyperSliceImgPlusTest { private static final long[] dim = new long[] { 16, 16, 64, 8, 32 }; - private static final AxisType[] axes = new AxisType[] { + private static final AxisType[] axisTypes = new AxisType[] { Axes.X, Axes.Y, Axes.Z, Axes.CHANNEL, Axes.TIME }; private static final float[] calibration = new float[] { 0.5f, 0.5f, 0.8f, 1, 5 }; private static final String name = "Source"; @@ -86,8 +87,8 @@ public void setUp() throws Exception { ArrayImg img = factory.create(dim , new UnsignedByteType()); source = new ImgPlus(img); for (int d = 0; d < dim.length; d++) { - source.setAxis(axes[d], d); - source.setCalibration(calibration[d], d); + source.axis(d).setType(axisTypes[d]); + source.axis(d).setCalibration(calibration[d]); } source.setName(name); @@ -109,7 +110,7 @@ public void testMetadata() { int index1 = 0; for (int d = 0; d < dim.length; d++) { if (d != REMOVED_DIM_1) { - assertEquals(source.calibration(d), imgplusZ.calibration(index1), Float.MIN_VALUE); + assertEquals(source.axis(d).calibration(), imgplusZ.axis(index1).calibration(), Float.MIN_VALUE); assertEquals(source.axis(d), imgplusZ.axis(index1)); index1++; } @@ -118,7 +119,7 @@ public void testMetadata() { int index2 = 0; for (int d = 0; d < dim.length; d++) { if (d != REMOVED_DIM_1 && d != (REMOVED_DIM_2+1)) { - assertEquals(source.calibration(d), imgplusZT.calibration(index2), Float.MIN_VALUE); + assertEquals(source.axis(d).calibration(), imgplusZT.axis(index2).calibration(), Float.MIN_VALUE); assertEquals(source.axis(d), imgplusZT.axis(index2)); index2++; } @@ -126,7 +127,7 @@ public void testMetadata() { } /** - * Test method for {@link fiji.plugin.trackmate.util.HyperSliceImgPlus#randomAccess()}. + * Test method for {@link HyperSliceImgPlus#randomAccess()}. */ @Test public void testRandomAccess() { @@ -176,7 +177,7 @@ val, printCoords(ra), printCoords(ra2), ra2.get().get()), } /** - * Test method for {@link fiji.plugin.trackmate.util.HyperSliceImgPlus#numDimensions()}. + * Test method for {@link HyperSliceImgPlus#numDimensions()}. */ @Test public void testNumDimensions() { @@ -185,7 +186,7 @@ public void testNumDimensions() { } /** - * Test method for {@link fiji.plugin.trackmate.util.HyperSliceImgPlus#min(int)}. + * Test method for {@link HyperSliceImgPlus#min(int)}. */ @Test public void testMinInt() { @@ -198,7 +199,7 @@ public void testMinInt() { } /** - * Test method for {@link fiji.plugin.trackmate.util.HyperSliceImgPlus#min(long[])}. + * Test method for {@link HyperSliceImgPlus#min(long[])}. */ @Test public void testMinLongArray() { @@ -213,7 +214,7 @@ public void testMinLongArray() { } /** - * Test method for {@link fiji.plugin.trackmate.util.HyperSliceImgPlus#max(int)}. + * Test method for {@link HyperSliceImgPlus#max(int)}. */ @Test public void testMaxInt() { @@ -234,7 +235,7 @@ public void testMaxInt() { } /** - * Test method for {@link fiji.plugin.trackmate.util.HyperSliceImgPlus#max(long[])}. + * Test method for {@link HyperSliceImgPlus#max(long[])}. */ @Test public void testMaxLongArray() { @@ -267,7 +268,7 @@ public void testMaxLongArray() { } /** - * Test method for {@link fiji.plugin.trackmate.util.HyperSliceImgPlus#dimensions(long[])}. + * Test method for {@link HyperSliceImgPlus#dimensions(long[])}. */ @Test public void testDimensions() { @@ -288,7 +289,7 @@ public void testDimensions() { } /** - * Test method for {@link fiji.plugin.trackmate.util.HyperSliceImgPlus#cursor()}. + * Test method for {@link HyperSliceImgPlus#cursor()}. */ @Test public void testCursor() { @@ -344,7 +345,7 @@ public void testCursor() { } /** - * Test method for {@link fiji.plugin.trackmate.util.HyperSliceImgPlus#size()}. + * Test method for {@link HyperSliceImgPlus#size()}. */ @Test public void testSize() { diff --git a/ops/pom.xml b/ops/pom.xml index 8d49a1881b..183795ff65 100644 --- a/ops/pom.xml +++ b/ops/pom.xml @@ -19,10 +19,16 @@ imglib2 ${project.version} + + ${project.groupId} + imglib2-meta + ${project.version} + + junit junit - 4.8.1 + ${junit.version} test diff --git a/ops/src/main/java/net/imglib2/ops/operation/imgplus/unary/ImgPlusCopy.java b/ops/src/main/java/net/imglib2/ops/operation/imgplus/unary/ImgPlusCopy.java index 50512e0864..4736d6ab76 100644 --- a/ops/src/main/java/net/imglib2/ops/operation/imgplus/unary/ImgPlusCopy.java +++ b/ops/src/main/java/net/imglib2/ops/operation/imgplus/unary/ImgPlusCopy.java @@ -37,7 +37,7 @@ package net.imglib2.ops.operation.imgplus.unary; -import net.imglib2.img.ImgPlus; +import net.imglib2.meta.ImgPlus; import net.imglib2.ops.operation.UnaryOperation; import net.imglib2.ops.operation.img.unary.ImgCopyOperation; import net.imglib2.type.Type; @@ -59,10 +59,7 @@ public ImgPlus< T > compute( ImgPlus< T > op, ImgPlus< T > r ) r.setSource( op.getSource() ); for ( int d = 0; d < op.numDimensions(); d++ ) { - r.setAxis( op.axis( d ), d ); - r.setCalibration( op.calibration( d ), d ); - } new ImgCopyOperation< T >().compute( op, r ); return r; diff --git a/ops/src/main/java/net/imglib2/ops/operation/imgplus/unary/ImgPlusCrop.java b/ops/src/main/java/net/imglib2/ops/operation/imgplus/unary/ImgPlusCrop.java index 7bb9b082fc..1b4484d295 100644 --- a/ops/src/main/java/net/imglib2/ops/operation/imgplus/unary/ImgPlusCrop.java +++ b/ops/src/main/java/net/imglib2/ops/operation/imgplus/unary/ImgPlusCrop.java @@ -42,7 +42,7 @@ import net.imglib2.Interval; import net.imglib2.RandomAccess; import net.imglib2.RealInterval; -import net.imglib2.img.ImgPlus; +import net.imglib2.meta.ImgPlus; import net.imglib2.ops.operation.UnaryOperation; import net.imglib2.type.Type; diff --git a/ops/src/main/java/net/imglib2/ops/operation/imgplus/unary/ImgPlusExtendDims.java b/ops/src/main/java/net/imglib2/ops/operation/imgplus/unary/ImgPlusExtendDims.java index 96de561d26..90f2b9e13b 100644 --- a/ops/src/main/java/net/imglib2/ops/operation/imgplus/unary/ImgPlusExtendDims.java +++ b/ops/src/main/java/net/imglib2/ops/operation/imgplus/unary/ImgPlusExtendDims.java @@ -42,9 +42,9 @@ import net.imglib2.Cursor; import net.imglib2.RandomAccess; -import net.imglib2.img.ImgPlus; import net.imglib2.meta.Axes; import net.imglib2.meta.AxisType; +import net.imglib2.meta.ImgPlus; import net.imglib2.ops.operation.UnaryOutputOperation; import net.imglib2.type.Type; @@ -81,7 +81,10 @@ public ImgPlus< T > createEmptyOutput( ImgPlus< T > op ) { AxisType[] axes = new AxisType[ op.numDimensions() ]; - op.axes( axes ); + for ( int d = 0; d < axes.length; d++ ) + { + axes[ d ] = op.axis( d ).type(); + } m_isNewDim.clear(); for ( int d = 0; d < m_newDimensions.length; d++ ) { @@ -116,7 +119,7 @@ public ImgPlus< T > compute( ImgPlus< T > op, ImgPlus< T > r ) for ( int d = 0; d < op.numDimensions(); d++ ) { - r.setAxis( Axes.get( op.axis( d ).getLabel() ), d ); + r.axis( d ).setType( Axes.get( op.axis( d ).type().getLabel() ) ); } int d = op.numDimensions(); @@ -124,7 +127,7 @@ public ImgPlus< T > compute( ImgPlus< T > op, ImgPlus< T > r ) { if ( m_isNewDim.get( i ) ) { - r.setAxis( Axes.get( m_newDimensions[ i ] ), d ); + r.axis( d ).setType( Axes.get( m_newDimensions[ i ] ) ); d++; } } diff --git a/ops/src/main/java/net/imglib2/ops/operation/imgplus/unary/ImgPlusRemove1Dims.java b/ops/src/main/java/net/imglib2/ops/operation/imgplus/unary/ImgPlusRemove1Dims.java index b91b2c1c01..bdc02395b2 100644 --- a/ops/src/main/java/net/imglib2/ops/operation/imgplus/unary/ImgPlusRemove1Dims.java +++ b/ops/src/main/java/net/imglib2/ops/operation/imgplus/unary/ImgPlusRemove1Dims.java @@ -43,14 +43,14 @@ import net.imglib2.FinalInterval; import net.imglib2.RandomAccess; import net.imglib2.img.Img; -import net.imglib2.img.ImgPlus; +import net.imglib2.meta.ImgPlus; import net.imglib2.meta.Metadata; import net.imglib2.ops.operation.UnaryOutputOperation; -import net.imglib2.ops.operation.metadata.unary.CopyCalibratedSpace; import net.imglib2.ops.operation.metadata.unary.CopyImageMetadata; import net.imglib2.ops.operation.metadata.unary.CopyMetadata; import net.imglib2.ops.operation.metadata.unary.CopyNamed; import net.imglib2.ops.operation.metadata.unary.CopySourced; +import net.imglib2.ops.operation.metadata.unary.CopyCalibratedSpace; import net.imglib2.type.Type; /** diff --git a/ops/src/main/java/net/imglib2/ops/operation/metadata/unary/CopyCalibratedSpace.java b/ops/src/main/java/net/imglib2/ops/operation/metadata/unary/CopyCalibratedSpace.java index 04c0ea600e..b3c6288cec 100644 --- a/ops/src/main/java/net/imglib2/ops/operation/metadata/unary/CopyCalibratedSpace.java +++ b/ops/src/main/java/net/imglib2/ops/operation/metadata/unary/CopyCalibratedSpace.java @@ -38,15 +38,17 @@ package net.imglib2.ops.operation.metadata.unary; import net.imglib2.Interval; +import net.imglib2.meta.CalibratedAxis; import net.imglib2.meta.CalibratedSpace; import net.imglib2.ops.operation.UnaryOperation; /** * @author Christian Dietz (University of Konstanz) - * - * @param + * @author Curtis Rueden + * + * @param The type of the space to copy */ -public class CopyCalibratedSpace< CS extends CalibratedSpace > implements UnaryOperation< CS, CS > +public class CopyCalibratedSpace< S extends CalibratedSpace > implements UnaryOperation< S, S > { private Interval interval; @@ -61,7 +63,7 @@ public CopyCalibratedSpace( Interval interval ) } @Override - public CS compute( CS input, CS output ) + public S compute( S input, S output ) { int offset = 0; @@ -73,8 +75,9 @@ public CS compute( CS input, CS output ) } else { + // NB: Axes are copied by reference here. If an axis is later + // mutated, this could cause unintuitive side effects... output.setAxis( input.axis( d ), d - offset ); - output.setCalibration( input.calibration( d ), d - offset ); } } @@ -82,9 +85,9 @@ public CS compute( CS input, CS output ) } @Override - public UnaryOperation< CS, CS > copy() + public UnaryOperation< S, S > copy() { - return new CopyCalibratedSpace< CS >(); + return new CopyCalibratedSpace< S >(); } } diff --git a/ops/src/main/java/net/imglib2/ops/operation/metadata/unary/CopyOldCalibratedSpace.java b/ops/src/main/java/net/imglib2/ops/operation/metadata/unary/CopyOldCalibratedSpace.java new file mode 100644 index 0000000000..e8f8d7f951 --- /dev/null +++ b/ops/src/main/java/net/imglib2/ops/operation/metadata/unary/CopyOldCalibratedSpace.java @@ -0,0 +1,91 @@ +/* + * #%L + * ImgLib2: a general-purpose, multidimensional image processing library. + * %% + * Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia, + * Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves + * Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris, + * Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier, + * Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are + * those of the authors and should not be interpreted as representing official + * policies, either expressed or implied, of any organization. + * #L% + */ + +package net.imglib2.ops.operation.metadata.unary; + +import net.imglib2.Interval; +import net.imglib2.meta.OldCalibratedSpace; +import net.imglib2.ops.operation.UnaryOperation; + +/** + * @author Christian Dietz (University of Konstanz) + * @deprecated Use {@link CopyCalibratedSpace}. + * @param + */ +@Deprecated +public class CopyOldCalibratedSpace< CS extends OldCalibratedSpace > implements UnaryOperation< CS, CS > +{ + private Interval interval; + + public CopyOldCalibratedSpace() + { + interval = null; + } + + public CopyOldCalibratedSpace( Interval interval ) + { + this.interval = interval; + } + + @Override + public CS compute( CS input, CS output ) + { + + int offset = 0; + for ( int d = 0; d < input.numDimensions(); d++ ) + { + if ( interval != null && interval.dimension( d ) == 1 ) + { + offset++; + } + else + { + output.setAxis( input.axis( d ), d - offset ); + output.setCalibration( input.calibration( d ), d - offset ); + } + } + + return output; + } + + @Override + public UnaryOperation< CS, CS > copy() + { + return new CopyOldCalibratedSpace< CS >(); + } + +} diff --git a/ops/src/main/java/net/imglib2/ops/operation/randomaccessibleinterval/binary/IterateBinaryOperation.java b/ops/src/main/java/net/imglib2/ops/operation/randomaccessibleinterval/binary/IterateBinaryOperation.java index ff47ca2465..b346893d69 100644 --- a/ops/src/main/java/net/imglib2/ops/operation/randomaccessibleinterval/binary/IterateBinaryOperation.java +++ b/ops/src/main/java/net/imglib2/ops/operation/randomaccessibleinterval/binary/IterateBinaryOperation.java @@ -43,10 +43,10 @@ import net.imglib2.Interval; import net.imglib2.RandomAccessibleInterval; import net.imglib2.img.Img; -import net.imglib2.img.ImgPlus; import net.imglib2.labeling.Labeling; +import net.imglib2.meta.ImgPlus; import net.imglib2.ops.operation.BinaryOperation; -import net.imglib2.ops.operation.metadata.unary.CopyCalibratedSpace; +import net.imglib2.ops.operation.metadata.unary.CopyOldCalibratedSpace; import net.imglib2.ops.operation.metadata.unary.CopyImageMetadata; import net.imglib2.ops.operation.metadata.unary.CopyMetadata; import net.imglib2.ops.operation.metadata.unary.CopyNamed; @@ -217,7 +217,7 @@ private synchronized < TT extends Type< TT >, II extends RandomAccessibleInterva if ( in instanceof ImgPlus ) { ImgPlusView< TT > imgPlusView = new ImgPlusView< TT >( SubsetViews.iterableSubsetView( in, i ), ( ( ImgPlus ) in ).factory() ); - new CopyMetadata( new CopyNamed(), new CopySourced(), new CopyImageMetadata(), new CopyCalibratedSpace( i ) ).compute( ( ImgPlus ) in, imgPlusView ); + new CopyMetadata( new CopyNamed(), new CopySourced(), new CopyImageMetadata(), new CopyOldCalibratedSpace( i ) ).compute( ( ImgPlus ) in, imgPlusView ); return ( II ) imgPlusView; } diff --git a/ops/src/main/java/net/imglib2/ops/operation/randomaccessibleinterval/unary/DistanceMap.java b/ops/src/main/java/net/imglib2/ops/operation/randomaccessibleinterval/unary/DistanceMap.java index 30c68b7166..5dea19df85 100644 --- a/ops/src/main/java/net/imglib2/ops/operation/randomaccessibleinterval/unary/DistanceMap.java +++ b/ops/src/main/java/net/imglib2/ops/operation/randomaccessibleinterval/unary/DistanceMap.java @@ -38,7 +38,7 @@ import net.imglib2.RandomAccess; import net.imglib2.RandomAccessibleInterval; -import net.imglib2.meta.CalibratedSpace; +import net.imglib2.meta.OldCalibratedSpace; import net.imglib2.ops.operation.UnaryOperation; import net.imglib2.type.numeric.RealType; import net.imglib2.type.numeric.real.FloatType; @@ -75,8 +75,8 @@ public M compute( final K src, final M res ) // if (src.dimension(i) > 1) { if ( a < MAX_DIMS ) { - if ( src instanceof CalibratedSpace ) - dim_unit[ a ] = ( ( CalibratedSpace ) src ).calibration( i ); + if ( src instanceof OldCalibratedSpace ) + dim_unit[ a ] = ( ( OldCalibratedSpace ) src ).calibration( i ); else dim_unit[ a ] = 1; diff --git a/ops/src/main/java/net/imglib2/ops/operation/randomaccessibleinterval/unary/IterateUnaryOperation.java b/ops/src/main/java/net/imglib2/ops/operation/randomaccessibleinterval/unary/IterateUnaryOperation.java index 9be1c2b77f..bacd73b346 100644 --- a/ops/src/main/java/net/imglib2/ops/operation/randomaccessibleinterval/unary/IterateUnaryOperation.java +++ b/ops/src/main/java/net/imglib2/ops/operation/randomaccessibleinterval/unary/IterateUnaryOperation.java @@ -43,11 +43,11 @@ import net.imglib2.Interval; import net.imglib2.RandomAccessibleInterval; import net.imglib2.img.Img; -import net.imglib2.img.ImgPlus; import net.imglib2.labeling.Labeling; import net.imglib2.labeling.NativeImgLabeling; +import net.imglib2.meta.ImgPlus; import net.imglib2.ops.operation.UnaryOperation; -import net.imglib2.ops.operation.metadata.unary.CopyCalibratedSpace; +import net.imglib2.ops.operation.metadata.unary.CopyOldCalibratedSpace; import net.imglib2.ops.operation.metadata.unary.CopyImageMetadata; import net.imglib2.ops.operation.metadata.unary.CopyMetadata; import net.imglib2.ops.operation.metadata.unary.CopyNamed; @@ -163,7 +163,7 @@ private synchronized < TT extends Type< TT >, II extends RandomAccessibleInterva if ( in instanceof ImgPlus ) { ImgPlusView< TT > imgPlusView = new ImgPlusView< TT >( SubsetViews.iterableSubsetView( in, i ), ( ( ImgPlus ) in ).factory() ); - new CopyMetadata( new CopyNamed(), new CopySourced(), new CopyImageMetadata(), new CopyCalibratedSpace( i ) ).compute( ( ImgPlus ) in, imgPlusView ); + new CopyMetadata( new CopyNamed(), new CopySourced(), new CopyImageMetadata(), new CopyOldCalibratedSpace( i ) ).compute( ( ImgPlus ) in, imgPlusView ); return ( II ) imgPlusView; } diff --git a/ops/src/main/java/net/imglib2/ops/operation/subset/views/ImgPlusView.java b/ops/src/main/java/net/imglib2/ops/operation/subset/views/ImgPlusView.java index 01250b896a..6428db0ce4 100644 --- a/ops/src/main/java/net/imglib2/ops/operation/subset/views/ImgPlusView.java +++ b/ops/src/main/java/net/imglib2/ops/operation/subset/views/ImgPlusView.java @@ -39,7 +39,7 @@ import net.imglib2.RandomAccessibleInterval; import net.imglib2.img.ImgFactory; -import net.imglib2.img.ImgPlus; +import net.imglib2.meta.ImgPlus; import net.imglib2.meta.Metadata; import net.imglib2.type.Type; diff --git a/ops/src/main/java/net/imglib2/ops/operation/subset/views/SubsetViews.java b/ops/src/main/java/net/imglib2/ops/operation/subset/views/SubsetViews.java index d6817cad27..c654ebb5f2 100644 --- a/ops/src/main/java/net/imglib2/ops/operation/subset/views/SubsetViews.java +++ b/ops/src/main/java/net/imglib2/ops/operation/subset/views/SubsetViews.java @@ -45,8 +45,8 @@ import net.imglib2.RandomAccessible; import net.imglib2.RandomAccessibleInterval; import net.imglib2.meta.AxisType; -import net.imglib2.meta.CalibratedSpace; -import net.imglib2.ops.util.metadata.CalibratedSpaceImpl; +import net.imglib2.meta.OldCalibratedSpace; +import net.imglib2.meta.DefaultOldCalibratedSpace; import net.imglib2.type.Type; import net.imglib2.util.Intervals; import net.imglib2.view.IterableRandomAccessibleInterval; @@ -121,8 +121,8 @@ public static final > RandomAccessibleInterval subsetView( * @return Adjusted {@link RandomAccessibleInterval} */ public static RandomAccessibleInterval synchronizeDimensionality( - final RandomAccessibleInterval src, CalibratedSpace srcSpace, - final Interval target, CalibratedSpace targetSpace) { + final RandomAccessibleInterval src, OldCalibratedSpace srcSpace, + final Interval target, OldCalibratedSpace targetSpace) { // must hold, if not: most likely an implementation error assert (srcSpace.numDimensions() == src.numDimensions() && target @@ -134,11 +134,11 @@ public static RandomAccessibleInterval synchronizeDimensionality( // Init result vars RandomAccessibleInterval res = src; - CalibratedSpace resSpace = new CalibratedSpaceImpl( + OldCalibratedSpace resSpace = new DefaultOldCalibratedSpace( target.numDimensions()); // 1. Step remove axis from source which can't be found in target - AxisType[] dispensable = getDeltaAxisTypes(targetSpace, srcSpace); + AxisType[] dispensable = getDeltaAxes(targetSpace, srcSpace); for (int d = dispensable.length - 1; d >= 0; --d) { int idx = srcSpace.getAxisIndex(dispensable[d]); res = Views.hyperSlice(res, idx, 0); @@ -156,7 +156,7 @@ public static RandomAccessibleInterval synchronizeDimensionality( } // 2. Add Axis which are available in target but not in source - AxisType[] missing = getDeltaAxisTypes(srcSpace, targetSpace); + AxisType[] missing = getDeltaAxes(srcSpace, targetSpace); // Dimensions are added and resSpace is synchronized with res i = srcSpace.numDimensions() - dispensable.length; @@ -223,8 +223,8 @@ public static RandomAccessibleInterval synchronizeDimensionality( } - private static boolean spaceEquals(CalibratedSpace srcSpace, - CalibratedSpace targetSpace) { + private static boolean spaceEquals(OldCalibratedSpace srcSpace, + OldCalibratedSpace targetSpace) { if (srcSpace.numDimensions() != targetSpace.numDimensions()) return false; @@ -240,8 +240,8 @@ private static boolean spaceEquals(CalibratedSpace srcSpace, * Calculate the delta axis which are missing in the smaller space. From the * smallest index of axistype to the biggest */ - private synchronized static AxisType[] getDeltaAxisTypes( - CalibratedSpace sourceSpace, CalibratedSpace targetSpace) { + private synchronized static AxisType[] getDeltaAxes( + OldCalibratedSpace sourceSpace, OldCalibratedSpace targetSpace) { List delta = new ArrayList(); for (int d = 0; d < targetSpace.numDimensions(); d++) { diff --git a/pom.xml b/pom.xml index 62f689636a..b4f8ac8609 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,7 @@ examples ij io + meta ops realtransform scripting diff --git a/scripting/pom.xml b/scripting/pom.xml index 2340efa0a0..06420a56e2 100644 --- a/scripting/pom.xml +++ b/scripting/pom.xml @@ -52,6 +52,11 @@ imglib2-io ${project.version} + + ${project.groupId} + imglib2-meta + ${project.version} + ${mpicbg.groupId} diff --git a/tests/pom.xml b/tests/pom.xml index 6ee0ff1bba..8843085efc 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -58,6 +58,12 @@ ${project.version} test + + ${project.groupId} + imglib2-meta + ${project.version} + test + ${project.groupId} imglib2-realtransform diff --git a/tests/src/test/java/net/imglib2/algorithm/gradient/GradientExample.java b/tests/src/test/java/net/imglib2/algorithm/gradient/GradientExample.java index ecbcf3d887..0a91bd5afc 100644 --- a/tests/src/test/java/net/imglib2/algorithm/gradient/GradientExample.java +++ b/tests/src/test/java/net/imglib2/algorithm/gradient/GradientExample.java @@ -28,11 +28,11 @@ import net.imglib2.Interval; import net.imglib2.img.Img; -import net.imglib2.img.ImgPlus; import net.imglib2.img.array.ArrayImgFactory; import net.imglib2.img.display.imagej.ImageJFunctions; import net.imglib2.io.ImgIOException; import net.imglib2.io.ImgOpener; +import net.imglib2.meta.ImgPlus; import net.imglib2.type.NativeType; import net.imglib2.type.numeric.RealType; import net.imglib2.type.numeric.real.FloatType; diff --git a/tests/src/test/java/net/imglib2/algorithm/legacy/scalespace/DoGBenchmark.java b/tests/src/test/java/net/imglib2/algorithm/legacy/scalespace/DoGBenchmark.java index ef47333055..0dc6f91156 100644 --- a/tests/src/test/java/net/imglib2/algorithm/legacy/scalespace/DoGBenchmark.java +++ b/tests/src/test/java/net/imglib2/algorithm/legacy/scalespace/DoGBenchmark.java @@ -27,9 +27,9 @@ package net.imglib2.algorithm.legacy.scalespace; import net.imglib2.RandomAccessibleInterval; -import net.imglib2.img.ImgPlus; import net.imglib2.img.array.ArrayImgFactory; import net.imglib2.io.ImgOpener; +import net.imglib2.meta.ImgPlus; import net.imglib2.outofbounds.OutOfBoundsMirrorFactory; import net.imglib2.type.numeric.real.FloatType; import net.imglib2.util.BenchmarkHelper; @@ -96,7 +96,7 @@ public static void main( final String[] args ) // sigmaZ is at least twice the image sigma if ( image.numDimensions() == 3 ) { - final float sigma1Z = Math.max( imageSigma * 2, sigma1 / (float)image.calibration( 2 ) ); + final float sigma1Z = Math.max( imageSigma * 2, sigma1 / (float)image.axis( 2 ).calibration() ); final float sigma2Z = sigma1Z * k; final float[] sigmaZ = new float[]{ sigma1Z, sigma2Z }; final float[] sigmaDiffZ = computeSigmaDiff( sigmaZ, imageSigma ); diff --git a/tests/src/test/java/tests/ImgPanel.java b/tests/src/test/java/tests/ImgPanel.java index 67f1747225..5f8c4c80ec 100644 --- a/tests/src/test/java/tests/ImgPanel.java +++ b/tests/src/test/java/tests/ImgPanel.java @@ -50,10 +50,10 @@ import net.imglib2.display.XYProjector; import net.imglib2.exception.IncompatibleTypeException; import net.imglib2.img.Img; -import net.imglib2.img.ImgPlus; import net.imglib2.io.ImgIOException; import net.imglib2.io.ImgIOUtils; import net.imglib2.io.ImgOpener; +import net.imglib2.meta.ImgPlus; import net.imglib2.type.NativeType; import net.imglib2.type.numeric.ARGBType; import net.imglib2.type.numeric.RealType; diff --git a/tests/src/test/java/tests/LanczosExample.java b/tests/src/test/java/tests/LanczosExample.java index 5d24579ec4..587f3699ae 100644 --- a/tests/src/test/java/tests/LanczosExample.java +++ b/tests/src/test/java/tests/LanczosExample.java @@ -35,14 +35,13 @@ import net.imglib2.display.ARGBScreenImage; import net.imglib2.display.RealARGBConverter; import net.imglib2.display.XYRandomAccessibleProjector; -import net.imglib2.img.Img; -import net.imglib2.img.ImgPlus; import net.imglib2.img.array.ArrayImgFactory; import net.imglib2.interpolation.Interpolant; import net.imglib2.interpolation.InterpolatorFactory; import net.imglib2.interpolation.randomaccess.LanczosInterpolatorFactory; import net.imglib2.io.ImgIOException; import net.imglib2.io.ImgOpener; +import net.imglib2.meta.ImgPlus; import net.imglib2.realtransform.AffineGet; import net.imglib2.realtransform.AffineRandomAccessible; import net.imglib2.realtransform.AffineTransform3D; @@ -64,12 +63,11 @@ final static public void main( final String[] args ) final ImgOpener io = new ImgOpener(); //final RandomAccessibleInterval< UnsignedShortType > img = io.openImg( "/home/saalfeld/phd/light-microscopy/presentation/saalfeld-05-05-4-DPX-05_L1_Sum.lsm", new ArrayImgFactory< UnsignedShortType >(), new UnsignedShortType()); final ImgPlus< UnsignedShortType > imgPlus = io.openImg( "/home/saalfeld/Desktop/l1-cns.tif", new ArrayImgFactory< UnsignedShortType >(), new UnsignedShortType()); - final Img< UnsignedShortType > img = imgPlus.getImg(); final double[][] matrix = new double[][]{ - { 0.5, 0, 0, img.dimension( 0 ) * 0.25 }, - { 0, 0.5 * imgPlus.calibration( 1 ) / imgPlus.calibration( 0 ), 0, img.dimension( 1 ) * 0.25 }, - { 0, 0, 0.5 * imgPlus.calibration( 0 ) / imgPlus.calibration( 0 ), 0 } + { 0.5, 0, 0, imgPlus.dimension( 0 ) * 0.25 }, + { 0, 0.5 * imgPlus.axis( 1 ).calibration() / imgPlus.axis( 0 ).calibration(), 0, imgPlus.dimension( 1 ) * 0.25 }, + { 0, 0, 0.5 * imgPlus.axis( 0 ).calibration() / imgPlus.axis( 0 ).calibration(), 0 } }; // final AffineTransform affine = new AffineTransform( new Matrix( matrix ) ); final AffineTransform3D affine = new AffineTransform3D(); @@ -79,11 +77,11 @@ final static public void main( final String[] args ) // final InterpolatorFactory< UnsignedShortType, RandomAccessible< UnsignedShortType > > interpolatorFactory = new NLinearInterpolatorFactory< UnsignedShortType >(); final InterpolatorFactory< UnsignedShortType, RandomAccessible< UnsignedShortType > > interpolatorFactory = new LanczosInterpolatorFactory< UnsignedShortType >(); - final RandomAccessible< UnsignedShortType > extendedImg = Views.extendValue( img, new UnsignedShortType() ); + final RandomAccessible< UnsignedShortType > extendedImg = Views.extendValue( imgPlus, new UnsignedShortType() ); final Interpolant< UnsignedShortType, RandomAccessible< UnsignedShortType > > interpolant = new Interpolant< UnsignedShortType, RandomAccessible< UnsignedShortType > >( extendedImg, interpolatorFactory ); final AffineRandomAccessible< UnsignedShortType, AffineGet > mapping = new AffineRandomAccessible< UnsignedShortType, AffineGet >( interpolant, affine ); - final ARGBScreenImage screenImage = new ARGBScreenImage( ( int )img.dimension( 0 ), ( int )img.dimension( 1 ) ); + final ARGBScreenImage screenImage = new ARGBScreenImage( ( int )imgPlus.dimension( 0 ), ( int )imgPlus.dimension( 1 ) ); final XYRandomAccessibleProjector< UnsignedShortType, ARGBType > projector = new XYRandomAccessibleProjector< UnsignedShortType, ARGBType >( mapping, screenImage, new RealARGBConverter< UnsignedShortType >( 0, 4095 ) ); final ColorProcessor cp = new ColorProcessor( screenImage.image() ); @@ -92,7 +90,7 @@ final static public void main( final String[] args ) final Timer timer = new Timer(); - projector.setPosition( img.dimension( 2 ) / 2, 2 ); + projector.setPosition( imgPlus.dimension( 2 ) / 2, 2 ); final AffineTransform3D forward = new AffineTransform3D(); final AffineTransform3D rotation = new AffineTransform3D(); @@ -109,15 +107,15 @@ final static public void main( final String[] args ) { rotation.rotate( 1, Math.PI / 360 ); forward.set( - 1.0, 0, 0, -img.dimension( 0 ) / 2.0, - 0, 1.0, 0, -img.dimension( 1 ) / 2.0, - 0, 0, 1.0, -img.dimension( 2 ) / 2.0 ); + 1.0, 0, 0, -imgPlus.dimension( 0 ) / 2.0, + 0, 1.0, 0, -imgPlus.dimension( 1 ) / 2.0, + 0, 0, 1.0, -imgPlus.dimension( 2 ) / 2.0 ); forward.preConcatenate( scale ); forward.preConcatenate( rotation ); forward.set( - forward.get( 0, 0 ), forward.get( 0, 1 ), forward.get( 0, 2 ), forward.get( 0, 3 ) + img.dimension( 0 ) / 2.0, - forward.get( 1, 0 ), forward.get( 1, 1 ), forward.get( 1, 2 ), forward.get( 1, 3 ) + img.dimension( 1 ) / 2.0, - forward.get( 2, 0 ), forward.get( 2, 1 ), forward.get( 2, 2 ), forward.get( 2, 3 ) + img.dimension( 2 ) / 2.0 ); + forward.get( 0, 0 ), forward.get( 0, 1 ), forward.get( 0, 2 ), forward.get( 0, 3 ) + imgPlus.dimension( 0 ) / 2.0, + forward.get( 1, 0 ), forward.get( 1, 1 ), forward.get( 1, 2 ), forward.get( 1, 3 ) + imgPlus.dimension( 1 ) / 2.0, + forward.get( 2, 0 ), forward.get( 2, 1 ), forward.get( 2, 2 ), forward.get( 2, 3 ) + imgPlus.dimension( 2 ) / 2.0 ); affine.set( forward.inverse() ); diff --git a/tests/src/test/java/tests/OpenAndDisplayAffineTransformedScreenImage.java b/tests/src/test/java/tests/OpenAndDisplayAffineTransformedScreenImage.java index cca11dbd9d..1b2aa83017 100644 --- a/tests/src/test/java/tests/OpenAndDisplayAffineTransformedScreenImage.java +++ b/tests/src/test/java/tests/OpenAndDisplayAffineTransformedScreenImage.java @@ -35,13 +35,12 @@ import net.imglib2.display.ARGBScreenImage; import net.imglib2.display.RealARGBConverter; import net.imglib2.display.XYRandomAccessibleProjector; -import net.imglib2.img.Img; -import net.imglib2.img.ImgPlus; import net.imglib2.img.array.ArrayImgFactory; import net.imglib2.interpolation.Interpolant; import net.imglib2.interpolation.randomaccess.NearestNeighborInterpolatorFactory; import net.imglib2.io.ImgIOException; import net.imglib2.io.ImgOpener; +import net.imglib2.meta.ImgPlus; import net.imglib2.realtransform.AffineGet; import net.imglib2.realtransform.AffineRandomAccessible; import net.imglib2.realtransform.AffineTransform3D; @@ -63,12 +62,11 @@ final static public void main( final String[] args ) final ImgOpener io = new ImgOpener(); //final RandomAccessibleInterval< UnsignedShortType > img = io.openImg( "/home/saalfeld/phd/light-microscopy/presentation/saalfeld-05-05-4-DPX-05_L1_Sum.lsm", new ArrayImgFactory< UnsignedShortType >(), new UnsignedShortType()); final ImgPlus< UnsignedShortType > imgPlus = io.openImg( "/home/saalfeld/phd/light-microscopy/presentation/saalfeld-05-05-4-DPX-05_L1_Sum.0.tif", new ArrayImgFactory< UnsignedShortType >(), new UnsignedShortType()); - final Img< UnsignedShortType > img = imgPlus.getImg(); final double[][] matrix = new double[][]{ - { 0.5, 0, 0, img.dimension( 0 ) * 0.25 }, - { 0, 0.5 * imgPlus.calibration( 1 ) / imgPlus.calibration( 0 ), 0, img.dimension( 1 ) * 0.25 }, - { 0, 0, 0.5 * imgPlus.calibration( 0 ) / imgPlus.calibration( 0 ), 0 } + { 0.5, 0, 0, imgPlus.dimension( 0 ) * 0.25 }, + { 0, 0.5 * imgPlus.axis( 1 ).calibration() / imgPlus.axis( 0 ).calibration(), 0, imgPlus.dimension( 1 ) * 0.25 }, + { 0, 0, 0.5 * imgPlus.axis( 0 ).calibration() / imgPlus.axis( 0 ).calibration(), 0 } }; // final AffineTransform affine = new AffineTransform( new Matrix( matrix ) ); final AffineTransform3D affine = new AffineTransform3D(); @@ -77,7 +75,7 @@ final static public void main( final String[] args ) final NearestNeighborInterpolatorFactory< UnsignedShortType > interpolatorFactory = new NearestNeighborInterpolatorFactory< UnsignedShortType >(); // final InterpolatorFactory< UnsignedShortType, RandomAccessible< UnsignedShortType> > interpolatorFactory = new NLinearInterpolatorFactory< UnsignedShortType >(); - final RandomAccessible< UnsignedShortType > extendedImg = Views.extendValue( img, new UnsignedShortType() ); + final RandomAccessible< UnsignedShortType > extendedImg = Views.extendValue( imgPlus, new UnsignedShortType() ); //final RandomAccessible< UnsignedShortType > channel = Views.hyperSlice( img, 2, 0 ); //final Interpolant< UnsignedShortType, RandomAccessible< UnsignedShortType > > interpolant = new Interpolant< UnsignedShortType, RandomAccessible< UnsignedShortType > >( channel, interpolatorFactory ); final Interpolant< UnsignedShortType, RandomAccessible< UnsignedShortType > > interpolant = new Interpolant< UnsignedShortType, RandomAccessible< UnsignedShortType > >( extendedImg, interpolatorFactory ); @@ -87,7 +85,7 @@ final static public void main( final String[] args ) // final ConstantAffineRandomAccessible< UnsignedShortType, AffineTransform3D > mapping = new ConstantAffineRandomAccessible< UnsignedShortType, AffineTransform3D >( interpolant, affine ); // final RandomAccessibleOnRealRandomAccessible< UnsignedShortType > transformedPixels = new RandomAccessibleOnRealRandomAccessible< UnsignedShortType >( mapping ); - final ColorProcessor cp = new ColorProcessor( ( int )img.dimension( 0 ), ( int )img.dimension( 1 ) ); + final ColorProcessor cp = new ColorProcessor( ( int )imgPlus.dimension( 0 ), ( int )imgPlus.dimension( 1 ) ); final ARGBScreenImage screenImage = new ARGBScreenImage( cp.getWidth(), cp.getHeight(), ( int[] )cp.getPixels() ); // final XYProjector< UnsignedShortType, ARGBType > projector = new XYProjector< UnsignedShortType, ARGBType >( mapping, screenImage, new RealARGBConverter< UnsignedShortType >( 0, 4095 ) ); // final XYProjector< UnsignedShortType, ARGBType > projector = new XYProjector< UnsignedShortType, ARGBType >( transformedPixels, screenImage, new RealARGBConverter< UnsignedShortType >( 0, 4095 ) ); @@ -103,7 +101,7 @@ final static public void main( final String[] args ) { timer.start(); // final long last = img.dimension( 3 ) * 2 - 2; - final long last = img.dimension( 2 ) * 2 - 2; + final long last = imgPlus.dimension( 2 ) * 2 - 2; for ( int i = 0; i < last; ++i ) { projector.setPosition( i, 2 ); @@ -113,7 +111,7 @@ final static public void main( final String[] args ) IJ.log( "loop " + ( k + 1 ) + ": " + timer.stop() ); } - projector.setPosition( img.dimension( 2 ) / 2, 2 ); + projector.setPosition( imgPlus.dimension( 2 ) / 2, 2 ); final AffineTransform3D forward = new AffineTransform3D(); final AffineTransform3D rotation = new AffineTransform3D(); @@ -130,15 +128,15 @@ final static public void main( final String[] args ) { rotation.rotate( 1, Math.PI / 360 ); forward.set( - 1.0, 0, 0, -img.dimension( 0 ) / 2.0, - 0, 1.0, 0, -img.dimension( 1 ) / 2.0, - 0, 0, 1.0, -img.dimension( 2 ) / 2.0 ); + 1.0, 0, 0, -imgPlus.dimension( 0 ) / 2.0, + 0, 1.0, 0, -imgPlus.dimension( 1 ) / 2.0, + 0, 0, 1.0, -imgPlus.dimension( 2 ) / 2.0 ); forward.preConcatenate( scale ); forward.preConcatenate( rotation ); forward.set( - forward.get( 0, 0 ), forward.get( 0, 1 ), forward.get( 0, 2 ), forward.get( 0, 3 ) + img.dimension( 0 ) / 2.0, - forward.get( 1, 0 ), forward.get( 1, 1 ), forward.get( 1, 2 ), forward.get( 1, 3 ) + img.dimension( 1 ) / 2.0, - forward.get( 2, 0 ), forward.get( 2, 1 ), forward.get( 2, 2 ), forward.get( 2, 3 ) + img.dimension( 2 ) / 2.0 ); + forward.get( 0, 0 ), forward.get( 0, 1 ), forward.get( 0, 2 ), forward.get( 0, 3 ) + imgPlus.dimension( 0 ) / 2.0, + forward.get( 1, 0 ), forward.get( 1, 1 ), forward.get( 1, 2 ), forward.get( 1, 3 ) + imgPlus.dimension( 1 ) / 2.0, + forward.get( 2, 0 ), forward.get( 2, 1 ), forward.get( 2, 2 ), forward.get( 2, 3 ) + imgPlus.dimension( 2 ) / 2.0 ); affine.set( forward.inverse() );