next up previous contents
Next: The ImageDisplayMap Class Up: Putting It All Together: Previous: Putting It All Together:

The Viewer: Getting and Displaying Positions

 

Our example uses the ncsa.horizon.viewer.PosTrackerViewer to display images. Its specialty as a Viewer is that it displays the data pixel positions and their corresponding world coordinate positions for the pixels pointed to by the mouse. As the mouse moves within the image, positions update in real time.

Our viewer is a typical example of the simplest interactions with a coordinate system, namely converting data voxels into coordinate positions. This is the level at which most applications programmers will operate on (when they indeed need to directly interact with coordinates at all). Our viewer accesses the coordinate system via a reference to a CoordinateSystem object, regardless of what actual subclass of that object is, using only CoordinateSystem methods.

The first part of the PosTrackerViewer, we will look at is the part where a new slice from the dataset is displayed-that is, within the displaySlice(Slice sl) method:

    if (newViewable) {

        // this is a new data set, so we need to update our coordinate
        // system 
        coordSys = data.getCoordSys();
The boolean newViewable is set when addViewable(Viewable) is called, i.e. when a new dataset is attached to the viewer. Thus, before we display this data for the first time, we need to get the data's CoordinateSystem by calling the Viewable method getCoordSys().

The next thing we do is update the labels we use to identify the current slice:

    // Since the user may have chosen a different pair of axes to
    // display, we should update our axis labels.
    if (coordSys != null) {
        xLabel.setText( coordSys.getAxisLabel(slice.getXaxis()) + 
                        ": " );
        yLabel.setText( coordSys.getAxisLabel(slice.getYaxis()) + 
                        ": " );
    }
Now we are ready to display the image. In order to see how we display world coordinate positions, we should first take a look at one the ImageDisplayMap.





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