+ * 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 SaalfeldA 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+ * 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+ * 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+ * 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 an-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