Package uk.ac.starlink.array
Class OrderedNDShape
- java.lang.Object
-
- uk.ac.starlink.array.NDShape
-
- uk.ac.starlink.array.OrderedNDShape
-
- All Implemented Interfaces:
java.lang.Cloneable
public class OrderedNDShape extends NDShape implements java.lang.Cloneable
Represents the arrangement of pixels within an N-dimensional array. Instances of this class areNDShape
s with an additional ordering specified which indicates the sequence in which pixels are encountered. This class thus defines a mapping between an ordered sequence of positions and their coordinates in N-dimensional space.- Version:
- $Id$
- Author:
- Mark Taylor (Starlink)
-
-
Field Summary
-
Fields inherited from class uk.ac.starlink.array.NDShape
DEFAULT_ORIGIN
-
-
Constructor Summary
Constructors Constructor Description OrderedNDShape(long[] origin, long[] dims, Order order)
Creates an OrderedNDShape from its origin, dimensions and ordering.OrderedNDShape(long[] dims, Order order)
Creates an OrderedNDShape with a default origin from its dimensions and ordering.OrderedNDShape(NDShape shape)
Creates a new OrderedNDShape from an NDShape.OrderedNDShape(NDShape shape, Order order)
Creates an OrderedNDShape from a NDShape and an ordering.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
boolean
equals(java.lang.Object other)
Indicates whether another object is equivalent to this one.Order
getOrder()
Gets the ordering scheme of this object.int
hashCode()
long[]
offsetToPosition(long offset)
Determines the coordinates of a pixel at a given offset within the pixel sequence.java.util.Iterator
pixelIterator()
Returns an Iterator which will iterate over all the pixels in this OrderedNDShape's pixel sequence.java.util.Iterator
pixelIterator(long start, long length)
Returns an Iterator which will iterate over a range of pixels in this OrderedNDShape's pixel sequence.long
positionToOffset(long[] pos)
Returns the offset of a pixel having given coordinates within the sequence of pixels defined by this OrderedNDShape.boolean
sameSequence(OrderedNDShape other)
Indicates whether another object represents the same pixel sequence as this.java.lang.String
toString()
-
Methods inherited from class uk.ac.starlink.array.NDShape
fromString, getDims, getLimits, getNumDims, getNumPixels, getOrigin, getUpperBounds, intersection, intsToLongs, longsToInts, sameShape, toString, toString, union, within
-
-
-
-
Constructor Detail
-
OrderedNDShape
public OrderedNDShape(long[] origin, long[] dims, Order order)
Creates an OrderedNDShape from its origin, dimensions and ordering.- Parameters:
origin
- an array representing the origindims
- an array representing the dimension extentsorder
- an Order object specifying the pixel ordering scheme. If the null value is supplied, an arbitrary ordering scheme will be applied.- Throws:
java.lang.IllegalArgumentException
- if origin and dims have different lengths or any of the dimensions are not positive
-
OrderedNDShape
public OrderedNDShape(long[] dims, Order order)
Creates an OrderedNDShape with a default origin from its dimensions and ordering. Each element of the origin array has the valueNDShape.DEFAULT_ORIGIN
.- Parameters:
dims
- an array representing the dimension extentsorder
- an Order object specifying the pixel ordering scheme. If the null value is supplied, an arbitrary ordering scheme will be applied.- Throws:
java.lang.IllegalArgumentException
- if any of the dimensions are not positive
-
OrderedNDShape
public OrderedNDShape(NDShape shape, Order order)
Creates an OrderedNDShape from a NDShape and an ordering.- Parameters:
shape
- a NDShape objectorder
- an Order object specifying the pixel ordering scheme If the null value is supplied, an arbitrary ordering scheme will be applied.
-
OrderedNDShape
public OrderedNDShape(NDShape shape)
Creates a new OrderedNDShape from an NDShape. If shape is in fact an instance of OrderedNDShape, the created object will be equivalent to it. If not, a new OrderedNDShape object will be created with an arbitrary ordering scheme.- Parameters:
shape
- an NDShape or OrderedNDShape object
-
-
Method Detail
-
getOrder
public Order getOrder()
Gets the ordering scheme of this object.- Returns:
- an Order object indicating the ordering scheme
-
pixelIterator
public java.util.Iterator pixelIterator(long start, long length)
Returns an Iterator which will iterate over a range of pixels in this OrderedNDShape's pixel sequence. Thenext
method of the returned Iterator returns an array of longs giving the coordinates of the next pixel in the sequence. Note that this long array is the same object every time, but its contents change at each iteration. It should not be modified by clients.- Parameters:
start
- the first offset in the pixel sequence over which to iteratelength
- the number of pixels over which to iterate- Returns:
- an Iterator over cells
- Throws:
java.lang.IllegalArgumentException
- if start and length would imply iteration outside of this shape or length is negative
-
pixelIterator
public java.util.Iterator pixelIterator()
Returns an Iterator which will iterate over all the pixels in this OrderedNDShape's pixel sequence. Thenext
method of the returned Iterator returns an array of longs giving the coordinates of the next pixel in the sequence. Note that this long array is the same object every time, but its contents change at each iteration. It should not be modified by clients.Equivalent to
pixelIterator(0,getNumPixels())
;- Returns:
- an Iterator over cells
-
positionToOffset
public long positionToOffset(long[] pos)
Returns the offset of a pixel having given coordinates within the sequence of pixels defined by this OrderedNDShape. It will validate its input, and so may not be maximally efficient.- Parameters:
pos
- a coordinate vector giving a pixel position- Returns:
- the offset into this shape's pixel sequence at which the pixel at pos occurs
- Throws:
java.lang.IndexOutOfBoundsException
- if pos is outside this shape
-
offsetToPosition
public long[] offsetToPosition(long offset)
Determines the coordinates of a pixel at a given offset within the pixel sequence. It will validate its input, and so may not be maximally efficient.- Parameters:
offset
- an offset into the list of pixels- Returns:
- the coordinates of the pixel at offset
- Throws:
java.lang.IndexOutOfBoundsException
- if offset is outside this shape
-
sameSequence
public boolean sameSequence(OrderedNDShape other)
Indicates whether another object represents the same pixel sequence as this. Two shapes are the same if they have the same origins, dimensions and ordering scheme. A true result from this method implies that pixel iterators returned from the two objects will behave in exactly the same way (present the same pixel positions in the same order).- Parameters:
other
- the shape to compare with this one- Returns:
- true iff the pixel sequences are the same
-
equals
public boolean equals(java.lang.Object other)
Indicates whether another object is equivalent to this one.
-
-