javax.media.jai
Class WarpAffine

java.lang.Object
  extended byjavax.media.jai.Warp
      extended byjavax.media.jai.WarpPolynomial
          extended byjavax.media.jai.WarpAffine
All Implemented Interfaces:
Serializable

public final class WarpAffine
extends WarpPolynomial

A description of an Affine warp.

The transform is specified as a mapping from destination space to source space, a backward mapping, as opposed to the forward mapping used in AffineOpImage.

The source position (x', y') of a point (x, y) is given by the first order (affine) bivariate polynomials:

 x' = p(x, y) = c1 + c2*x + c3*y
 y' = q(x, y) = c4 + c5*x + c6*y
 

WarpAffine is marked final so that it may be more easily inlined.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.media.jai.WarpPolynomial
degree, postScaleX, postScaleY, preScaleX, preScaleY, xCoeffs, yCoeffs
 
Constructor Summary
WarpAffine(AffineTransform transform)
          Constructs a WarpAffine with pre- and post-scale factors of 1.
WarpAffine(AffineTransform transform, float preScaleX, float preScaleY, float postScaleX, float postScaleY)
          Constructs a WarpAffine with a given transform mapping destination pixels into source space.
WarpAffine(float[] xCoeffs, float[] yCoeffs)
          Constructs a WarpAffine with pre- and post-scale factors of 1.
WarpAffine(float[] xCoeffs, float[] yCoeffs, float preScaleX, float preScaleY, float postScaleX, float postScaleY)
          Constructs a WarpAffine with a given transform mapping destination pixels into source space.
 
Method Summary
 AffineTransform getTransform()
          Returns a clone of the AffineTransform associated with this WarpAffine object.
 Point2D mapDestPoint(Point2D destPt)
          Computes the source point corresponding to the supplied point.
 Rectangle mapDestRect(Rectangle destRect)
          Computes a Rectangle that is guaranteed to enclose the region of the source that is required in order to produce a given rectangular output region.
 Point2D mapSourcePoint(Point2D sourcePt)
          Computes the destination point corresponding to the supplied point.
 Rectangle mapSourceRect(Rectangle srcRect)
          Computes a Rectangle that is guaranteed to enclose the region of the destination to which the source rectangle maps.
 float[] warpSparseRect(int x, int y, int width, int height, int periodX, int periodY, float[] destRect)
          Computes the source subpixel positions for a given rectangular destination region, subsampled with an integral period.
 
Methods inherited from class javax.media.jai.WarpPolynomial
createWarp, getCoeffs, getDegree, getPostScaleX, getPostScaleY, getPreScaleX, getPreScaleY, getXCoeffs, getYCoeffs
 
Methods inherited from class javax.media.jai.Warp
warpPoint, warpPoint, warpRect, warpRect, warpSparseRect
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WarpAffine

public WarpAffine(float[] xCoeffs,
                  float[] yCoeffs,
                  float preScaleX,
                  float preScaleY,
                  float postScaleX,
                  float postScaleY)
Constructs a WarpAffine with a given transform mapping destination pixels into source space. The transform is given by:
 x' = xCoeffs[0] + xCoeffs[1]*x + xCoeffs[2]*y;
 y' = yCoeffs[0] + yCoeffs[1]*x + yCoeffs[2]*y;
 
where x', y' are the source image coordinates and x, y are the destination image coordinates.

Parameters:
xCoeffs - The 3 destination to source transform coefficients for the X coordinate.
yCoeffs - The 3 destination to source transform coefficients for the Y coordinate.
preScaleX - The scale factor to apply to input (dest) X positions.
preScaleY - The scale factor to apply to input (dest) Y positions.
postScaleX - The scale factor to apply to the evaluated x transform
postScaleY - The scale factor to apply to the evaluated y transform
Throws:
IllegalArgumentException - if array xCoeffs or yCoeffs does not have length of 3.

WarpAffine

public WarpAffine(float[] xCoeffs,
                  float[] yCoeffs)
Constructs a WarpAffine with pre- and post-scale factors of 1.

Parameters:
xCoeffs - The 3 destination to source transform coefficients for the X coordinate.
yCoeffs - The 3 destination to source transform coefficients for the Y coordinate.

WarpAffine

public WarpAffine(AffineTransform transform,
                  float preScaleX,
                  float preScaleY,
                  float postScaleX,
                  float postScaleY)
Constructs a WarpAffine with a given transform mapping destination pixels into source space. Note that this is a backward mapping as opposed to the forward mapping used in AffineOpImage.

Parameters:
transform - The destination to source transform.
preScaleX - The scale factor to apply to source X positions.
preScaleY - The scale factor to apply to source Y positions.
postScaleX - The scale factor to apply to destination X positions.
postScaleY - The scale factor to apply to destination Y positions.

WarpAffine

public WarpAffine(AffineTransform transform)
Constructs a WarpAffine with pre- and post-scale factors of 1.

Parameters:
transform - An AffineTransform mapping dest to source coordinates.
Method Detail

getTransform

public AffineTransform getTransform()
Returns a clone of the AffineTransform associated with this WarpAffine object.

Returns:
An AffineTransform.

warpSparseRect

public float[] warpSparseRect(int x,
                              int y,
                              int width,
                              int height,
                              int periodX,
                              int periodY,
                              float[] destRect)
Computes the source subpixel positions for a given rectangular destination region, subsampled with an integral period. The destination region is specified using normal integral (full pixel) coordinates. The source positions returned by the method are specified in floating point.

Specified by:
warpSparseRect in class Warp
Parameters:
x - The minimum X coordinate of the destination region.
y - The minimum Y coordinate of the destination region.
width - The width of the destination region.
height - The height of the destination region.
periodX - The horizontal sampling period.
periodY - The vertical sampling period.
destRect - A float array containing at least 2*((width+periodX-1)/periodX)* ((height+periodY-1)/periodY) elements, or null. If null, a new array will be constructed.
Returns:
A reference to the destRect parameter if it is non-null, or a new float array otherwise.

mapDestRect

public Rectangle mapDestRect(Rectangle destRect)
Computes a Rectangle that is guaranteed to enclose the region of the source that is required in order to produce a given rectangular output region.

Overrides:
mapDestRect in class Warp
Parameters:
destRect - The Rectangle in destination coordinates.
Returns:
A Rectangle in the source coordinate system that is guaranteed to contain all pixels referenced by the output of warpRect() on the destination region, or null.
Throws:
IllegalArgumentException - if destRect is null.

mapSourceRect

public Rectangle mapSourceRect(Rectangle srcRect)
Computes a Rectangle that is guaranteed to enclose the region of the destination to which the source rectangle maps.

Overrides:
mapSourceRect in class Warp
Parameters:
srcRect - The Rectangle in source coordinates.
Returns:
A Rectangle in the destination coordinate system that is guaranteed to contain all pixels within the forward mapping of the source rectangle.
Throws:
IllegalArgumentException - if srctRect is null.
Since:
JAI 1.1

mapDestPoint

public Point2D mapDestPoint(Point2D destPt)
Computes the source point corresponding to the supplied point.

This method returns the value of pt in the following code snippet:

 double dx = (destPt.getX() + 0.5)*preScaleX;
 double dy = (destPt.getY() + 0.5)*preScaleY;
 Point2D pt = (Point2D)destPt.clone();
 pt.setLocation((c1 + c2*dx + c3*dy)*postScaleX - 0.5F,
                (c4 + c5*dx + c6*dy)*postScaleY - 0.5F);
 

Overrides:
mapDestPoint in class WarpPolynomial
Parameters:
destPt - the position in destination image coordinates to map to source image coordinates.
Returns:
a Point2D of the same class as destPt.
Throws:
IllegalArgumentException - if destPt is null.
Since:
JAI 1.1.2

mapSourcePoint

public Point2D mapSourcePoint(Point2D sourcePt)
Computes the destination point corresponding to the supplied point.

If the transform is invertible, this method returns the value of pt in the following code snippet:

 double sx = (sourcePt.getX() + 0.5F)/postScaleX;
 double sy = (sourcePt.getY() + 0.5F)/postScaleY;
 Point2D pt = (Point2D)sourcePt.clone();
 pt.setLocation((invc1 + invc2*sx + invc3*sy)/preScaleX - 0.5F,
                (invc4 + invc5*sx + invc6*sy)/preScaleY - 0.5F);
 
where invc* are the inverse transform coefficients. If the transform is not invertible, null is returned.

Overrides:
mapSourcePoint in class Warp
Parameters:
sourcePt - the position in source image coordinates to map to destination image coordinates.
Returns:
a Point2D of the same class as sourcePt or null> if the transform is not invertible.
Throws:
IllegalArgumentException - if destPt is null.
Since:
JAI 1.1.2