public class NDShape extends Object implements 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 |
---|---|
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.
|
public static final long DEFAULT_ORIGIN
public NDShape(long[] origin, long[] dims)
origin
- an array representing the origindims
- an array representing the dimension extentsIllegalArgumentException
- 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 extentsIllegalArgumentException
- 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 extentsIllegalArgumentException
- if any of the dimensions are
not positivepublic NDShape(int[] dims)
DEFAULT_ORIGIN
.dims
- an array representing the dimension extentsIllegalArgumentException
- if any of the dimensions are
not positivepublic NDShape(NDShape shape)
NDShape
from an 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 shapeIllegalArgumentException
- if the other has a different
dimensionality to this shapepublic NDShape union(NDShape other)
other
- the other shapeIllegalArgumentException
- 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 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 describepublic 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 longspublic 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)
int
values
to an array of long
values.iarray
- an array of integersiarray
public static int[] longsToInts(long[] larray)
long
values
to an array of int
values. Unlike a normal java typecast,
if a conversion overflow occurs an IndexOutOfBoundsException
will be thrown.larray
- an array of long integerslarray
IndexOutOfBoundsException
- if any of the elements of
larray
is out of the range
Integer.MIN_VALUE..Integer.MAX_VALUE
Copyright © 2025 Central Laboratory of the Research Councils. All Rights Reserved.