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.coordinates.transforms.
AbsToRelCoordTransform

java.lang.Object
  |
  +--java.util.Observable
        |
        +--ncsa.horizon.coordinates.CoordTransform
              |
              +--ncsa.horizon.coordinates.transforms.AbsToRelCoordTransform

public class AbsToRelCoordTransform
extends CoordTransform
an object for transforming positions from absolute positions to positions relative to a reference position.

See the documentation for the super class, CoordTransform, for a general description of how a transform is used.

The transform applied by this class is governed by two basic pieces of data: a reference position and a stepsize. The stepsize, a scale factor to be applied to width of a voxel, is usually left to its default value of 1.0. The reference position is the absolute position that the relative positions are referred to; that is, the reference position in the old system will be shifted to 0.0 in the new, transformed system.

When one instantiates this class, one usually indicates whether the transform can adapt its reference position and stepsize according to the CoordinateSystem it gets attached to. If this transform is adaptable (e.g. willAdapt() returns true), then when the transform is attached to a CoordinateSystem, it will change its reference position to that found in the system's metadata, and the stepsize will be set to 1.0. If it is not adaptable, it will use the reference position and stepsize set at construction.

For example, if one wants to make a CoordinateSystem give positions in relative coordinates, one can:

     CoordinateSystem csys;
     int numaxes;
     ...             // csys and numaxes are set
     CoordTransform t = new AbsToRelCoordTransform(numaxes);
     csys.attachTransform(t);
 
The csys system will now print out its coordinate positions relative to its native reference position. However, if we want positions be be relative to some other reference, we can instead:
     double[] ref = { 20.0, 31.53, -15.8 };
     CoordTransform t = new AbsToRelCoordTransform(ref.length, ref, false);
     csys.attachTransform(t); 
 
Now suppose the system already prints out relative coordinate positions; We can change the positions to absolute ones by attaching this transform in reverse:
     double[] ref = { 20.0, 31.53, -15.8 };
     CoordTransform t = new AbsToRelCoordTransform(ref.length, ref, false);
     csys.attachTransform(t, false); 
 
In this case, we needed to provide the reference position, since the native reference (if the positions really are relative coordinates) is likely to be zero. However, it may not be, and you can allow the transform use that reference when attached in reverse:
     CoordTransform t = new AbsToRelCoordTransform(numaxes, null, true);
     csys.attachTransform(t, false); 
 
This will cause the zero position in the native system to be shifted to the native reference position; in addition, -1.0 will be used as the stepsize. This turns about to be exactly equivalent to our first example.


Field Summary
boolean adapt
          if true, this transform--when attached to a CoordinateSystem--will replace its reference position data with that of the CoordinateSystem being attached to.
LinearCoordTransform delegate
           
 
Fields inherited from class ncsa.horizon.coordinates.CoordTransform
fwdfmtrs, fwdnames, revfmtrs, revnames
 
Constructor Summary
AbsToRelCoordTransform()
          create a AbsToRelCoordTransform object with default values, assuming it will operate on up to 2 axes.
AbsToRelCoordTransform(int naxes)
          create a AbsToRelCoordTransform object with default values.
AbsToRelCoordTransform(int naxes, double[] refval, boolean adapt)
          create a AbsToRelCoordTransform object specifying all internal data.
AbsToRelCoordTransform(int naxes, double[] refval, double[] stepsize, boolean adapt)
          create a AbsToRelCoordTransform object specifying all internal data.
AbsToRelCoordTransform(Metadata md)
          create a linear transform based on the specified metadata using the horizon schema.
 
Method Summary
java.lang.Object clone()
          create a copy of this Transform
double[] forward(double[] position, int[] axisIndices)
          apply a forward tranform on an input position.
double[] forward(double[] position)
          apply a forward tranform on an input position.
int getInNaxes()
          return the minimum number of axes that the forward transform operates on.
int getMaxNaxes()
          return the maximum number of axes this transform operates on
Metadata getMetadata(Metadata in, boolean forward, int[] axisIndices)
          update the input Metadata object to reflect the changes that this tranform makes to a coordinate position.
int getOutNaxes()
          return the minimum number of axes that results from the forward transform.
double getRefvalue(int axis)
          return the axis reference value for the specified axis.
double[] getRefvalue()
          return a copy of the axis reference values for all axes.
double getStepsize(int axis)
          return the axis step size for the specified axis.
double[] getStepsize()
          return the axis step size for each axis.
void init(CoordinateSystem csys, boolean forward, int[] axisIndices)
          initialize this transform according to the system it is to be applied to.
double[] reverse(double[] position, int[] axisIndices)
          apply a reverse tranform on an input position
double[] reverse(double[] position)
          apply a reverse tranform on an input position.
void setMaxNaxes(int naxes)
          set the maximum number of axes this transform operates on
void setRefvalue(int axis, double in)
          set the axis reference value for the specified axis.
void setRefvalue(double[] in)
          set the axis reference value for each axis.
void setStepsize(int axis, double in)
          set the axis step size for the specified axis.
void setStepsize(double[] in)
          set the axis step size for each axis.
void setToAdapt(boolean doadapt)
          set whether this transform should adapt its internal data according to the reference position data of the CoordinateSystem it gets attached to.
boolean willAdapt()
          return whether the data internal to this object will get update upon attachment to a CoordinateSystem.
 
Methods inherited from class ncsa.horizon.coordinates.CoordTransform
applyNamesAndFormatters, canTransform, canTransform, canTransform, clone, determineConstraints, determineConstraints, forward, forward, getFormatters, getInNaxes, getMetadata, getNames, getOutNaxes, init, reverse, reverse, setFormatter, setName
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Field Detail

adapt

protected boolean adapt
if true, this transform--when attached to a CoordinateSystem--will replace its reference position data with that of the CoordinateSystem being attached to.

delegate

protected LinearCoordTransform delegate
Constructor Detail

AbsToRelCoordTransform

public AbsToRelCoordTransform()
create a AbsToRelCoordTransform object with default values, assuming it will operate on up to 2 axes. By default, willAdapt() will return true.

AbsToRelCoordTransform

public AbsToRelCoordTransform(int naxes)
create a AbsToRelCoordTransform object with default values. By default, willAdapt() will return true.
Parameters:
naxes - the maximum number of axes this transform can operate on

AbsToRelCoordTransform

public AbsToRelCoordTransform(int naxes,
                              double[] refval,
                              boolean adapt)
create a AbsToRelCoordTransform object specifying all internal data. Missing values in the input array are set to zero
Parameters:
naxes - the maximum number of axes this transform can operate on
refval - the position in the "output" system (the system forward() transforms to) that is equal to the the refpos position. Default equals 0.
adapt - if false, these values should not be updated when attached to a CoordinateSystem. (If one intends intend to attach this AbsToRelCoordTransform to a CoordinateSystem, this value will not be used.)

AbsToRelCoordTransform

public AbsToRelCoordTransform(int naxes,
                              double[] refval,
                              double[] stepsize,
                              boolean adapt)
create a AbsToRelCoordTransform object specifying all internal data. Missing values in the input arrays are set to default values: 0.0 for refval and 1.0 for stepsize.
Parameters:
naxes - the maximum number of axes this transform can operate on
refval - the position in the "output" system (the system forward() transforms to) that is equal to the the refpos position. Default equals 0.
stepsize - the size of a voxel of the "output" system (the system that forward() transforms to) in units of the "input" system
adapt - if false, these values should not be updated when attached to a CoordinateSystem. (If one intends intend to attach this AbsToRelCoordTransform to a CoordinateSystem, this value will not be used.)

AbsToRelCoordTransform

public AbsToRelCoordTransform(Metadata md)
                       throws IllegalTransformException
create a linear transform based on the specified metadata using the horizon schema.
Method Detail

forward

public double[] forward(double[] position,
                        int[] axisIndices)
apply a forward tranform on an input position.
Parameters:
position - an array giving the input position to transform
axisIndices - an array containing the indices of the position array that should be used in the tranformation. The order of the indices indicate how the position should be interpreted by the transform.
Overrides:
forward in class CoordTransform

forward

public double[] forward(double[] position)
apply a forward tranform on an input position.
Parameters:
position - an array giving the input position to transform
Overrides:
forward in class CoordTransform

reverse

public double[] reverse(double[] position,
                        int[] axisIndices)
apply a reverse tranform on an input position
Parameters:
position - an array giving the input position to transform
axisIndices - an array containing the indices of the position array that should be used in the tranformation. The order of the indices indicate how the position should be interpreted by the transform.
Overrides:
reverse in class CoordTransform

reverse

public double[] reverse(double[] position)
apply a reverse tranform on an input position. A list of axis indices is assumed (usually { 0, ... getOutNAxes()-1 }).
Parameters:
position - an array giving the input position to transform
Overrides:
reverse in class CoordTransform

getInNaxes

public int getInNaxes()
return the minimum number of axes that the forward transform operates on. This value is equal to the minimum number of axes that results from the reverse transform. This value is often equal to the that returned by getOutNaxes(), but is not required to.
Overrides:
getInNaxes in class CoordTransform

getOutNaxes

public int getOutNaxes()
return the minimum number of axes that results from the forward transform. This value is equal to the minimum number of axes that the reverse transform operates on. This value is often equal to the that returned by getInNaxes(), but is not required to.
Overrides:
getOutNaxes in class CoordTransform

getMaxNaxes

public int getMaxNaxes()
return the maximum number of axes this transform operates on

setMaxNaxes

public void setMaxNaxes(int naxes)
                throws java.lang.ArrayIndexOutOfBoundsException
set the maximum number of axes this transform operates on

setRefvalue

public void setRefvalue(int axis,
                        double in)
                throws java.lang.ArrayIndexOutOfBoundsException
set the axis reference value for the specified axis. The reference value is position along a world coordinate axis that corresponds to the data location given by the "refposition" metadatum.
Parameters:
axis - the index of the axis to be set (first axis has index 0)
in - value to be set

getRefvalue

public double getRefvalue(int axis)
                  throws java.lang.ArrayIndexOutOfBoundsException
return the axis reference value for the specified axis. The reference value is position along a world coordinate axis that corresponds to the data location given by the "refposition" metadatum.
Parameters:
axis - the index of the axis to be set (first axis has index 0)

setRefvalue

public void setRefvalue(double[] in)
set the axis reference value for each axis. The reference value is position along a world coordinate axis that corresponds to the data location given by the "refposition" metadatum.
Parameters:
in - values to be set; missing or extra values are ignored

getRefvalue

public double[] getRefvalue()
return a copy of the axis reference values for all axes. The reference value is position along a world coordinate axis that corresponds to the data location given by the "refposition" metadatum.

setStepsize

public void setStepsize(int axis,
                        double in)
                throws java.lang.ArrayIndexOutOfBoundsException
set the axis step size for the specified axis. The step size is length of a voxel along an axis in world coordinate units.
Parameters:
axis - the index of the axis to be set (first axis has index 0)
in - value to be set

getStepsize

public double getStepsize(int axis)
                  throws java.lang.ArrayIndexOutOfBoundsException
return the axis step size for the specified axis. The step size is length of a voxel along an axis in world coordinate units.
Parameters:
axis - the index of the axis to be set (first axis has index 0)

setStepsize

public void setStepsize(double[] in)
set the axis step size for each axis. The step size is length of a voxel along an axis in world coordinate units.
Parameters:
axis - the index of the axis to be set (first axis has index 0)
in - value to be set

getStepsize

public double[] getStepsize()
return the axis step size for each axis. The step size is length of a voxel along an axis in world coordinate units.
Parameters:
axis - the index of the axis to be set (first axis has index 0)
in - value to be set

clone

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

getMetadata

public Metadata getMetadata(Metadata in,
                            boolean forward,
                            int[] axisIndices)
update the input Metadata object to reflect the changes that this tranform makes to a coordinate position. In general, this method will actually edit the contents of the input Metadata when changes are necessary.
Overrides:
getMetadata in class CoordTransform

setToAdapt

public void setToAdapt(boolean doadapt)
set whether this transform should adapt its internal data according to the reference position data of the CoordinateSystem it gets attached to. If the input is true, then when this transform is attached to a CoordinateSystem object, it will ignore its own reference position information; instead, it will look up the current reference position of the system and then reset its internal parameters to convert positions in that system to positions relative to that reference position.

willAdapt

public boolean willAdapt()
return whether the data internal to this object will get update upon attachment to a CoordinateSystem.

init

public void init(CoordinateSystem csys,
                 boolean forward,
                 int[] axisIndices)
         throws IllegalTransformException
initialize this transform according to the system it is to be applied to. This method is usually called by a CoordinateSystem object when the transform is attached to it.
Throws:
IllegalTransformException - if the csys has a non-positive number of axes
Overrides:
init in class CoordTransform

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