edu.mines.jtk.mosaic
Class Projector

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

public class Projector
extends java.lang.Object

Converts (projects) world coordinates v to/from normalized coordinates u. The projection is a simple scale and translation, such that specified world coordinates (v0,v1) correspond to specified normalized coordinates (u0,u1).

Specifically, a projector computes u = shift+scale*v, where scale = (u1-u0)/(v1-v0), and shift = u0-scale*v0. The projection exists only for v1 != v0. However, v0 and v1 are otherwise unconstrained. v0 may be greater than v1.

The projection from normalized coordinates u to world coordinates v is simply the inverse, and this inverse exists only for u1 != u0.

By definition, u0 is closest to normalized coordinate u=0, and u1 is closest to normalized coordinate u=1. These coordinates must satisfy the constraints 0.0 <= u0 < u1 <= 1.0.

Typically, the coordinates (v0,v1) represent bounds in world coordinate space. Then, the gaps in normalized coordinate space [0,u0) and (u1,1] represent margins, extra space needed for graphic rendering. The amount of extra space required varies, depending on the graphics. Accounting for this varying amount of extra space is a complex but important aspect of aligning the coordinate systems of two or more graphics.

Alignment is accomplished by simply rendering all graphics using the same projector. We obtain this shared projector by merging the preferred projectors of each graphic. A preferred projector is one that a graphic might use if it were the only one being rendered.

We assume that each graphic has a preferred projector that indicates the world coordinate span [v0,v1] and margins [0,u0) and (u1,1] that it would prefer if it were the only graphic rendered. We then merge two projectors into one so that the merged projector contains the union of the two world coordinate spans and has adequate margins.

A projector has a sign, which is the sign of v1-v0. Note that this sign is never ambiguous, because v1 never equals v0. When merging a projector B into into a projector A, we preserve the sign of projector A.

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

Constructor Summary
Projector(double v0, double v1)
          Constructs a projector with specified v values, u0=0, and u1=1.
Projector(double v0, double v1, double u0, double u1)
          Constructs a projector with specified v and u values.
Projector(Projector p)
          Constructs a copy of the specified projector.
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 double getScaleRatio(Projector p)
          Gets the scale ratio for this projector and a specified projector.
 int hashCode()
           
 void merge(Projector p)
          Merges the specified projector into this projector.
 double u(double v)
          Returns normalized coordinate u corresponding to world coordinate v.
 double u0()
          Returns the u-coordinate bound closest to u=0.
 double u1()
          Returns the u-coordinate bound closest to u=1.
 double v(double u)
          Returns world coordinate v corresponding to normalized coordinate u.
 double v0()
          Returns the v-coordinate bound closest to u=0.
 double v1()
          Returns the v-coordinate bound closest to u=1.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Projector

public Projector(double v0,
                 double v1)
Constructs a projector with specified v values, u0=0, and u1=1. The projector will have zero margins.

Parameters:
v0 - the v coordinate that corresponds to u coordinate 0; v0 != v1 is required.
v1 - the v coordinate that corresponds to u coordinate 1; v0 != v1 is required.

Projector

public Projector(double v0,
                 double v1,
                 double u0,
                 double u1)
Constructs a projector with specified v and u values. The parameters u0 and u1 determine the margins of the projector. The world coordinate v0 corresponds to normalized coordinate u0; the world coordinate v1 corresponds to normalized coordinate u1.

Parameters:
v0 - the v coordinate that corresponds to u coordinate u0; v0 != v1 is required.
v1 - the v coordinate that corresponds to u coordinate u1; v0 != v1 is required.
u0 - the u coordinate closest to normalized coordinate 0; 0.0 <= u0 < u1 is required.
u1 - the u coordinate closest to normalized coordinate 1; u0 < u1 <= 1.0 is required.

Projector

public Projector(Projector p)
Constructs a copy of the specified projector.

Parameters:
p - the projector.
Method Detail

u

public double u(double v)
Returns normalized coordinate u corresponding to world coordinate v.

Parameters:
v - world coordinate v.
Returns:
normalized coordinate u.

v

public double v(double u)
Returns world coordinate v corresponding to normalized coordinate u.

Parameters:
u - normalized coordinate u.
Returns:
world coordinate v.

u0

public double u0()
Returns the u-coordinate bound closest to u=0.

Returns:
the u-coordinate bound.

u1

public double u1()
Returns the u-coordinate bound closest to u=1.

Returns:
the u-coordinate bound.

v0

public double v0()
Returns the v-coordinate bound closest to u=0.

Returns:
the v-coordinate bound.

v1

public double v1()
Returns the v-coordinate bound closest to u=1.

Returns:
the v-coordinate bound.

merge

public void merge(Projector p)
Merges the specified projector into this projector.

Parameters:
p - the projector.

getScaleRatio

public double getScaleRatio(Projector p)
Gets the scale ratio for this projector and a specified projector. Recall that a projector converts world coordinates v to normalized coordinates u by a simple scaling and translation: u = shift+scale*v. This method returns the scale for this projector divided by the scale for the specified projector.

This method is typically used to account for the effects of merging two or more projectors. For example, after merging, parameters that are proportional to the sizes of margins [0,u0) or (u1,1] in the specified projector should be scaled by this ratio before being used with this projector.

Returns:
the scale factor.

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object