From 17eaef2ddfec3a620c8cdaf5e7d8b3251335719b Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Tue, 26 Mar 2024 20:25:44 +0100 Subject: [PATCH] Implement Typed::getType where it makes sense --- .../imglib2/labeling/DefaultROIStrategy.java | 6 +++++ .../imglib2/labeling/NativeImgLabeling.java | 6 +++++ .../roi/AbstractIterableRegionOfInterest.java | 12 ++++++++++ .../roi/BinaryMaskRegionOfInterest.java | 12 ++++++++++ .../net/imglib2/roi/RegionOfInterest.java | 6 +++++ .../net/imglib2/roi/boundary/Boundary.java | 16 ++++++++++++-- .../roi/boundary/BoundaryRandomAccess4.java | 6 +++++ .../roi/boundary/BoundaryRandomAccess8.java | 6 +++++ .../roi/geom/integer/IterableLine.java | 6 +++++ .../net/imglib2/roi/labeling/ImgLabeling.java | 18 +++++++++++++++ .../net/imglib2/roi/labeling/LabelRegion.java | 12 ++++++++++ .../roi/labeling/LabelRegionRandomAccess.java | 6 +++++ .../mask/integer/MaskAsRandomAccessible.java | 5 +++++ ...askIntervalAsRandomAccessibleInterval.java | 6 +++++ .../integer/MaskPredicateRandomAccess.java | 6 +++++ .../real/MaskPredicateRealRandomAccess.java | 6 +++++ .../real/RealMaskAsRealRandomAccessible.java | 5 +++++ ...valAsRealRandomAccessibleRealInterval.java | 6 +++++ .../util/IterableRandomAccessibleRegion.java | 12 ++++++++++ .../roi/util/IterableRegionOnBooleanRAI.java | 12 ++++++++++ .../PositionableWrappedIterableInterval.java | 12 ++++++++++ .../PositionableWrappedIterableRegion.java | 22 +++++++++++++++++-- .../net/imglib2/roi/util/SamplingCursor.java | 6 +++++ .../roi/util/SamplingIterableInterval.java | 6 +++++ 24 files changed, 212 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/imglib2/labeling/DefaultROIStrategy.java b/src/main/java/net/imglib2/labeling/DefaultROIStrategy.java index d28f1073..87e750aa 100644 --- a/src/main/java/net/imglib2/labeling/DefaultROIStrategy.java +++ b/src/main/java/net/imglib2/labeling/DefaultROIStrategy.java @@ -44,6 +44,7 @@ import net.imglib2.roi.AbstractIterableRegionOfInterest; import net.imglib2.roi.IterableRegionOfInterest; import net.imglib2.roi.RegionOfInterest; +import net.imglib2.type.logic.BitType; /** * A relatively conservative strategy suitable for blobby objects - retain the @@ -329,6 +330,11 @@ public void move( final double[] displacement ) throw new UnsupportedOperationException( "yet to be implemented" ); } + @Override + public BitType getType() + { + return new BitType(); + } } @Override diff --git a/src/main/java/net/imglib2/labeling/NativeImgLabeling.java b/src/main/java/net/imglib2/labeling/NativeImgLabeling.java index 04994809..9a6a3c76 100644 --- a/src/main/java/net/imglib2/labeling/NativeImgLabeling.java +++ b/src/main/java/net/imglib2/labeling/NativeImgLabeling.java @@ -226,4 +226,10 @@ public Cursor< LabelingType< T > > localizingCursor( final Interval interval ) return new LabelingConvertedCursor< I, T >( c, generation, mapping ); } + + @Override + public LabelingType< T > getType() + { + return new LabelingType<>( null, mapping, generation ); + } } diff --git a/src/main/java/net/imglib2/roi/AbstractIterableRegionOfInterest.java b/src/main/java/net/imglib2/roi/AbstractIterableRegionOfInterest.java index 84477a78..baa5ccdc 100644 --- a/src/main/java/net/imglib2/roi/AbstractIterableRegionOfInterest.java +++ b/src/main/java/net/imglib2/roi/AbstractIterableRegionOfInterest.java @@ -326,6 +326,12 @@ public T get() return randomAccess.get(); } + @Override + public T getType() + { + return randomAccess.getType(); + } + @Override public void jumpFwd( final long steps ) { @@ -402,6 +408,12 @@ public long size() return getCachedSize(); } + @Override + public T getType() + { + return src.getType(); + } + @Override public T firstElement() { diff --git a/src/main/java/net/imglib2/roi/BinaryMaskRegionOfInterest.java b/src/main/java/net/imglib2/roi/BinaryMaskRegionOfInterest.java index e42c4909..a5944d1f 100644 --- a/src/main/java/net/imglib2/roi/BinaryMaskRegionOfInterest.java +++ b/src/main/java/net/imglib2/roi/BinaryMaskRegionOfInterest.java @@ -127,6 +127,12 @@ public TT get() return src.get(); } + @Override + public TT getType() + { + return src.getType(); + } + @Override public void fwd() { @@ -215,6 +221,12 @@ public TT firstElement() return src.get(); } + @Override + public TT getType() + { + return src.getType(); + } + @Override public Object iterationOrder() { diff --git a/src/main/java/net/imglib2/roi/RegionOfInterest.java b/src/main/java/net/imglib2/roi/RegionOfInterest.java index 596c170c..a406b005 100644 --- a/src/main/java/net/imglib2/roi/RegionOfInterest.java +++ b/src/main/java/net/imglib2/roi/RegionOfInterest.java @@ -59,4 +59,10 @@ public interface RegionOfInterest extends RealRandomAccessibleRealInterval< BitT void move( double displacement, int d ); void move( double[] displacement ); + + @Override + default BitType getType() + { + return new BitType(); + } } diff --git a/src/main/java/net/imglib2/roi/boundary/Boundary.java b/src/main/java/net/imglib2/roi/boundary/Boundary.java index 74d3580e..9e292cb3 100644 --- a/src/main/java/net/imglib2/roi/boundary/Boundary.java +++ b/src/main/java/net/imglib2/roi/boundary/Boundary.java @@ -11,13 +11,13 @@ * %% * 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 @@ -135,6 +135,12 @@ public RandomAccess< BoolType > randomAccess( final Interval interval ) return randomAccess(); } + @Override + public BoolType getType() + { + return new BoolType(); + } + private final class BoundaryIterable extends AbstractWrappedInterval< Interval > implements IterableInterval< Void > { BoundaryIterable() @@ -177,6 +183,12 @@ public Void firstElement() { return cursor().next(); } + + @Override + public Void getType() + { + return null; + } } private final class BoundaryCursor extends Point implements Cursor< Void > diff --git a/src/main/java/net/imglib2/roi/boundary/BoundaryRandomAccess4.java b/src/main/java/net/imglib2/roi/boundary/BoundaryRandomAccess4.java index 50f8c603..62a575bb 100644 --- a/src/main/java/net/imglib2/roi/boundary/BoundaryRandomAccess4.java +++ b/src/main/java/net/imglib2/roi/boundary/BoundaryRandomAccess4.java @@ -117,6 +117,12 @@ public BoolType get() return type; } + @Override + public BoolType getType() + { + return type; + } + @Override public BoundaryRandomAccess4< T > copy() { diff --git a/src/main/java/net/imglib2/roi/boundary/BoundaryRandomAccess8.java b/src/main/java/net/imglib2/roi/boundary/BoundaryRandomAccess8.java index a59c5613..2af918dc 100644 --- a/src/main/java/net/imglib2/roi/boundary/BoundaryRandomAccess8.java +++ b/src/main/java/net/imglib2/roi/boundary/BoundaryRandomAccess8.java @@ -145,6 +145,12 @@ public BoolType get() return type; } + @Override + public BoolType getType() + { + return type; + } + @Override public BoundaryRandomAccess8< T > copy() { diff --git a/src/main/java/net/imglib2/roi/geom/integer/IterableLine.java b/src/main/java/net/imglib2/roi/geom/integer/IterableLine.java index 36f1eb6b..a8aca650 100644 --- a/src/main/java/net/imglib2/roi/geom/integer/IterableLine.java +++ b/src/main/java/net/imglib2/roi/geom/integer/IterableLine.java @@ -164,6 +164,12 @@ public Cursor< Void > localizingCursor() return new LineCursor(); } + @Override + public Void getType() + { + return null; + } + private final class LineCursor implements Cursor< Void > { diff --git a/src/main/java/net/imglib2/roi/labeling/ImgLabeling.java b/src/main/java/net/imglib2/roi/labeling/ImgLabeling.java index 5bf1b70f..8479ec45 100644 --- a/src/main/java/net/imglib2/roi/labeling/ImgLabeling.java +++ b/src/main/java/net/imglib2/roi/labeling/ImgLabeling.java @@ -167,6 +167,12 @@ public LabelingType< T > get() return type; } + @Override + public LabelingType< T > getType() + { + return type; + } + @Override public LabelingConvertedRandomAccess copy() { @@ -191,6 +197,12 @@ public LabelingType< T > get() return type; } + @Override + public LabelingType< T > getType() + { + return type; + } + @Override public LabelingConvertedCursor copy() { @@ -228,6 +240,12 @@ public LabelingType< T > firstElement() return cursor().next(); } + @Override + public LabelingType< T > getType() + { + return new LabelingType<>( null, mapping, generation ); + } + @Override public Iterator< LabelingType< T > > iterator() { diff --git a/src/main/java/net/imglib2/roi/labeling/LabelRegion.java b/src/main/java/net/imglib2/roi/labeling/LabelRegion.java index 88df4f6c..9f18492b 100644 --- a/src/main/java/net/imglib2/roi/labeling/LabelRegion.java +++ b/src/main/java/net/imglib2/roi/labeling/LabelRegion.java @@ -180,6 +180,12 @@ public RandomAccess< BoolType > randomAccess( final Interval interval ) return new OutOfBoundsConstantValue<>( this, new BoolType( false ) ); } + @Override + public BoolType getType() + { + return new BoolType(); + } + @Override public PositionableIterableInterval< Void > inside() { @@ -218,6 +224,12 @@ public Void firstElement() return null; } + @Override + public Void getType() + { + return null; + } + @Override public Object iterationOrder() { diff --git a/src/main/java/net/imglib2/roi/labeling/LabelRegionRandomAccess.java b/src/main/java/net/imglib2/roi/labeling/LabelRegionRandomAccess.java index 68ba72fd..1166067c 100644 --- a/src/main/java/net/imglib2/roi/labeling/LabelRegionRandomAccess.java +++ b/src/main/java/net/imglib2/roi/labeling/LabelRegionRandomAccess.java @@ -88,6 +88,12 @@ public BoolType get() return type; } + @Override + public BoolType getType() + { + return type; + } + @Override public LabelRegionRandomAccess< T > copy() { diff --git a/src/main/java/net/imglib2/roi/mask/integer/MaskAsRandomAccessible.java b/src/main/java/net/imglib2/roi/mask/integer/MaskAsRandomAccessible.java index 0fb15f22..7f8014af 100644 --- a/src/main/java/net/imglib2/roi/mask/integer/MaskAsRandomAccessible.java +++ b/src/main/java/net/imglib2/roi/mask/integer/MaskAsRandomAccessible.java @@ -88,4 +88,9 @@ public RandomAccess< B > randomAccess( final Interval interval ) return randomAccess(); } + @Override + public B getType() + { + return type; + } } diff --git a/src/main/java/net/imglib2/roi/mask/integer/MaskIntervalAsRandomAccessibleInterval.java b/src/main/java/net/imglib2/roi/mask/integer/MaskIntervalAsRandomAccessibleInterval.java index 120a54ce..f281e516 100644 --- a/src/main/java/net/imglib2/roi/mask/integer/MaskIntervalAsRandomAccessibleInterval.java +++ b/src/main/java/net/imglib2/roi/mask/integer/MaskIntervalAsRandomAccessibleInterval.java @@ -78,4 +78,10 @@ public RandomAccess< B > randomAccess( final Interval interval ) { return randomAccess(); } + + @Override + public B getType() + { + return type; + } } diff --git a/src/main/java/net/imglib2/roi/mask/integer/MaskPredicateRandomAccess.java b/src/main/java/net/imglib2/roi/mask/integer/MaskPredicateRandomAccess.java index 6b81a3b6..fb70c68e 100644 --- a/src/main/java/net/imglib2/roi/mask/integer/MaskPredicateRandomAccess.java +++ b/src/main/java/net/imglib2/roi/mask/integer/MaskPredicateRandomAccess.java @@ -73,6 +73,12 @@ public B get() return type; } + @Override + public B getType() + { + return type; + } + @Override public MaskPredicateRandomAccess< B > copy() { diff --git a/src/main/java/net/imglib2/roi/mask/real/MaskPredicateRealRandomAccess.java b/src/main/java/net/imglib2/roi/mask/real/MaskPredicateRealRandomAccess.java index 63ca3852..f94d3d8e 100644 --- a/src/main/java/net/imglib2/roi/mask/real/MaskPredicateRealRandomAccess.java +++ b/src/main/java/net/imglib2/roi/mask/real/MaskPredicateRealRandomAccess.java @@ -75,6 +75,12 @@ public B get() return type; } + @Override + public B getType() + { + return type; + } + @Override public MaskPredicateRealRandomAccess< B > copy() { diff --git a/src/main/java/net/imglib2/roi/mask/real/RealMaskAsRealRandomAccessible.java b/src/main/java/net/imglib2/roi/mask/real/RealMaskAsRealRandomAccessible.java index c71da7fb..368ff918 100644 --- a/src/main/java/net/imglib2/roi/mask/real/RealMaskAsRealRandomAccessible.java +++ b/src/main/java/net/imglib2/roi/mask/real/RealMaskAsRealRandomAccessible.java @@ -81,4 +81,9 @@ public RealRandomAccess< B > realRandomAccess( final RealInterval interval ) return realRandomAccess(); } + @Override + public B getType() + { + return type; + } } diff --git a/src/main/java/net/imglib2/roi/mask/real/RealMaskRealIntervalAsRealRandomAccessibleRealInterval.java b/src/main/java/net/imglib2/roi/mask/real/RealMaskRealIntervalAsRealRandomAccessibleRealInterval.java index eed9e745..f465a554 100644 --- a/src/main/java/net/imglib2/roi/mask/real/RealMaskRealIntervalAsRealRandomAccessibleRealInterval.java +++ b/src/main/java/net/imglib2/roi/mask/real/RealMaskRealIntervalAsRealRandomAccessibleRealInterval.java @@ -70,4 +70,10 @@ public RealRandomAccess< B > realRandomAccess( final RealInterval interval ) { return realRandomAccess(); } + + @Override + public B getType() + { + return type; + } } diff --git a/src/main/java/net/imglib2/roi/util/IterableRandomAccessibleRegion.java b/src/main/java/net/imglib2/roi/util/IterableRandomAccessibleRegion.java index 7dca8391..258eb65c 100644 --- a/src/main/java/net/imglib2/roi/util/IterableRandomAccessibleRegion.java +++ b/src/main/java/net/imglib2/roi/util/IterableRandomAccessibleRegion.java @@ -90,6 +90,12 @@ public RandomAccess< T > randomAccess( final Interval interval ) return sourceInterval.randomAccess( interval ); } + @Override + public T getType() + { + return sourceInterval.getType(); + } + @Override public IterableInterval< Void > inside() { @@ -140,5 +146,11 @@ public Cursor< Void > localizingCursor() { return cursor(); } + + @Override + public Void getType() + { + return null; + } } } diff --git a/src/main/java/net/imglib2/roi/util/IterableRegionOnBooleanRAI.java b/src/main/java/net/imglib2/roi/util/IterableRegionOnBooleanRAI.java index 92d8c0d6..81b39361 100644 --- a/src/main/java/net/imglib2/roi/util/IterableRegionOnBooleanRAI.java +++ b/src/main/java/net/imglib2/roi/util/IterableRegionOnBooleanRAI.java @@ -89,6 +89,12 @@ public RandomAccess< T > randomAccess( final Interval interval ) return sourceInterval.randomAccess( interval ); } + @Override + public T getType() + { + return sourceInterval.getType(); + } + @Override public IterableInterval< Void > inside() { @@ -139,5 +145,11 @@ public Cursor< Void > localizingCursor() { return new TrueCursor< T >( sourceIterable.localizingCursor(), size ); } + + @Override + public Void getType() + { + return null; + } } } diff --git a/src/main/java/net/imglib2/roi/util/PositionableWrappedIterableInterval.java b/src/main/java/net/imglib2/roi/util/PositionableWrappedIterableInterval.java index b33d4a14..b09e91b1 100644 --- a/src/main/java/net/imglib2/roi/util/PositionableWrappedIterableInterval.java +++ b/src/main/java/net/imglib2/roi/util/PositionableWrappedIterableInterval.java @@ -106,6 +106,12 @@ public Cursor< T > localizingCursor() return new PositionableIterableIntervalCursor( source.localizingCursor() ); } + @Override + public T getType() + { + return source.getType(); + } + class PositionableIterableIntervalCursor extends OffsetLocalizable< Cursor< T > > implements Cursor< T > { public PositionableIterableIntervalCursor( final Cursor< T > cursor ) @@ -119,6 +125,12 @@ public T get() return source.get(); } + @Override + public T getType() + { + return source.getType(); + } + @Override public void jumpFwd( final long steps ) { diff --git a/src/main/java/net/imglib2/roi/util/PositionableWrappedIterableRegion.java b/src/main/java/net/imglib2/roi/util/PositionableWrappedIterableRegion.java index a638a5b7..08093c81 100644 --- a/src/main/java/net/imglib2/roi/util/PositionableWrappedIterableRegion.java +++ b/src/main/java/net/imglib2/roi/util/PositionableWrappedIterableRegion.java @@ -11,13 +11,13 @@ * %% * 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 @@ -84,6 +84,12 @@ public RandomAccess< T > randomAccess( final Interval interval ) return new RA( source.randomAccess( Intervals.translate( interval, currentOffset ) ), currentOffset ); } + @Override + public T getType() + { + return source.getType(); + } + private final class RA extends OffsetPositionableLocalizable< RandomAccess< T > > implements RandomAccess< T > { public RA( final RandomAccess< T > source, final long[] offset ) @@ -97,6 +103,12 @@ public T get() return source.get(); } + @Override + public T getType() + { + return source.getType(); + } + @Override public RA copy() { @@ -170,6 +182,12 @@ public long max( final int d ) { return PositionableWrappedIterableRegion.this.max( d ); } + + @Override + public Void getType() + { + return null; + } } private final class PositionableInsideCursor extends OffsetLocalizable< Cursor< Void > > implements Cursor< Void > diff --git a/src/main/java/net/imglib2/roi/util/SamplingCursor.java b/src/main/java/net/imglib2/roi/util/SamplingCursor.java index dbc3316d..fedb9660 100644 --- a/src/main/java/net/imglib2/roi/util/SamplingCursor.java +++ b/src/main/java/net/imglib2/roi/util/SamplingCursor.java @@ -54,6 +54,12 @@ public T get() return target.get(); } + @Override + public T getType() + { + return target.getType(); + } + @Override public SamplingCursor< T > copy() { diff --git a/src/main/java/net/imglib2/roi/util/SamplingIterableInterval.java b/src/main/java/net/imglib2/roi/util/SamplingIterableInterval.java index 296e1685..5d49f731 100644 --- a/src/main/java/net/imglib2/roi/util/SamplingIterableInterval.java +++ b/src/main/java/net/imglib2/roi/util/SamplingIterableInterval.java @@ -91,4 +91,10 @@ public Iterator< T > iterator() { return cursor(); } + + @Override + public T getType() + { + return target.getType(); + } }