jsky.image.gui
Class ImageCoordinateConverter

java.lang.Object
  extended by jsky.image.gui.ImageCoordinateConverter
All Implemented Interfaces:
CoordinateConverter, WorldCoordinateConverter

public class ImageCoordinateConverter
extends java.lang.Object
implements CoordinateConverter

This utility class may be used by classes that display images to convert between different coordinate systems, optionally including world coordinates. Methods are available for converting between the following coordinate systems:

Screen Coordinates
The origin (0,0) is always at the upper left corner of the window. Whole pixels are counted and no transformations are taken into account.
Canvas Coordinates
The origin (0,0) is at the upper left corner of the image. Whole pixels are counted and no transformations are taken into account.
Image Coordinates
The origin is at lower left (FITS style) after all transformations are undone. At mag 1, the origin is (1, 1), otherwise it is a fraction of a pixel (0.5, 0.5). Image coordinates correspond to the coordinates in a FITS image.
User Coordinates
The origin (0.0, 0.0) is at upper left after all transformations undone. User coordinates are like image coordinates, except that the Y axis is reversed and the origin at mag 1 is (0., 0.) instead of (1. 1).
World Coordinates
World coordinates are converted from image coordinates based on the keywords in the image header, if available.

Version:
$Revision: 1.1 $
Author:
Allan Brighton

Field Summary
 
Fields inherited from interface jsky.coords.CoordinateConverter
CANVAS, IMAGE, SCREEN, USER, WORLD
 
Constructor Summary
ImageCoordinateConverter(BasicImageDisplay imageDisplay)
           
 
Method Summary
 void addChangeListener(javax.swing.event.ChangeListener l)
          Register to receive change events from this object whenever the the WCS information is changed.
 void assertWCS()
          Throw an exception is WCS information is not available
 void canvasToImageCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given canvas coordinates to image coordinates.
 void canvasToScreenCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given canvas coordinates to screen coordinates.
 void canvasToUserCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given canvas coordinates to user coordinates.
 void canvasToWorldCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given canvas coordinates to world coordinates degrees in the equinox of the current image.
 void convertCoords(java.awt.geom.Point2D.Double p, int inType, int outType, boolean isDistance)
          Convert the given coordinates from inType to outType.
protected  void fireChange()
          Notify any listeners of a change in the WCS information.
 void flip(java.awt.geom.Point2D.Double p)
          Flip the x,y coordinates of the given point based on the current settings.
 double getEquinox()
          Return the equinox used for coordinates (usually the equionx of the image)
 double getHeight()
          Return the height in pixels
 double getHeightInDeg()
          Return the height in deg
 java.awt.geom.Point2D.Double getImageCenter()
          Return the center coordinates in image pixels.
 BasicImageDisplay getImageDisplay()
          Return the target image display
 java.awt.geom.Point2D.Double getWCSCenter()
          Return the center RA,Dec coordinates in degrees.
 double getWidth()
          Return the width in pixels
 double getWidthInDeg()
          Return the width in deg
 void imageToCanvasCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given image coordinates to canvas coordinates.
 void imageToScreenCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given image coordinates to screen coordinates.
 void imageToUserCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given image coordinates to user coordinates.
 void imageToWorldCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given image coordinates to world coordinates degrees in the equinox of the current image.
 boolean isWCS()
          Return true if world coordinates conversion is available.
 void removeChangeListener(javax.swing.event.ChangeListener l)
          Stop receiving change events from this object.
 void rotate(java.awt.geom.Point2D.Double p, int factor)
          Rotate the given point about the image center by the current rotation angle, multiplied by the given factor.
 void screenToCanvasCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given screen coordinates to canvas coordinates.
 void screenToImageCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given screen coordinates to image coordinates.
 void screenToUserCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given screen coordinates to user coordinates.
 void screenToWorldCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given screen coordinates to world coordinates degrees in the equinox of the current image.
 void userToCanvasCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given user coordinates to canvas coordinates.
 void userToImageCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given user coordinates to image coordinates.
 void userToScreenCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given user coordinates to screen coordinates.
 void userToWorldCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given user coordinates to world coordinates degrees in the equinox of the current image.
 void worldToCanvasCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given world coordinates (degrees, in the equinox of the current image) to canvas coordinates.
 void worldToImageCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given world coordinates (degrees, in the equinox of the current image) to image coordinates.
 void worldToScreenCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given world coordinates (degrees, in the equinox of the current image) to screen coordinates.
 void worldToUserCoords(java.awt.geom.Point2D.Double p, boolean isDistance)
          Convert the given world coordinates (degrees, in the equinox of the current image) to user coordinates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageCoordinateConverter

public ImageCoordinateConverter(BasicImageDisplay imageDisplay)
Method Detail

getImageDisplay

public BasicImageDisplay getImageDisplay()
Return the target image display


addChangeListener

public void addChangeListener(javax.swing.event.ChangeListener l)
Register to receive change events from this object whenever the the WCS information is changed.


removeChangeListener

public void removeChangeListener(javax.swing.event.ChangeListener l)
Stop receiving change events from this object.


fireChange

protected void fireChange()
Notify any listeners of a change in the WCS information.


isWCS

public boolean isWCS()
Return true if world coordinates conversion is available. This method should be called to check before calling any of the world coordinates conversion methods.

Specified by:
isWCS in interface WorldCoordinateConverter

getWCSCenter

public java.awt.geom.Point2D.Double getWCSCenter()
Return the center RA,Dec coordinates in degrees.

Specified by:
getWCSCenter in interface WorldCoordinateConverter

getImageCenter

public java.awt.geom.Point2D.Double getImageCenter()
Return the center coordinates in image pixels.

Specified by:
getImageCenter in interface WorldCoordinateConverter

getEquinox

public double getEquinox()
Return the equinox used for coordinates (usually the equionx of the image)

Specified by:
getEquinox in interface WorldCoordinateConverter

getWidthInDeg

public double getWidthInDeg()
Return the width in deg

Specified by:
getWidthInDeg in interface WorldCoordinateConverter

getHeightInDeg

public double getHeightInDeg()
Return the height in deg

Specified by:
getHeightInDeg in interface WorldCoordinateConverter

getWidth

public double getWidth()
Return the width in pixels

Specified by:
getWidth in interface WorldCoordinateConverter

getHeight

public double getHeight()
Return the height in pixels

Specified by:
getHeight in interface WorldCoordinateConverter

convertCoords

public void convertCoords(java.awt.geom.Point2D.Double p,
                          int inType,
                          int outType,
                          boolean isDistance)
Convert the given coordinates from inType to outType. The inType and outType arguments should be one of the constants defined in this interface (IMAGE for image coordinates, WCS for world coordinates, etc...).

Specified by:
convertCoords in interface CoordinateConverter
Parameters:
p - The point to convert.
inType - the type of the input coordinates
outType - the type of the output coordinates
isDistance - True if p should be interpreted as a distance instead of a point.

canvasToImageCoords

public void canvasToImageCoords(java.awt.geom.Point2D.Double p,
                                boolean isDistance)
Convert the given canvas coordinates to image coordinates.

Specified by:
canvasToImageCoords in interface CoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

userToImageCoords

public void userToImageCoords(java.awt.geom.Point2D.Double p,
                              boolean isDistance)
Convert the given user coordinates to image coordinates.

Specified by:
userToImageCoords in interface CoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

canvasToUserCoords

public void canvasToUserCoords(java.awt.geom.Point2D.Double p,
                               boolean isDistance)
Convert the given canvas coordinates to user coordinates.

Specified by:
canvasToUserCoords in interface CoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

userToCanvasCoords

public void userToCanvasCoords(java.awt.geom.Point2D.Double p,
                               boolean isDistance)
Convert the given user coordinates to canvas coordinates.

Specified by:
userToCanvasCoords in interface CoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

imageToCanvasCoords

public void imageToCanvasCoords(java.awt.geom.Point2D.Double p,
                                boolean isDistance)
Convert the given image coordinates to canvas coordinates.

Specified by:
imageToCanvasCoords in interface CoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

imageToUserCoords

public void imageToUserCoords(java.awt.geom.Point2D.Double p,
                              boolean isDistance)
Convert the given image coordinates to user coordinates.

Specified by:
imageToUserCoords in interface CoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

canvasToScreenCoords

public void canvasToScreenCoords(java.awt.geom.Point2D.Double p,
                                 boolean isDistance)
Convert the given canvas coordinates to screen coordinates.

Specified by:
canvasToScreenCoords in interface CoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

screenToCanvasCoords

public void screenToCanvasCoords(java.awt.geom.Point2D.Double p,
                                 boolean isDistance)
Convert the given screen coordinates to canvas coordinates.

Specified by:
screenToCanvasCoords in interface CoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

screenToImageCoords

public void screenToImageCoords(java.awt.geom.Point2D.Double p,
                                boolean isDistance)
Convert the given screen coordinates to image coordinates.

Specified by:
screenToImageCoords in interface CoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

imageToScreenCoords

public void imageToScreenCoords(java.awt.geom.Point2D.Double p,
                                boolean isDistance)
Convert the given image coordinates to screen coordinates.

Specified by:
imageToScreenCoords in interface CoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

screenToUserCoords

public void screenToUserCoords(java.awt.geom.Point2D.Double p,
                               boolean isDistance)
Convert the given screen coordinates to user coordinates.

Specified by:
screenToUserCoords in interface CoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

userToScreenCoords

public void userToScreenCoords(java.awt.geom.Point2D.Double p,
                               boolean isDistance)
Convert the given user coordinates to screen coordinates.

Specified by:
userToScreenCoords in interface CoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

imageToWorldCoords

public void imageToWorldCoords(java.awt.geom.Point2D.Double p,
                               boolean isDistance)
Convert the given image coordinates to world coordinates degrees in the equinox of the current image.

Specified by:
imageToWorldCoords in interface WorldCoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

screenToWorldCoords

public void screenToWorldCoords(java.awt.geom.Point2D.Double p,
                                boolean isDistance)
Convert the given screen coordinates to world coordinates degrees in the equinox of the current image.

Specified by:
screenToWorldCoords in interface CoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

canvasToWorldCoords

public void canvasToWorldCoords(java.awt.geom.Point2D.Double p,
                                boolean isDistance)
Convert the given canvas coordinates to world coordinates degrees in the equinox of the current image.

Specified by:
canvasToWorldCoords in interface CoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

userToWorldCoords

public void userToWorldCoords(java.awt.geom.Point2D.Double p,
                              boolean isDistance)
Convert the given user coordinates to world coordinates degrees in the equinox of the current image.

Specified by:
userToWorldCoords in interface CoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

worldToImageCoords

public void worldToImageCoords(java.awt.geom.Point2D.Double p,
                               boolean isDistance)
Convert the given world coordinates (degrees, in the equinox of the current image) to image coordinates.

Specified by:
worldToImageCoords in interface WorldCoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

worldToCanvasCoords

public void worldToCanvasCoords(java.awt.geom.Point2D.Double p,
                                boolean isDistance)
Convert the given world coordinates (degrees, in the equinox of the current image) to canvas coordinates.

Specified by:
worldToCanvasCoords in interface CoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

worldToScreenCoords

public void worldToScreenCoords(java.awt.geom.Point2D.Double p,
                                boolean isDistance)
Convert the given world coordinates (degrees, in the equinox of the current image) to screen coordinates.

Specified by:
worldToScreenCoords in interface CoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

worldToUserCoords

public void worldToUserCoords(java.awt.geom.Point2D.Double p,
                              boolean isDistance)
Convert the given world coordinates (degrees, in the equinox of the current image) to user coordinates.

Specified by:
worldToUserCoords in interface CoordinateConverter
Parameters:
p - The point to convert.
isDistance - True if p should be interpreted as a distance instead of a point.

flip

public void flip(java.awt.geom.Point2D.Double p)
Flip the x,y coordinates of the given point based on the current settings. This assumes that the input coordinates are in terms of the source image (i.e.: with no scaling applied). Note that the meaning of flipY is reversed here to conform to FITS coords, where the origin is at lower left.


rotate

public void rotate(java.awt.geom.Point2D.Double p,
                   int factor)
Rotate the given point about the image center by the current rotation angle, multiplied by the given factor. This assumes that the input coordinates are in terms of the source image (i.e.: with no scaling applied).

Parameters:
p - the point to rotate
factor - set to 1 to rotate, -1 to undo the rotation

assertWCS

public void assertWCS()
Throw an exception is WCS information is not available