Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class ncsa.horizon.util.Voxel

java.lang.Object
  |
  +--ncsa.horizon.util.Voxel
Subclasses:
MoveableVoxel, VolumeIterator

public class Voxel
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable
a generalized description of a point location in n-space.

A Voxel represents a position in a data space whose dimensions are specified in its constructor call. Positions in the space are described (naturally) by a vector giving the component of the position along each axis; these components can be queried, for example, via the getPos() method returning an integer array . Component positions restricted to the range of a regular integer; however, the positions are in general floating point numbers--that is, Voxels can describe fractional positions within the space. If a fractional position is desired, one can call getExactPos() (returning a double array).

(It should be noted that a Voxel object does not include the data value or color associated with the position. This is perhaps contrary to other uses of the term "voxel"--the author apologizes.)

It is assumed that most applications will be interested integer positions in the space (e.g. because the data exists at integer positions within a data array). Thus, the Voxel class is optimized for access to integer positions (via the IntLikeDblArray class), even when a Voxel is actually set to a fractions position. If a Voxel is set to a fractional position and one asks for a whole position by calling getPos(), the nearest whole position will be returned.

Components of the position can be accessed individually via the methods that take an axis index. The first axis has an index of zero.

In this implementation, Voxels are immutable--that is, they refer to a single position that cannot change. (This is a new with Horizon 2.0.) Thus, isMutable() always returns false. When Voxel.isMutable() returns false, objects can feel free to share a reference to the Voxel without worry about it changing. In contrast, a MoveableVoxel is change-able (isMutable() returns true). Voxel subclasses (like MoveableVoxel) should override their isMutable() methods to return true if they allow the position to change with time.

See also Volume, Slice, Segment, MoveableVoxel, VolumeIterator, and IntLikeDblArray.

See Also:
Serialized Form

Field Summary
static int MAX_AXIS_POSITION
          the maximum position along one axis that a Voxel can have.
 
Constructor Summary
Voxel(int nax)
          create a Voxel in a space of nax dimensions and initialize it to the origin (i.e. position = [0, 0, 0, ...]).
Voxel(int nax, int[] in)
          create a Voxel in a space of nax dimensions and initialize it with a position.
Voxel(int[] in)
          create a Voxel in a space of in.length dimensions and initialize it with a position.
Voxel(int nax, double[] in)
          create a Voxel in a space of nax dimensions and initialize it with a position.
Voxel(double[] in)
          create a Voxel in a space of nax dimensions and initialize it with a position.
Voxel(Voxel that)
          create an immutable Voxel positioned at the location of anoher Voxel
 
Method Summary
Voxel add(Voxel vox)
          return a Voxel that is the sum of this Voxel and the projection of another Voxel into this space.
double axisPos(int i)
          Deprecated. get the projection of the Voxel's position along the i-th axis.
java.lang.Object clone()
          create a deep copy of this Voxel
static int[] doubleToInt(double[] in)
          convert a double array to an integer array.
boolean equals(Voxel vox)
          return true if another Voxel is (in principle) at the same location as this Voxel.
boolean equals(java.lang.Object vox)
           
double getExactPos(int i)
          get the exact projection of the Voxel's position along the i-th axis.
double[] getExactPos()
          get the exact projection of the Voxel's position along the i-th axis.
java.util.Observable getMonitor()
          return an Observable monitor for listening for changes to this Voxel, or null if this Voxel is immutable.
int getNaxes()
          return the number of dimensions in the space containing this Voxel
int getPos(int i)
          get the projection of the Voxel's position along the i-th axis, rounded to the nearest integer.
int[] getPos()
          return the position of this voxel rounded to the nearest whole voxel
double[] getValues(int firstaxis)
          Deprecated. return an array of doubles representing the position along each axis
int hashCode()
          compute a hashcode for this Voxel.
static double[] intToDouble(int[] in)
          converts a integer array to double array.
boolean isMutable()
          return true if the position of this Voxel can change
static int[] roundDoubleToInt(double[] in)
          convert a double array to an integer array.
static int[] roundToInt(double[] in)
          round a double array to an integer array.
Voxel subtract(Voxel vox)
          return a Voxel that is the differenc of another Voxel from this Voxel
java.lang.String toString()
          converts position to (x, y, ...) formatted string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Field Detail

MAX_AXIS_POSITION

public static final int MAX_AXIS_POSITION
the maximum position along one axis that a Voxel can have.
Constructor Detail

Voxel

public Voxel(int nax)
      throws ValueOutOfBoundsException
create a Voxel in a space of nax dimensions and initialize it to the origin (i.e. position = [0, 0, 0, ...]).
Parameters:
nax - number of axes or dimensions in the space
Throws:
ValueOutOfBoundsException - thrown if nax < 0

Voxel

public Voxel(int nax,
             int[] in)
      throws ValueOutOfBoundsException
create a Voxel in a space of nax dimensions and initialize it with a position. The index of the first axis will be zero. This constructor should be preferred over Voxel(int, double[]) when the position is none to be whole valued.
Parameters:
nax - number of axes or dimensions in the space
in - an array containing the position. The first nax elements will be used. If the array size is smaller than nax, the remaining components will be 0.
Throws:
ValueOutOfBoundsException - thrown if nax < 0

Voxel

public Voxel(int[] in)
create a Voxel in a space of in.length dimensions and initialize it with a position. This constructor should be preferred over Voxel(double[]) when the position is none to be whole-valued.
Parameters:
in - an array containing the position. The first nax elements will be used. If the array size is smaller than nax, the remaining components will be 0.

Voxel

public Voxel(int nax,
             double[] in)
      throws ValueOutOfBoundsException,
             PositionOutOfBoundsException
create a Voxel in a space of nax dimensions and initialize it with a position.
Parameters:
nax - number of axes or dimensions in the space
in - an array containing the position. The first nax elements will be used. If the array size is smaller than nax, the remaining components will be 0.
Throws:
ValueOutOfBoundsException - thrown if nax < 0
PositionOutOfBoundsException - thrown if any of the position elements are out of bounds.

Voxel

public Voxel(double[] in)
      throws PositionOutOfBoundsException
create a Voxel in a space of nax dimensions and initialize it with a position.
Parameters:
nax - number of axes or dimensions in the space
in - an array containing the position. The first nax elements will be used. If the array size is smaller than nax, the remaining components will be 0.
Throws:
PositionOutOfBoundsException - thrown if any of the position elements are out of bounds.

Voxel

public Voxel(Voxel that)
create an immutable Voxel positioned at the location of anoher Voxel
Method Detail

getNaxes

public int getNaxes()
return the number of dimensions in the space containing this Voxel

getPos

public int getPos(int i)
          throws java.lang.ArrayIndexOutOfBoundsException
get the projection of the Voxel's position along the i-th axis, rounded to the nearest integer. (Axes are numbered such that the first axis is zero.)

axisPos

public double axisPos(int i)
              throws java.lang.ArrayIndexOutOfBoundsException
Deprecated. use getExactPos()
get the projection of the Voxel's position along the i-th axis. (Axes are numbered such that the first axis is zero.)

getExactPos

public double getExactPos(int i)
                  throws java.lang.ArrayIndexOutOfBoundsException
get the exact projection of the Voxel's position along the i-th axis. That is, the position can be fractional. (Axes are numbered such that the first axis is zero.)

getExactPos

public double[] getExactPos()
                    throws java.lang.ArrayIndexOutOfBoundsException
get the exact projection of the Voxel's position along the i-th axis. That is, the position can be fractional. (Axes are numbered such that the first axis is zero.)

getValues

public double[] getValues(int firstaxis)
                  throws java.lang.ArrayIndexOutOfBoundsException
Deprecated. use getExactPos()
return an array of doubles representing the position along each axis
Parameters:
firstaxis - index at which first value should appear
Throws:
java.lang.ArrayIndexOutOfBoundsException - if firstaxis < 0

getPos

public int[] getPos()
return the position of this voxel rounded to the nearest whole voxel

toString

public java.lang.String toString()
converts position to (x, y, ...) formatted string
Overrides:
toString in class java.lang.Object

clone

public java.lang.Object clone()
create a deep copy of this Voxel
Overrides:
clone in class java.lang.Object

equals

public boolean equals(Voxel vox)
return true if another Voxel is (in principle) at the same location as this Voxel. For equality to be true, locations along extra axes (for either Voxel) must be zero.

equals

public boolean equals(java.lang.Object vox)
Overrides:
equals in class java.lang.Object

isMutable

public boolean isMutable()
return true if the position of this Voxel can change

getMonitor

public java.util.Observable getMonitor()
return an Observable monitor for listening for changes to this Voxel, or null if this Voxel is immutable. Observers will be notified when the Voxel position changes, passing this Voxel as an argument to the Observers' update() method.

roundToInt

public static int[] roundToInt(double[] in)
                       throws PositionOutOfBoundsException
round a double array to an integer array. If input is null, the output is null.
Throws:
PositionOutOfBoundsException - if any of the input values are out of bounds.

add

public Voxel add(Voxel vox)
return a Voxel that is the sum of this Voxel and the projection of another Voxel into this space.

subtract

public Voxel subtract(Voxel vox)
return a Voxel that is the differenc of another Voxel from this Voxel

doubleToInt

public static int[] doubleToInt(double[] in)
convert a double array to an integer array. Often the parameters provided by this class are needed as integers rather than doubles. This method converts each element in the input double array to an int via a simple cast. If input is null, the output is null.

roundDoubleToInt

public static int[] roundDoubleToInt(double[] in)
convert a double array to an integer array. Often the parameters provided by this class are needed as integers rather than doubles. This method converts each element in the input double array by rounding it to the nearest int. If input is null, the output is null.

intToDouble

public static double[] intToDouble(int[] in)
converts a integer array to double array. Most of The parameters required by this class are needed as doubles rather than ints. This method provides a convenient way to convert an integer array to a double array. If the input in null, the output is null.

hashCode

public final int hashCode()
compute a hashcode for this Voxel. Voxels which are immutable and set to the same position will be return the same hash code. Voxels that are mutable will (virtually) always return different hash codes (in this case, the default Object.hashCode() is used).
Overrides:
hashCode in class java.lang.Object

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD