public abstract class GeometryTransformer
extends java.lang.Object
p
are mapped
to deformed points p'
using a function
p' = f (p)The mapping is assumed to be piecewise differentiable, so that each point
p
is also associated with a
deformation gradient F
.
The transformations can be applied to a variety of primitives, including
points, vectors, planes, meshes, and transformation matrices. Subclasses
provide different types of transformations, include rigid, affine, and
nonlinear.
The transformations themselves are effected with a set of
transform()
methods, one for each primitive type. Primitives
of type Point3d
and Vector3d
are transformed using
primitives named transformVec()
and
transformPnt()
, to help resolve ambiguities between point and
vector transformations.
The transformer is able to save and restore the previous values associated
with each transformation, so that its transform actions can later be
"undone". Storing of save information is activated by calling
setUndoState(UndoState.SAVING)
, after which each transform
operation will save the original value of each primitive. Restoring of this
information is then activated by calling
setUndoState(UndoState.RESTORING)
, after which each transform
operation will restore the original primitive value instead of performing
the actual transformation. For example:
GeometryTransformer gtr; Vector3d v1, v2; Plane plane; ... initialize variables ... // start saving undo information gtr.setUndoState (UndoState.SAVING); gtr.transformVec (v1); gtr.transformVec (v2); // transform v1, v2, and plane gtr.transform (plane) // restore undo information gtr.setUndoState (UndoState.RESTORING); gtr.transformVec (v1); gtr.transformVec (v2); // restore v1, v2, and plane to their gtr.transform (plane) // original valuesWhen restoring undo information, operations must be called on the same primitives in the same order as was used during the original transform. It is the responsibility of the calling application to ensure this. The caller may also save and restore additional applicationspecific information using the primitives
saveObject(java.lang.Object)
and restoreObject(T)
.Modifier and Type  Class and Description 

static interface 
GeometryTransformer.Constrainer
Implements constraint operations on rigid or affine transform objects.

static class 
GeometryTransformer.UndoState
Describes the current undo state of this transformer.

static class 
GeometryTransformer.UniformScalingConstrainer
Constrains an affine transform so that it results in
uniform scaling with no translation

Constructor and Description 

GeometryTransformer() 
Modifier and Type  Method and Description 

AffineTransform3dBase 
computeLinearizedTransform(Vector3d r)
Computes and returns the linearized affine transform at the specified
reference position.

AffineTransform3d 
computeLocalAffineTransform(RigidTransform3d T,
GeometryTransformer.Constrainer constrainer)
Computes the local affine transform
XL that transforms
points xl local to a coordinate frame T after
that frame is itself transformed. 
abstract void 
computeLocalTransforms(Matrix3d PL,
Vector3d Ndiag,
RigidTransform3d T)
Computes the matrices
PL and N that transform
points xl local to a coordinate frame T after
that frame is itself transformed. 
abstract void 
computeTransform(AffineTransform3d XR,
AffineTransform3d X)
Transforms an affine transform
X and returns the result in
XR . 
void 
computeTransform(AffineTransform3dBase X) 
abstract void 
computeTransform(Matrix3d MR,
Matrix3d M,
Vector3d r)
Transforms a general 3 X 3 matrix
M , located at reference
position r , and returns the result in MR . 
abstract void 
computeTransform(Plane pr,
Plane p,
Vector3d r)
Transforms a plane
p , located at reference position
r , and returns the result in pr . 
abstract void 
computeTransform(RotationMatrix3d RR,
Vector3d Ndiag,
RotationMatrix3d R,
Vector3d r)
Transforms a rotation matrix
R , located at reference
position r , and returns the result in RR ,
according to 
abstract void 
computeTransformNormal(Vector3d nr,
Vector3d n,
Vector3d r)
Transforms a normal vector
n , located at reference position
r , and returns the result in nr . 
abstract void 
computeTransformPnt(Point3d pr,
Point3d p)
Transforms a point
p and returns the result in
pr . 
abstract void 
computeTransformVec(Vector3d vr,
Vector3d v,
Vector3d r)
Transforms a vector
v , located at reference position
r , and returns the result in vr . 
static GeometryTransformer 
create(AffineTransform3dBase X)
Return an appropriate transformer for a given affine transform.

abstract GeometryTransformer 
getInverse()
Returns a transformer that implements the inverse operation of
this transformer, if
isInvertible() returns true . 
int 
getUndoDataSize()
Return the current size of the undo data buffer, or 1 if the buffer is
null.

abstract boolean 
isAffine()
Returns
true if this transformer implements a linear affine
transform. 
abstract boolean 
isInvertible()
Returns
true if this transformer is invertible. 
boolean 
isReflecting()
Returns
true if this transformer globally implements a
reflection (i.e., the determinant of the deformation gradient
at all transformation points is negative). 
boolean 
isRestoring()
Returns
true if the undo state of this transformer is set to
restore primitive values. 
abstract boolean 
isRigid()
Returns
true if this transformer implements a linear
rigid transform. 
boolean 
isSaving()
Returns
true if the undo state of this transformer is set to
save primitive values. 
void 
popRestoreData(int cnt)
Removes
cnt items of restore data if the undo state of this
transformer is set to GeometryTransformer.UndoState.RESTORING . 
<T> T 
restoreObject(T obj)
Returns applicationspecific data (that was previously set using
saveObject(java.lang.Object) ) if the undo state of this transformer is set to GeometryTransformer.UndoState.RESTORING . 
void 
saveObject(java.lang.Object obj)
Saves applicationspecific data if the undo state of this transformer is
set to
GeometryTransformer.UndoState.SAVING . 
void 
setUndoState(GeometryTransformer.UndoState state)
Sets the undo state of this transformer so as to enable it save or
restore the original data form transformation operations.

void 
transform(AffineTransform3d X)
Transforms an affine transform
X , in place. 
void 
transform(AffineTransform3d XR,
AffineTransform3d X)
Transforms an affine transform
X and returns the
result in XR . 
void 
transform(Matrix3d MR,
Matrix3d M,
Vector3d r)
Transforms a general 3 X 3 matrix
M , located at reference
position r , and returns the result in MR . 
void 
transform(Matrix3d M,
Vector3d r)
Transforms a general 3 X 3 matrix
M , located at reference
position r , in place. 
void 
transform(MeshBase mesh)
Applies a geometric transformation to the vertex positions of a mesh, in
local mesh coordinates.

void 
transform(MeshBase mesh,
GeometryTransformer.Constrainer constrainer) 
void 
transform(Plane pr,
Plane p,
Vector3d r)
Transforms a plane
p , located at reference position
r , and returns the result in pr . 
void 
transform(Plane p,
Vector3d r)
Transforms a plane
p , located at reference
position r , in place. 
void 
transform(RigidTransform3d T)
Transforms a rigid transform
T , in place. 
void 
transform(RigidTransform3d TR,
RigidTransform3d T)
Transforms a rigid transform
T and returns the
result in TR . 
void 
transform(RotationMatrix3d RR,
RotationMatrix3d R,
Vector3d r)
Transforms a rotation matrix
R , located at reference
position r , and returns the result in RR . 
void 
transform(RotationMatrix3d R,
Vector3d r)
Transforms a rotation matrix
R , located at reference
position r , in place. 
void 
transformNormal(Vector3d n,
Vector3d r)
Transforms a normal vector
n , located at reference position
r , in place. 
void 
transformNormal(Vector3d nr,
Vector3d n,
Vector3d r)
Transforms a normal vector
n , located at reference position
r , and returns the result in nr . 
void 
transformPnt(Point3d p)
Transforms a point
p , in place. 
void 
transformPnt(Point3d pr,
Point3d p)
Transforms a point
p and returns the result in
pr . 
void 
transformVec(Vector3d v,
Vector3d r)
Transforms a vector
v , located at reference position
r , in place. 
void 
transformVec(Vector3d vr,
Vector3d v,
Vector3d r)
Transforms a vector
v , located at reference position
r , and returns the result in vr . 
void 
transformWorld(MeshBase mesh)
Applies a geometric transformation to both the vertex positions of a mesh
and its meshtoworld transform TMW, in world coordinates.

double 
transformWorld(MeshBase mesh,
GeometryTransformer.Constrainer constrainer)
Applies a geometric transformation to both the vertices of a mesh and
its meshtoworld transform TMW, in world coordinates.

public void setUndoState(GeometryTransformer.UndoState state)
state
 new undo statepublic boolean isRestoring()
true
if the undo state of this transformer is set to
restore primitive values.public boolean isSaving()
true
if the undo state of this transformer is set to
save primitive values.public <T> T restoreObject(T obj)
saveObject(java.lang.Object)
) if the undo state of this transformer is set to GeometryTransformer.UndoState.RESTORING
. Otherwise, an exception is thrown.obj
 any object with the same data type as the object to be
restored. Used only for compiletime type checking and will not be
modified.public void saveObject(java.lang.Object obj)
GeometryTransformer.UndoState.SAVING
. Otherwise, an exception is thrown.obj
 object to be saved.public void popRestoreData(int cnt)
cnt
items of restore data if the undo state of this
transformer is set to GeometryTransformer.UndoState.RESTORING
. Otherwise, an
exception is thrown.cnt
 number of restore items to remove.public abstract boolean isRigid()
true
if this transformer implements a linear
rigid transform.public abstract boolean isAffine()
true
if this transformer implements a linear affine
transform.public boolean isReflecting()
true
if this transformer globally implements a
reflection (i.e., the determinant of the deformation gradient
at all transformation points is negative). The default declaration
of this method returns false
. Subclasses should
override this if necessary.public abstract boolean isInvertible()
true
if this transformer is invertible. If it is,
then an inverse transformer can be obtained using getInverse()
.public abstract GeometryTransformer getInverse()
isInvertible()
returns true
.public void transformPnt(Point3d p)
p
, in place.
This is equivalent to transformPnt(p,p)
.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then p
is instead set to its original
value that was previously saved when the undo state was set to GeometryTransformer.UndoState.SAVING
.
p
 point to be transformedpublic void transformPnt(Point3d pr, Point3d p)
p
and returns the result in
pr
.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then pr
is instead set to the value of
p
that was previously saved when the undo state was set to
GeometryTransformer.UndoState.SAVING
.
pr
 transformed pointp
 point to be transformedpublic abstract void computeTransformPnt(Point3d pr, Point3d p)
p
and returns the result in
pr
. This provides the low level implementation for point
transformations and does not do any saving or restoring of data.pr
 transformed pointp
 point to be transformedpublic void transformVec(Vector3d v, Vector3d r)
v
, located at reference position
r
, in place.
This is equivalent to transformVec(v,v,r)
.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then v
is instead set to its original
value that was previously saved when the undo state was set to GeometryTransformer.UndoState.SAVING
.
v
 vector to be transformedr
 reference position of the vector, in original coordinatespublic void transformVec(Vector3d vr, Vector3d v, Vector3d r)
v
, located at reference position
r
, and returns the result in vr
.
Generally, this transformation will take the form
vr = F vwhere
F
is the deformation gradient at the reference
position.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then vr
is instead set to the value of
v
that was previously saved when the undo state was set to
GeometryTransformer.UndoState.SAVING
.
vr
 transformed vectorv
 vector to be transformedr
 reference position of the vector, in original coordinatespublic abstract void computeTransformVec(Vector3d vr, Vector3d v, Vector3d r)
v
, located at reference position
r
, and returns the result in vr
. This
provides the low level implementation for vector transformations and does
not do any saving or restoring of data.vr
 transformed vectorv
 vector to be transformedr
 reference position of the vector, in original coordinatespublic void transformNormal(Vector3d n, Vector3d r)
n
, located at reference position
r
, in place. This is equivalent to transformNormal(n,
n)
.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then n
is instead set to its original
value that was previously saved when the undo state was set to GeometryTransformer.UndoState.SAVING
.
n
 normal to be transformedr
 reference position of the normal, in original coordinatespublic void transformNormal(Vector3d nr, Vector3d n, Vector3d r)
n
, located at reference position
r
, and returns the result in nr
.
Generally, this transformation will take the form
1 T nr = F nwhere
F
is the deformation gradient at the reference
position. The result is not normalized since
the unnormalized form could be useful in some contexts.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then nr
is instead set to the value of
n
that was previously saved when the undo state was set to
GeometryTransformer.UndoState.SAVING
.
nr
 transformed normaln
 normal to be transformedr
 reference position of the normal, in original coordinatespublic abstract void computeTransformNormal(Vector3d nr, Vector3d n, Vector3d r)
n
, located at reference position
r
, and returns the result in nr
. This
provides the low level implementation for normal transformations and does
not do any saving or restoring of data.nr
 transformed normaln
 normal to be transformedr
 reference position of the normal, in original coordinatespublic void transform(RigidTransform3d T)
T
, in place.
This is equivalent to transform(T,T)
.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then T
is instead set to its original
value that was previously saved when the undo state was set to GeometryTransformer.UndoState.SAVING
.
T
 rigid transform to be transformed.public void transform(RigidTransform3d TR, RigidTransform3d T)
T
and returns the
result in TR
. If
[ R p ] T = [ ] [ 0 1 ]and
f(p)
and F
are the deformed position
and deformation gradient at p
, then
generally this transform takes the form
[ Q R N f(p) ] TR = [ ] [ 0 1 ]where
Q
is the orthogonal matrix from the left polar
decomposition F = P Q
, and N
is matrix that
flips an axis to ensure that Q R N
remains righthanded.
If det(Q) = 1
, then N
is the identity, while if
det(Q) = 1
, then N
is typically choosen to
correspond to the axis least affected by Q
, which is the one
corresponding to the diagonal of Q
nearest to 1.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then TR
is instead set to the value of
T
that was previously saved when the undo state was set to
GeometryTransformer.UndoState.SAVING
.
TR
 transformed transformT
 transform to be transformedpublic void computeTransform(AffineTransform3dBase X)
public void transform(AffineTransform3d X)
X
, in place.
This is equivalent to transform(X,X)
.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then X
is instead set to its original
value that was previously saved when the undo state was set to GeometryTransformer.UndoState.SAVING
.
X
 affine transform to be transformed.public void transform(AffineTransform3d XR, AffineTransform3d X)
X
and returns the
result in XR
. If
[ A p ] X = [ ] [ 0 1 ]then generally, this transform takes the form
[ F A f(p) ] XR = [ ] [ 0 1 ]where
F
is the deformation gradient
at p
, and f(p)
is the deformed
position of p
.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then XR
is instead set to the value of
X
that was previously saved when the undo state was set to
GeometryTransformer.UndoState.SAVING
.
XR
 transformed transformX
 transform to be transformedpublic abstract void computeTransform(AffineTransform3d XR, AffineTransform3d X)
X
and returns the result in
XR
. This provides the low level implementation for the
transformation of affine transforms and does not do any saving or
restoring of data.XR
 transformed transformX
 transform to be transformedpublic void transform(RotationMatrix3d R, Vector3d r)
R
, located at reference
position r
, in place.
This is equivalent to transform(R,R,r)
.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then R
is instead set to its original
value that was previously saved when the undo state was set to GeometryTransformer.UndoState.SAVING
.
R
 rotation to be transformedr
 reference position of the rotation, in original coordinatespublic void transform(RotationMatrix3d RR, RotationMatrix3d R, Vector3d r)
R
, located at reference
position r
, and returns the result in RR
.
If F
is the deformation gradient at r
,
this transform takes the form
RR = Q R Nwhere
Q
is the orthogonal matrix from the left polar
decomposition F = P Q
, and N
is matrix that
flips an axis to ensure that Q R N
remains righthanded.
If det(Q) = 1
, then N
is the identity, while if
det(Q) = 1
, then N
is typically choosen to
correspond to the axis least affected by Q
, which is the one
corresponding to the diagonal of Q
nearest to 1.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then RR
is instead set to the value of
R
that was previously saved when the undo state was set to
GeometryTransformer.UndoState.SAVING
.
RR
 transformed rotationR
 rotation to be transformedr
 reference position of the rotation, in original coordinatespublic abstract void computeTransform(RotationMatrix3d RR, Vector3d Ndiag, RotationMatrix3d R, Vector3d r)
R
, located at reference
position r
, and returns the result in RR
,
according to
RR = Q R Nwhere
P
, Q
and N
are described
in the documentation for transform(RotationMatrix3d,RotationMatrix3d,Vector3d)
.
This provides the low level implementation for the transformation of rotation matrices and does not do any saving or restoring of data.
RR
 transformed rotationR
 rotation to be transformedr
 reference position of the rotation, in original coordinatesNdiag
 if nonnull, returns the diagonal elements of the
matrix N
public void transform(Matrix3d M, Vector3d r)
M
, located at reference
position r
, in place.
This is equivalent to transform(M,M,r)
.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then M
is instead set to its original
value that was previously saved when the undo state was set to GeometryTransformer.UndoState.SAVING
.
M
 matrix to be transformedr
 reference position of the matrix, in original coordinatespublic void transform(Matrix3d MR, Matrix3d M, Vector3d r)
M
, located at reference
position r
, and returns the result in MR
.
Generally, this transform takes the form
MR = F Mwhere
F
is the deformation gradient at the reference
position.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then MR
is instead set to the value of
M
that was previously saved when the undo state was set to
GeometryTransformer.UndoState.SAVING
.
MR
 transformed matrixM
 matrix to be transformedr
 reference position of the matrix, in original coordinatespublic abstract void computeTransform(Matrix3d MR, Matrix3d M, Vector3d r)
M
, located at reference
position r
, and returns the result in MR
.
This provides the low level implementation for the transformation of 3 X
3 matrices and does not do any saving or restoring of data.MR
 transformed matrixM
 matrix to be transformedr
 reference position of the matrix, in original coordinatespublic void transform(Plane p, Vector3d r)
p
, located at reference
position r
, in place.
This is equivalent to transform(p,p,r)
.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then p
is instead set to its original
value that was previously saved when the undo state was set to GeometryTransformer.UndoState.SAVING
.
p
 plane to be transformedr
 reference position of the plane, in original coordinatespublic void transform(Plane pr, Plane p, Vector3d r)
p
, located at reference position
r
, and returns the result in pr
.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then pr
is instead set to the value of
p
that was previously saved when the undo state was set to
GeometryTransformer.UndoState.SAVING
.
pr
 transformed planep
 plane to be transformedr
 reference position of the plane, in original coordinatespublic abstract void computeTransform(Plane pr, Plane p, Vector3d r)
p
, located at reference position
r
, and returns the result in pr
. This
provides the low level implementation for the transformation of planes
and does not do any saving or restoring of data.pr
 transformed planep
 plane to be transformedr
 reference position of the plane, in original coordinatespublic void transform(MeshBase mesh)
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then the vertex positions are instead set to their
original values that were previously saved when the undo state was set to
GeometryTransformer.UndoState.SAVING
.
mesh
 Mesh to be transformedpublic void transform(MeshBase mesh, GeometryTransformer.Constrainer constrainer)
public void transformWorld(MeshBase mesh)
p
are modified to accommodate that of part
of the transformation not provided by the change to TMW. Specifically,
p' = TMWnew X (TMW p)where
X( )
indicates the
transform applied by this transformer and TMWnew is the transformed value
of TMW
.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then the vertex positions and TMW are instead set
to their original values that were previously saved when the undo state
was set to GeometryTransformer.UndoState.SAVING
.
mesh
 Mesh to be transformedpublic double transformWorld(MeshBase mesh, GeometryTransformer.Constrainer constrainer)
p
are modified to accommodate that part
of the transformation not provided by the change to TMW. If
a constrainer
is supplied, then this change is
constrained to that obtained by applying the constrainer to
the local affine transform obtained at the origin of the mesh
coordinate system. Otherwise, this method behaves identically to
transformWorld(MeshBase)
.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then the vertex positions and TMW are instead set
to their original values that were previously saved when the undo state
was set to GeometryTransformer.UndoState.SAVING
.
mesh
 Mesh to be transformedpublic abstract void computeLocalTransforms(Matrix3d PL, Vector3d Ndiag, RigidTransform3d T)
PL
and N
that transform
points xl
local to a coordinate frame T
after
that frame is itself transformed. The updated local coordinates are
given by
xl' = N PL xlwhere
PL
is symmetric positive definite and
N
is a diagonal matrix that is either the identity,
or a reflection that flips a single axis. This accounts
for the nonrigid aspects of the transformation
that cannot be absorbed into T
.
See the documentation for transform(RigidTransform3d,RigidTransform3d)
. If
[ R p ] T = [ ] [ 0 1 ]then
[ Q R N f(p) ] TR = [ ]. [ 0 1 ]Meanwhile, the linearization of f(p) about
p
is given
by the affine transform
[ F F p + f(p) ] X = [ ]. [ 0 1 ]If
xw
and xl
describe points with respect
to world and T
, respectively,
we have
xw' = X xw = X T xland so the updated value of
xl
is given by
xl' = inv(TR) xw' = inv(TR) X T xlwhich can be expressed as
T T xl' = N PL xl, PL = R Q P Q R
PL
 primary transformation matrixNdiag
 if nonnull, returns the diagonal components of NT
 rigid transform for which the local transforms are computed.public AffineTransform3d computeLocalAffineTransform(RigidTransform3d T, GeometryTransformer.Constrainer constrainer)
XL
that transforms
points xl
local to a coordinate frame T
after
that frame is itself transformed. The updated local coordinates are
given by
[ xl' ] [ xl ] [ ] = XL [ ] [ 1 ] [ 0 ]and
XL
is computed from the PL
and
N
matrices returned by
computeLocalTransform(PL,Ndiag,T)
, according to
[ N PL 0 ] XL = [ ]. [ 0 1 ]An optional
constrainer
can be provided to
further constrain the resulting value of XL
.T
 rigid transform for which the local affine transform is computedconstrainer
 if nonnull, specifies a constrainer that should be
applied to constrain the value of the transformpublic AffineTransform3dBase computeLinearizedTransform(Vector3d r)
r
,
given by
[ F f(dp) ] X = [ ] [ 0 1 ]so that for a small change in position
dp
, we have
[ dp ] f(p+dp) = X [ ] [ 1 ]In the case where f(p) is itself an affine or rigid transform given by
[ F px ] A = [ ] [ 0 1 ]the local transform becomes
[ F F p + px ] X = [ ] [ 0 1 ]and if p = 0, then X is the simply the transform itself.
r
 reference position at which the transformation is calculatedpublic static GeometryTransformer create(AffineTransform3dBase X)
X
 Affine transform (either rigid or strictly affine) for which
the transformer should be createdpublic int getUndoDataSize()