Class Intervals


  • public class Intervals
    extends java.lang.Object
    Convenience methods for manipulating Intervals.
    • Constructor Detail

      • Intervals

        public Intervals()
    • Method Detail

      • createMinSize

        public static FinalInterval createMinSize​(long... minsize)
        Create a FinalInterval from a parameter list comprising minimum coordinates and size. For example, to create a 2D interval from (10, 10) to (20, 40) use createMinSize( 10, 10, 11, 31 ).
        Parameters:
        minsize - a list of 2*n parameters to create a n -dimensional interval. The first n parameters specify the minimum of the interval, the next n parameters specify the dimensions of the interval.
        Returns:
        interval with the specified boundaries
      • createMinMax

        public static FinalInterval createMinMax​(long... minmax)
        Create a FinalInterval from a parameter list comprising minimum and maximum coordinates. For example, to create a 2D interval from (10, 10) to (20, 40) use createMinMax( 10, 10, 20, 40 ).
        Parameters:
        minmax - a list of 2*n parameters to create a n -dimensional interval. The first n parameters specify the minimum of the interval, the next n parameters specify the maximum of the interval.
        Returns:
        interval with the specified boundaries
      • createMinSizeReal

        @Deprecated
        public static FinalRealInterval createMinSizeReal​(double... minsize)
        Deprecated.
        THIS METHOD WILL BE REMOVED IN A FUTURE RELEASE. It was mistakenly introduced, analogous to createMinSize(long...) for integer intervals. Dimension is not defined for RealInterval and computing the max as min + dim - 1 does not make sense.

        Create a FinalRealInterval from a parameter list comprising minimum coordinates and size. For example, to create a 2D interval from (10, 10) to (20, 40) use createMinSize( 10, 10, 11, 31 ).

        Parameters:
        minsize - a list of 2*n parameters to create a n -dimensional interval. The first n parameters specify the minimum of the interval, the next n parameters specify the dimensions of the interval.
        Returns:
        interval with the specified boundaries
      • createMinMaxReal

        public static FinalRealInterval createMinMaxReal​(double... minmax)
        Create a FinalRealInterval from a parameter list comprising minimum and maximum coordinates. For example, to create a 2D interval from (10, 10) to (20, 40) use createMinMax( 10, 10, 20, 40 ).
        Parameters:
        minmax - a list of 2*n parameters to create a n -dimensional interval. The first n parameters specify the minimum of the interval, the next n parameters specify the maximum of the interval.
        Returns:
        interval with the specified boundaries
      • expand

        public static FinalInterval expand​(Interval interval,
                                           long border)
        Grow/shrink an interval in all dimensions. Create a FinalInterval, which is the input interval plus border pixels on every side, in every dimension.
        Parameters:
        interval - the input interval
        border - how many pixels to add on every side
        Returns:
        expanded interval
      • expand

        public static FinalInterval expand​(Interval interval,
                                           long... border)
        Grow/shrink an interval in all dimensions. Create a FinalInterval, which is the input interval plus border pixels on every side, in every dimension.
        Parameters:
        interval - the input interval
        border - how many pixels to add on every side
        Returns:
        expanded interval
      • expand

        public static FinalInterval expand​(Interval interval,
                                           Dimensions border)
        Grow/shrink an interval in all dimensions. Create a FinalInterval, which is the input interval plus border pixels on every side, in every dimension.
        Parameters:
        interval - the input interval
        border - how many pixels to add on every side
        Returns:
        expanded interval
      • expand

        public static FinalInterval expand​(Interval interval,
                                           long border,
                                           int d)
        Grow/shrink an interval in one dimensions. Create a FinalInterval, which is the input interval plus border pixels on every side, in dimension d.
        Parameters:
        interval - the input interval
        border - how many pixels to add on every side
        d - in which dimension
        Returns:
        expanded interval
      • translate

        public static FinalInterval translate​(Interval interval,
                                              long t,
                                              int d)
        Translate an interval in one dimension. Create a FinalInterval, which is the input interval shifted by t in dimension d.
        Parameters:
        interval - the input interval
        t - by how many pixels to shift the interval
        d - in which dimension
        Returns:
        translated interval
      • translate

        public static FinalInterval translate​(Interval interval,
                                              long... translation)
        Translate an interval. Create a FinalInterval, which is the input interval shifted by translation.
        Parameters:
        interval - the input interval
        translation - by how many pixels to shift the interval
        Returns:
        translated interval
      • translateInverse

        public static FinalInterval translateInverse​(Interval interval,
                                                     long... translation)
        Translate an interval by -translation. Create a FinalInterval, which is the input interval shifted by -translation.
        Parameters:
        interval - the input interval
        translation - by how many pixels to inverse-shift the interval
        Returns:
        translated interval
      • addDimension

        public static FinalInterval addDimension​(Interval interval,
                                                 long minOfNewDim,
                                                 long maxOfNewDim)
        Create new interval by adding a dimension to the source Interval. The Interval boundaries in the additional dimension are set to the specified values. The additional dimension is the last dimension.
        Parameters:
        interval - the original interval
        minOfNewDim - Interval min in the additional dimension.
        maxOfNewDim - Interval max in the additional dimension.
      • invertAxis

        public static FinalInterval invertAxis​(Interval interval,
                                               int d)
        Invert the bounds on the d-axis of the given interval
        Parameters:
        interval - the source
        d - the axis to invert
      • hyperSlice

        public static FinalInterval hyperSlice​(Interval interval,
                                               int d)
        Take a (n-1)-dimensional slice of a n-dimensional interval, dropping the d axis.
      • moveAxis

        public static FinalInterval moveAxis​(Interval interval,
                                             int fromAxis,
                                             int toAxis)
        Create an interval with permuted axes. The fromAxis is moved to toAxis, while the order of the other axes is preserved. If fromAxis=2 and toAxis=4, and axis order of interval was XYCZT, then an interval with axis order XYZTC would be created.
      • permuteAxes

        public static FinalInterval permuteAxes​(Interval interval,
                                                int fromAxis,
                                                int toAxis)
        Create an interval with permuted axes. fromAxis and toAxis are swapped. If fromAxis=0 and toAxis=2, this means that the X-axis of the source interval is mapped to the Z-Axis of the permuted interval and vice versa. For a XYZ source, a ZYX interval would be created.
      • rotate

        public static FinalInterval rotate​(Interval interval,
                                           int fromAxis,
                                           int toAxis)
        Create an interval that is rotated by 90 degrees. The rotation is specified by the fromAxis and toAxis arguments. If fromAxis=0 and toAxis=1, this means that the X-axis of the source interval is mapped to the Y-Axis of the rotated interval. That is, it corresponds to a 90 degree clock-wise rotation of the source interval in the XY plane. fromAxis=1 and toAxis=0 corresponds to a counter-clock-wise rotation in the XY plane.
      • zeroMin

        public static FinalInterval zeroMin​(Interval interval)
        Returns an Interval with the same dimensions as the given interval, but min is all zero.
      • intersect

        public static FinalInterval intersect​(Interval intervalA,
                                              Interval intervalB)
        Compute the intersection of two intervals. Create a FinalInterval , which is the intersection of the input intervals (i.e., the area contained in both input intervals).
        Parameters:
        intervalA - input interval
        intervalB - input interval
        Returns:
        intersection of input intervals
      • intersect

        public static FinalRealInterval intersect​(RealInterval intervalA,
                                                  RealInterval intervalB)
        Compute the intersection of two intervals. Create a RealInterval , which is the intersection of the input intervals (i.e., the area contained in both input intervals).
        Parameters:
        intervalA - input interval
        intervalB - input interval
        Returns:
        intersection of input intervals
      • unionUnsafe

        public static FinalInterval unionUnsafe​(Interval intervalA,
                                                Interval intervalB)
        Compute the smallest interval that contains both input intervals. Create a FinalInterval that represents that interval. May produce unexpected results for empty Intervals. Use union(Interval, Interval) if either input interval could be empty.
        Parameters:
        intervalA - input interval
        intervalB - input interval
        Returns:
        union of input intervals
      • union

        public static FinalInterval union​(Interval intervalA,
                                          Interval intervalB)
        Compute the smallest interval that contains both input intervals. Create a FinalInterval that represents that interval.
        Parameters:
        intervalA - input interval
        intervalB - input interval
        Returns:
        union of input intervals
      • union

        public static FinalRealInterval union​(RealInterval intervalA,
                                              RealInterval intervalB)
        Compute the smallest interval that contains both input intervals. Create a RealInterval that represents that interval.
        Parameters:
        intervalA - input interval
        intervalB - input interval
        Returns:
        union of input intervals
      • smallestContainingInterval

        public static Interval smallestContainingInterval​(RealInterval ri)
        Compute the smallest Interval containing the specified RealInterval.
        Parameters:
        ri - input interval.
        Returns:
        the smallest integer interval that completely contains the input interval.
      • largestContainedInterval

        public static Interval largestContainedInterval​(RealInterval ri)
        Compute the largest Interval that is contained in the specified RealInterval.
        Parameters:
        ri - input interval.
        Returns:
        the largest integer interval that is completely contained in the input interval.
      • isEmpty

        public static boolean isEmpty​(Interval interval)
        Check whether the given interval is empty, that is, the maximum is smaller than the minimum in some dimension.
        Parameters:
        interval - interval to check
        Returns:
        true when the interval is empty, that is, the maximum is smaller than the minimum in some dimension.
      • isEmpty

        public static boolean isEmpty​(RealInterval interval)
        Check whether the given interval is empty, that is, the maximum is smaller than the minimum in some dimension.
        Parameters:
        interval - interval to check
        Returns:
        true when the interval is empty, that is, the maximum is smaller than the minimum in some dimension.
      • contains

        public static boolean contains​(Interval containing,
                                       Localizable contained)
        Test whether the containing interval contains the contained point. The interval is closed, that is, boundary points are contained.
        Returns:
        true, iff contained is in containing.
      • contains

        public static boolean contains​(RealInterval containing,
                                       RealLocalizable contained)
        Test whether the containing interval contains the contained point. The interval is closed, that is, boundary points are contained.
        Returns:
        true, iff contained is in containing.
      • contains

        public static final boolean contains​(Interval containing,
                                             Interval contained)
        Test whether the containing interval completely contains the contained interval.
      • contains

        public static final boolean contains​(RealInterval containing,
                                             RealInterval contained)
        Test whether the containing interval completely contains the contained interval.
      • numElements

        public static long numElements​(Dimensions interval)
        Compute the number of elements contained in an (integer) Interval .
        Returns:
        number of elements in interval.
      • numElements

        public static long numElements​(int... dimensions)
        Compute the number of elements contained in an (integer) interval.
        Parameters:
        dimensions - dimensions of the interval.
        Returns:
        number of elements in the interval.
      • numElements

        public static long numElements​(long... dimensions)
        Compute the number of elements contained in an (integer) interval.
        Parameters:
        dimensions - dimensions of the interval.
        Returns:
        number of elements in the interval.
      • equals

        public static boolean equals​(Interval a,
                                     Interval b)
        Tests whether two intervals are equal in their min / max.
      • equals

        public static boolean equals​(RealInterval a,
                                     RealInterval b,
                                     double tolerance)
        Tests whether two RealIntervals are equal in their min / max. With respect to the given tolerance.
      • equalDimensions

        @Deprecated
        public static boolean equalDimensions​(Interval a,
                                              Interval b)
        Deprecated.
        Tests whether two intervals have equal dimensions (same size).
      • dimensionsAsLongArray

        public static long[] dimensionsAsLongArray​(Dimensions dimensions)
        Create a long[] with the dimensions of a Dimensions.

        Keep in mind that creating arrays wildly is not good practice and consider using the interval directly. See Dimensions.dimensions(long[]).

        Consider using the more convenient Dimensions.dimensionsAsLongArray(). This method may be deprecated in a future release.

        Parameters:
        dimensions - something which has dimensions
        Returns:
        dimensions as a new long[]
      • dimensionsAsIntArray

        public static int[] dimensionsAsIntArray​(Dimensions dimensions)
        Create a int[] with the dimensions of an Interval.

        Keep in mind that creating arrays wildly is not good practice and consider using the interval directly.

        Parameters:
        dimensions - something which has dimensions
        Returns:
        dimensions as a new int[]
      • minAsLongArray

        public static long[] minAsLongArray​(Interval interval)
        Create a long[] with the minimum of an Interval.

        Keep in mind that creating arrays wildly is not good practice and consider using the interval directly. See Interval.min(long[]).

        Consider using the more convenient Interval.minAsLongArray(). This method may be deprecated in a future release.

        Parameters:
        interval - something with interval boundaries
        Returns:
        minimum as a new long[]
      • minAsIntArray

        public static int[] minAsIntArray​(Interval interval)
        Create a int[] with the minimum of an Interval.

        Keep in mind that creating arrays wildly is not good practice and consider using the interval directly.

        Parameters:
        interval - something with interval boundaries
        Returns:
        minimum as a new int[]
      • maxAsLongArray

        public static long[] maxAsLongArray​(Interval interval)
        Create a long[] with the maximum of an Interval.

        Keep in mind that creating arrays wildly is not good practice and consider using the interval directly. See Interval.max(long[]).

        Consider using the more convenient Interval.maxAsLongArray(). This method may be deprecated in a future release.

        Parameters:
        interval - something with interval boundaries
        Returns:
        maximum as a new long[]
      • maxAsIntArray

        public static int[] maxAsIntArray​(Interval interval)
        Create a int[] with the maximum of an Interval.

        Keep in mind that creating arrays wildly is not good practice and consider using the interval directly.

        Parameters:
        interval - something with interval boundaries
        Returns:
        maximum as a new int[]
      • maxAsDoubleArray

        public static double[] maxAsDoubleArray​(RealInterval interval)
        Create a double[] with the maximum of a RealInterval .

        Keep in mind that creating arrays wildly is not good practice and consider using the interval directly. See RealInterval.realMax(double[]).

        Consider using the more convenient RealInterval.maxAsDoubleArray(). This method may be deprecated in a future release.

        Parameters:
        interval - something with interval boundaries
        Returns:
        maximum as a new double[]
      • minAsDoubleArray

        public static double[] minAsDoubleArray​(RealInterval interval)
        Create a double[] with the minimum of a RealInterval .

        Keep in mind that creating arrays wildly is not good practice and consider using the interval directly. See RealInterval.realMin(double[]).

        Consider using the more convenient RealInterval.minAsDoubleArray() This method may be deprecated in a future release.

        Parameters:
        interval - something with interval boundaries
        Returns:
        minimum as a new double[]
      • toString

        public static java.lang.String toString​(Interval value)
        Returns a string that contains min, max and the dimensions of the Interval.
      • toString

        public static java.lang.String toString​(RealInterval value)
        Returns a string that contains min and max of the RealInterval.
      • toString

        public static java.lang.String toString​(Dimensions value)
        Converts the Dimensions into a string.