next up previous contents
Next: Putting It All Together: Up: The World Coordinate System Previous: getMetadata(Metadata inboolean forward,

Implementing a New Coordinate System

One can think of a CoordinateSystem that encapsulates one or more transformations together to convert dataset positions into world coordinate positions. Thus the simplest way-actually, the most appropriate way-to create a new CoordinateSystem class is to subclass another CoordinateSystem and within the constructor, attach any new CoordTransform objects necessary to map positions into the new system.

For example, the CoordinateSystem class itself starts off containing no internal transforms. Coordinate positions return from its getCoordPos() method simply return the input dataset position unchanged. The LinearCoordinateSystem subclasses CoordinateSystem and adds one transform to the empty stack of transforms the class will use: the LinearCoordTransform. Here is the snippet of code executed by the LinearCoordinateSystem constructors to accomplish this:

try {
    t = new LinearCoordTransform(cmdata);
} catch (IllegalTransformException ex) {
    throw new 
        IllegalTransformException("Bad parameters in metadata: " +
                                  ex.getMessage());
}
CoordTransformConstraints c = new CoordTransformConstraints(naxes);
attachTransform(t, c);
glueTransforms(false);
The last line calls the protected method glueTransforms(). This method ``glues'' all currently attached transforms to the system, preventing them from being removed with methods like popTransform().

For most subclasses of CoordinateSystem, it is not necessary to override any other methods other than constructors. Whenever either getCoordPos() or getVoxel() is called, the CoordinateSystem will automatically send the input position through its stack of transforms, first the ``glued'' transforms and then the ``attached'' ones. Of course, when you set out to implement a new CoordinateSystem, you may discover that the CoordTransform you need does not exist. In this case, you will have to first implement the specialized CoordTransform
[2] classes you will need.



Ray Plante
Mon Aug 25 15:16:12 CDT 1997