edu.mines.jtk.mosaic
Class Transcaler

java.lang.Object
  extended by edu.mines.jtk.mosaic.Transcaler

public class Transcaler
extends java.lang.Object

Translates and scales (maps) user coordinates to/from device coordinates. The mapping is specified by two rectangles, one in user coordinates and the other in device coordinates.

Device coordinates are ints, and the device coordinate rectangle typically corresponds to device bounds. User coordinates are doubles.

In conversion from user to device coordinates, the latter are clipped to lie in the range [-32768,32767], which is the range of a 16-bit short integer. Although device coordinates are represented by ints, they are often limited by an underlying graphics systems to the 16-bit range of shorts.

Conversion from/to user coordinates to/from device coordinates behaves robustly in the cases where the mapping is degenerate. For example, if the device coordinate rectangle has width one, then conversion from any device x-coordinate to user x-coordinate yields the average of the user x-coordinate bounds. Likewise, if the user coordinate rectangle has zero width, then conversion from any user x-coordinate to device x-coordinate yields the average of the device x-coordinate bounds.

Version:
2004.12.23
Author:
Dave Hale, Colorado School of Mines

Constructor Summary
Transcaler()
          Constructs a transcaler with identity coordinate mapping.
Transcaler(double x1u, double y1u, double x2u, double y2u, int x1d, int y1d, int x2d, int y2d)
          Constructs a transcaler with specified coordinate mapping.
Transcaler(int width, int height)
          Constructs a transcaler with specified device width and height.
 
Method Summary
 Transcaler combineWith(Projector xp, Projector yp)
          Returns a new transcaler that combines this transcaler with projectors.
 int height(double hu)
          Converts the specified user-coordinate height to device-coordinate height.
 double height(int hd)
          Converts the specified device-coordinate height to user-coordinate height.
 void setMapping(double x1u, double y1u, double x2u, double y2u)
          Sets the user-coordinate part of the mapping for this transcaler.
 void setMapping(double x1u, double y1u, double x2u, double y2u, int x1d, int y1d, int x2d, int y2d)
          Sets the coordinate mapping for this transcaler.
 void setMapping(int width, int height)
          Sets the device-coordinate width and height.
 void setMapping(int x1d, int y1d, int x2d, int y2d)
          Sets the device-coordinate part of the mapping for this transcaler.
 int width(double wu)
          Converts the specified user-coordinate width to device-coordinate width.
 double width(int wd)
          Converts the specified device-coordinate width to user-coordinate width.
 int x(double xu)
          Converts the specified user x-coordinate to device x-coordinate.
 double x(int xd)
          Converts the specified device x-coordinate to user x-coordinate.
 int y(double yu)
          Converts the specified user y-coordinate to device y-coordinate.
 double y(int yd)
          Converts the specified device y-coordinate to user y-coordinate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Transcaler

public Transcaler()
Constructs a transcaler with identity coordinate mapping. In this mapping, device coordinates equal user coordinates, rounded to the nearest integer.


Transcaler

public Transcaler(int width,
                  int height)
Constructs a transcaler with specified device width and height. Maps user coordinates (0.0,0.0) to device coordinates (0,0) and user coordinates (1.0,1.0) to device coordinates (width-1,height-1).

Parameters:
width - the width, in device coordinates.
height - the height, in device coordinates.

Transcaler

public Transcaler(double x1u,
                  double y1u,
                  double x2u,
                  double y2u,
                  int x1d,
                  int y1d,
                  int x2d,
                  int y2d)
Constructs a transcaler with specified coordinate mapping.

Parameters:
x1u - the user x-coordinate corresponding to x1d.
y1u - the user y-coordinate corresponding to y1d.
x2u - the user x-coordinate corresponding to x2d.
y2u - the user y-coordinate corresponding to y2d.
x1d - the device x-coordinate corresponding to x1u.
y1d - the device y-coordinate corresponding to y1u.
x2d - the device x-coordinate corresponding to x2u.
y2d - the device y-coordinate corresponding to y2u.
Method Detail

setMapping

public void setMapping(double x1u,
                       double y1u,
                       double x2u,
                       double y2u,
                       int x1d,
                       int y1d,
                       int x2d,
                       int y2d)
Sets the coordinate mapping for this transcaler.

Parameters:
x1u - the user x-coordinate corresponding to x1d.
y1u - the user y-coordinate corresponding to y1d.
x2u - the user x-coordinate corresponding to x2d.
y2u - the user y-coordinate corresponding to y2d.
x1d - the device x-coordinate corresponding to x1u.
y1d - the device y-coordinate corresponding to y1u.
x2d - the device x-coordinate corresponding to x2u.
y2d - the device y-coordinate corresponding to y2u.

setMapping

public void setMapping(double x1u,
                       double y1u,
                       double x2u,
                       double y2u)
Sets the user-coordinate part of the mapping for this transcaler.

Parameters:
x1u - the user x-coordinate corresponding to the current x1d.
y1u - the user y-coordinate corresponding to the current y1d.
x2u - the user x-coordinate corresponding to the current x2d.
y2u - the user y-coordinate corresponding to the current y2d.

setMapping

public void setMapping(int x1d,
                       int y1d,
                       int x2d,
                       int y2d)
Sets the device-coordinate part of the mapping for this transcaler.

Parameters:
x1d - the device x-coordinate corresponding to the current x1u.
y1d - the device y-coordinate corresponding to the current y1u.
x2d - the device x-coordinate corresponding to the current x2u.
y2d - the device y-coordinate corresponding to the current y2u.

setMapping

public void setMapping(int width,
                       int height)
Sets the device-coordinate width and height. Maps the current user coordinates (x1u,y1u) to device coordinates (0,0) and user coordinates (x2u,y2u) to device coordinates (width-1,height-1).


combineWith

public Transcaler combineWith(Projector xp,
                              Projector yp)
Returns a new transcaler that combines this transcaler with projectors. The returned transcaler includes the transforms of the projectors. Does not change this transcaler.

Parameters:
xp - the projector for x coordinates.
yp - the projector for y coordinates.
Returns:
the new transcaler.

x

public int x(double xu)
Converts the specified user x-coordinate to device x-coordinate.

Parameters:
xu - the user x-coordinate.
Returns:
the device x-coordinate.

y

public int y(double yu)
Converts the specified user y-coordinate to device y-coordinate.

Parameters:
yu - the user y-coordinate.
Returns:
the device y-coordinate.

width

public int width(double wu)
Converts the specified user-coordinate width to device-coordinate width.

Parameters:
wu - the user-coordinate width.
Returns:
the device-coordinate width.

height

public int height(double hu)
Converts the specified user-coordinate height to device-coordinate height.

Parameters:
hu - the user-coordinate height.
Returns:
the device-coordinate height.

x

public double x(int xd)
Converts the specified device x-coordinate to user x-coordinate.

Parameters:
xd - the device x-coordinate.
Returns:
the user x-coordinate.

y

public double y(int yd)
Converts the specified device y-coordinate to user y-coordinate.

Parameters:
yd - the device y-coordinate.
Returns:
the user y-coordinate.

width

public double width(int wd)
Converts the specified device-coordinate width to user-coordinate width.

Parameters:
wd - the device-coordinate width.
Returns:
the user-coordinate width.

height

public double height(int hd)
Converts the specified device-coordinate height to user-coordinate height.

Parameters:
hd - the device-coordinate height.
Returns:
the user-coordinate height.