|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.ac.starlink.array.NDShape
public class NDShape
Represents the shape of an N-dimensional rectangular array.
The shape is represented by an N-element array of longs giving the
origin (coordinates of the first pixel) and another N-element array
of longs giving the dimensions (number of pixels in each dimension).
This shape is considered to contain pixels with coordinate
origin[i]<=pos[i]<origin[i]+dims[i]
in each dimension i.
An Iterator over all these pixels may be obtained by using the
OrderedNDShape
class.
This object is immutable.
Field Summary | |
---|---|
static long |
DEFAULT_ORIGIN
The default value of the origin in each dimension; its value is 1. |
Constructor Summary | |
---|---|
NDShape(int[] dims)
Creates an NDShape object with a default origin from an integer array of dimensions. |
|
NDShape(long[] dims)
Creates an NDShape object with a default origin from its dimensions. |
|
NDShape(long[] origin,
int[] dims)
Creates an NDShape object from its origin and an integer array of dimensions. |
|
NDShape(long[] origin,
long[] dims)
Creates an NDShape object from its origin and dimensions. |
|
NDShape(NDShape shape)
Creates an NDShape object with the same origin and dimensions as an existing one. |
Method Summary | |
---|---|
Object |
clone()
|
boolean |
equals(Object other)
|
static NDShape |
fromString(String str)
Turns a string specification of a shape into an NDShape object. |
long[] |
getDims()
Returns the extents in each dimension of the NDShape. |
long[] |
getLimits()
Returns the exclusive upper limits in each dimension of the NDShape. |
int |
getNumDims()
Returns the dimensionality of the NDShape. |
long |
getNumPixels()
Returns the number of cells in the array represented by this NDShape. |
long[] |
getOrigin()
Returns the origin in each dimension of the NDShape. |
long[] |
getUpperBounds()
Returns the inclusive upper limits in each dimension of the NDShape. |
int |
hashCode()
|
NDShape |
intersection(NDShape other)
Returns a NDShape giving the intersection between this shape and another one. |
static long[] |
intsToLongs(int[] iarray)
Convenience method for converting an array of int values to an array of long values. |
static int[] |
longsToInts(long[] larray)
Convenience method for converting an array of long values to an array of int values. |
boolean |
sameShape(NDShape other)
Indicates whether another object represents the same shape as this. |
String |
toString()
|
static String |
toString(long[] pos)
Returns a string representation of a position. |
static String |
toString(NDShape shape)
Returns a string representation of a shape. |
NDShape |
union(NDShape other)
Returns a NDShape giving the union of this shape and another one. |
boolean |
within(long[] pos)
Indicates whether a given point is within this shape. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final long DEFAULT_ORIGIN
Constructor Detail |
---|
public NDShape(long[] origin, long[] dims)
origin
- an array representing the origindims
- an array representing the dimension extents
IllegalArgumentException
- if origin and dims have different
lengths or any of the dimensions are not positivepublic NDShape(long[] origin, int[] dims)
origin
- an array representing the origindims
- an array representing the dimension extents
IllegalArgumentException
- if origin and dims have different
lengths or any of the dimensions are not positivepublic NDShape(long[] dims)
DEFAULT_ORIGIN
.
dims
- an array representing the dimension extents
IllegalArgumentExceptoin
- if any of the dimensions are
not positivepublic NDShape(int[] dims)
DEFAULT_ORIGIN
.
dims
- an array representing the dimension extents
IllegalArgumentExceptoin
- if any of the dimensions are
not positivepublic NDShape(NDShape shape)
OrderedNDShape
.
shape
- existing NDShape objectMethod Detail |
---|
public long[] getOrigin()
public long[] getDims()
public long[] getLimits()
limits[i]=origin[i]+dims[i]
.
public long[] getUpperBounds()
limits[i]=origin[i]+dims[i]-1
.
public int getNumDims()
public long getNumPixels()
public NDShape intersection(NDShape other)
other
- the other shape
IllegalArgumentException
- if the other has a different
dimensionality to this shapepublic NDShape union(NDShape other)
other
- the other shape
IllegalArgumentException
- if the other has a different
dimensionality to this shapepublic boolean within(long[] pos)
pos
- the coordinates of a position
i
,
origin[i]<=pos[i]<origin[i]+dims[i]
public boolean sameShape(NDShape other)
other
- an NDShape object for comparison with this onepublic boolean equals(Object other)
equals
in class Object
public int hashCode()
hashCode
in class Object
public Object clone()
clone
in class Object
public String toString()
toString
in class Object
public static String toString(NDShape shape)
As a special case, if any of the origin elements has the value Long.MIN_VALUE, then a "*" is written in the corresponding position.
shape
- the shape to describe
public static String toString(long[] pos)
As a special case, if any of the elements has the value Long.MIN_VALUE, then a "*" is written in the corresponding position.
pos
- a vector of longs
public static NDShape fromString(String str)
toString()
.
Each dimension specification is separated from the next using a comma, and may be given as lower:upper inclusive bounds or origin+dimension. So a 100x100 array with origin (50,50) may be written:
50:149,50:149or
50+100,50+100Straggling whitespace is tolerated.
str
- the string representing the shape.
IllegalArgumentException
- if str does not match
one of the understood formats for a shapepublic static long[] intsToLongs(int[] iarray)
iarray
- an array of integers
public static int[] longsToInts(long[] larray)
larray
- an array of long integers
IndexOutOfBoundsException
- if any of the elements of
larray is out of the range
Integer.MIN_VALUE..Integer.MAX_VALUE
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |