ImagerTransform.mesa
Copyright © 1984 Xerox Corporation. All rights reserved.
Frank Crow, July 31, 1983 3:28 pm
Michael Plass, February 7, 1984 10:44:55 am PST
Doug Wyatt, August 12, 1984 4:08:43 pm PDT
This interface provides the internal view of the procedures, structures, etc. involved in setting, modifying and using transformations in the imager.
DIRECTORY
Vector2 USING [VEC];
ImagerTransform: CEDAR DEFINITIONS
=
BEGIN
VEC: TYPE ~ Vector2.VEC; -- RECORD[x, y: REAL];
Pair: TYPE ~ VEC;
Rectangle: TYPE ~ RECORD [x, y, w, h: REAL];
IntRectangle: TYPE ~ RECORD [x, y, w, h: INTEGER];
Ref: TYPE ~ REF Rep;
Rep:
TYPE ~
RECORD[a, b, c, d, e, f:
REAL];
A two-dimensional affine transformation; represents the following 3 by 3 matrix:
a d 0
b e 0
c f 1
Transformation: TYPE ~ Ref;
TransformationRec: TYPE ~ Rep;
Access to transformation fields.
Contents: PROC[m: Ref] RETURNS[Rep] ~ INLINE { RETURN[m^] };
FromRec: PROC[Rep] RETURNS[Ref];
These make new transformation matrices.
Create:
PROC[a, b, c, d, e, f:
REAL]
RETURNS[Ref];
Create a new transformation.
Copy:
PROC[m: Ref]
RETURNS[Ref];
Make a copy of m.
Translate:
PROC[x, y:
REAL]
RETURNS[Ref];
Equivalent to Create[1, 0, x, 0, 1, y].
Scale:
PROC[s:
REAL]
RETURNS[Ref];
Equivalent to Create[s, 0, 0, 0, s, 0].
Scale2:
PROC[sx, sy:
REAL]
RETURNS[Ref];
Equivalent to Create[sx, 0, 0, 0, sy, 0].
Rotate:
PROC[a:
REAL]
RETURNS[Ref];
Equivalent to Create[cos(a), -sin(a), 0, sin(a), cos(a), 0]. Angle a is in degrees.
Concat:
PROC[m, n: Ref]
RETURNS[Ref];
Returns the matrix product mn.
Invert:
PROC[m: Ref]
RETURNS[Ref];
Returns m's inverse.
These modify an existing transformation in place.
PreMultiply:
PROC[m, pre: Ref];
Equivalent to m^ ← Concat[pre, m]^.
PreScale:
PROC[m: Ref, s:
REAL];
Equivalent to PreMultiply[m, Scale[s]].
PreScale2:
PROC[m: Ref, sx, sy:
REAL];
Equivalent to PreMultiply[m, Scale2[sx, sy]].
PreRotate:
PROC[m: Ref, a:
REAL];
Equivalent to PreMultiply[m, Rotate[a]].
PreTranslate:
PROC[m: Ref, x, y:
REAL];
Equivalent to PreMultiply[m, Translate[x, y]].
PostMultiply:
PROC[m, post: Ref];
Equivalent to m^ ← Concat[m, post]^.
PostScale:
PROC[m: Ref, s:
REAL];
Equivalent to PostMultiply[m, Scale[s]].
PostScale2:
PROC[m: Ref, sx, sy:
REAL];
Equivalent to PostMultiply[m, Scale2[sx, sy]].
PostRotate:
PROC[m: Ref, a:
REAL];
Equivalent to PostMultiply[m, Rotate[a]].
PostTranslate:
PROC[m: Ref, x, y:
REAL];
Equivalent to PostMultiply[m, Translate[x, y]].
Get:
PROC[m: Ref]
RETURNS[Rep] ~
INLINE {
RETURN[m^] };
Get m's contents.
Set:
PROC[m: Ref, value: Rep] ~
INLINE { m^ ← value };
Set m to a given transformation.
GetTrans:
PROC[m: Ref]
RETURNS[
VEC] ~
INLINE {
RETURN[[m.c, m.f]] };
Get m's translation part.
SetTrans:
PROC[m: Ref, value:
VEC] ~
INLINE { m.c ← value.x; m.f ← value.y };
Set m's translation part.
These apply a transform (or its inverse) to a position or displacement
Transform:
PROC[m: Ref, v:
VEC]
RETURNS[
VEC];
"Point" transformation: [m.a*v.x + m.b*v.y + m.c, m.d*v.x + m.e*v.y + m.f].
TransformVec:
PROC[m: Ref, v:
VEC]
RETURNS[
VEC];
"Vector" transformation: [m.a*v.x + m.b*v.y, m.d*v.x + m.e*v.y].
InverseTransform:
PROC[m: Ref, v:
VEC]
RETURNS[
VEC];
Equivalent to Invert[m].Transform[v].
InverseTransformVec:
PROC[m: Ref, v:
VEC]
RETURNS[
VEC];
Equivalent to Invert[m].TransformVec[v].
These test for transformations that are close to each other.
CloseEnough:
PROC [s, t: Transformation, rangeSize:
REAL ← 2000.0]
RETURNS [
BOOLEAN];
Returns TRUE if for all points p such that Transform[p, s] is in [0, 0, rangeSize, rangeSize], Transform[p, s] and Transform[p, t] differ by at most 1/4 pixel.
CloseToTranslation:
PROC [s, t: Transformation, rangeSize:
REAL ← 2000.0]
RETURNS [
BOOLEAN];
Returns TRUE if for all points p such that TransformVec[p, s] is in [0, 0, rangeSize, rangeSize], TransformVec[p, s] and TransformVec[p, t] differ by at most 1/4 pixel.
These always return rectangles, thus "hard" transforms will cause a bounding box to be returned
TransformRectangle: PROC[m: Ref, rect: Rectangle] RETURNS[Rectangle];
TransformIntRectangle: PROC[m: Ref, rect: Rectangle] RETURNS[IntRectangle];
Computing singular values
SingularValues:
PROC [m: Ref]
RETURNS [Pair];
Returns the singular values of the non-translation portion of m. These are the square roots of the eigenvalues of the symmetric matrix MMT, where M is the non-translation portion. The x component is the larger of the two. These correspond to the maximum and minimum magnitudes that the image of a unit vector can achieve.
END.