public class NDShape
extends java.lang.Object
implements java.lang.Cloneable
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.
Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_ORIGIN
The default value of the origin in each dimension; its value is 1.
|
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone() |
boolean |
equals(java.lang.Object other) |
static NDShape |
fromString(java.lang.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.
|
java.lang.String |
toString() |
static java.lang.String |
toString(long[] pos)
Returns a string representation of a position.
|
static java.lang.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.
|
public static final long DEFAULT_ORIGIN
public NDShape(long[] origin, long[] dims)
origin
- an array representing the origindims
- an array representing the dimension extentsjava.lang.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 extentsjava.lang.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 extentsIllegalArgumentExceptoin
- if any of the dimensions are
not positivepublic NDShape(int[] dims)
DEFAULT_ORIGIN
.dims
- an array representing the dimension extentsIllegalArgumentExceptoin
- if any of the dimensions are
not positivepublic NDShape(NDShape shape)
OrderedNDShape
.shape
- existing NDShape objectpublic 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 shapejava.lang.IllegalArgumentException
- if the other has a different
dimensionality to this shapepublic NDShape union(NDShape other)
other
- the other shapejava.lang.IllegalArgumentException
- if the other has a different
dimensionality to this shapepublic boolean within(long[] pos)
pos
- the coordinates of a positioni
,
origin[i]<=pos[i]<origin[i]+dims[i]
public boolean sameShape(NDShape other)
other
- an NDShape object for comparison with this onepublic boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.Object clone()
clone
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public static java.lang.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 describepublic static java.lang.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 longspublic static NDShape fromString(java.lang.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.java.lang.IllegalArgumentException
- if str does not match
one of the understood formats for a shapepublic static long[] intsToLongs(int[] iarray)
iarray
- an array of integerspublic static int[] longsToInts(long[] larray)
larray
- an array of long integersjava.lang.IndexOutOfBoundsException
- if any of the elements of
larray is out of the range
Integer.MIN_VALUE..Integer.MAX_VALUECopyright © 2017 Central Laboratory of the Research Councils. All Rights Reserved.