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 piece-wise 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. Sub-classes
provide different types of transformations, include rigid, affine, and
non-linear.
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 application-specific 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 its matrix component results in
uniform scaling.
|
Constructor and Description |
---|
GeometryTransformer() |
Modifier and Type | Method and Description |
---|---|
AffineTransform3dBase |
computeLocalTransform(Vector3d r)
Computes and returns the local affine transform at the specified
reference position.
|
AffineTransform3d |
computeRightAffineTransform(RigidTransform3d T)
Computes and returns the right affine transform for the general
transformation of a rigid transform T.
|
abstract void |
computeTransform(AffineTransform3d XR,
AffineTransform3d X1)
Transforms an affine transform
X1 and returns the result in
XR . |
void |
computeTransform(AffineTransform3dBase X) |
abstract void |
computeTransform(Matrix3d MR,
Matrix3d M1,
Vector3d r)
Transforms a general 3 X 3 matrix
M1 , located at reference
position ref , and returns the result in MR . |
abstract void |
computeTransform(Plane pr,
Plane p1,
Vector3d r)
Transforms a plane
p1 , located at reference position
ref , and returns the result in pr . |
abstract void |
computeTransform(RigidTransform3d TR,
RigidTransform3d T1)
Transforms a rigid transform
T1 and returns the result in
TR . |
abstract void |
computeTransform(RotationMatrix3d RR,
RotationMatrix3d R1,
Vector3d r)
Transforms a rotation matrix
R1 , located at reference
position r , and returns the result in RR . |
abstract void |
computeTransformPnt(Point3d pr,
Point3d p1)
Transforms a point
p1 and returns the result in
pr . |
abstract void |
computeTransformVec(Vector3d vr,
Vector3d v1,
Vector3d r)
Transforms a vector
v1 , 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 . |
abstract boolean |
isAffine()
Returns
true if this transformer implements a linear affine
transform. |
abstract boolean |
isInvertible()
Returns
true if this transformer is invertible. |
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 application-specific 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 application-specific 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 X1)
Transforms an affine transform
X1 and returns the
result in XR . |
void |
transform(Matrix3d MR,
Matrix3d M1,
Vector3d ref)
Transforms a general 3 X 3 matrix
M1 , located at reference
position ref , and returns the result in MR . |
void |
transform(Matrix3d M,
Vector3d ref)
Transforms a general 3 X 3 matrix
M , located at reference
position ref , in place. |
void |
transform(MeshBase mesh)
Applies a geometric transformation to the vertex positions of a mesh, in
local mesh coordinates.
|
void |
transform(Plane pr,
Plane p1,
Vector3d r)
Transforms a plane
p1 , located at reference position
ref , 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 T1)
Transforms a rigid transform
T1 and returns the
result in TR . |
void |
transform(RotationMatrix3d RR,
RotationMatrix3d R1,
Vector3d r)
Transforms a rotation matrix
R1 , 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 |
transformPnt(Point3d p)
Transforms a point
p , in place. |
void |
transformPnt(Point3d pr,
Point3d p1)
Transforms a point
p1 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 v1,
Vector3d r)
Transforms a vector
v1 , 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 mesh-to-world 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 mesh-to-world 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 compile-time 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 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.
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 p1)
p1
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
p1
that was previously saved when the undo state was set to
GeometryTransformer.UndoState.SAVING
.
pr
- transformed pointp1
- point to be transformedpublic abstract void computeTransformPnt(Point3d pr, Point3d p1)
p1
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 pointp1
- point to be transformedpublic void transformVec(Vector3d v, Vector3d r)
v
, located at reference position
r
, in place.
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 v1, Vector3d r)
v1
, located at reference position
r
, and returns the result in vr
.
Generally, this transformation will take the form
vr = F v1where
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
v1
that was previously saved when the undo state was set to
GeometryTransformer.UndoState.SAVING
.
vr
- transformed vectorv1
- vector to be transformedr
- reference position of the vector, in original coordinatespublic abstract void computeTransformVec(Vector3d vr, Vector3d v1, Vector3d r)
v1
, 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 vectorv1
- vector to be transformedr
- reference position of the vector, in original coordinatespublic void transform(RigidTransform3d T)
T
, in place.
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 T1)
T1
and returns the
result in TR
. If
[ R1 p1 ] T1 = [ ] [ 0 1 ]then generally, this transform takes the form
[ RF R1 f(p1) ] TR = [ ] [ 0 1 ]where
RF
is the right-handed rotational component
of the deformation gradient F
at p1
, and f(p1)
is the deformed
position of p1
.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then TR
is instead set to the value of
T1
that was previously saved when the undo state was set to
GeometryTransformer.UndoState.SAVING
.
TR
- transformed transformT1
- transform to be transformedpublic void computeTransform(AffineTransform3dBase X)
public abstract void computeTransform(RigidTransform3d TR, RigidTransform3d T1)
T1
and returns the result in
TR
. This provides the low level implementation for the
transformation of rigid transforms and does not do any saving or
restoring of data.TR
- transformed transformT1
- transform to be transformedpublic void transform(AffineTransform3d X)
X
, in place.
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 X1)
X1
and returns the
result in XR
. If
[ A1 p1 ] X1 = [ ] [ 0 1 ]then generally, this transform takes the form
[ F A1 f(p1) ] XR = [ ] [ 0 1 ]where
F
is the deformation gradient
at p1
, and f(p1)
is the deformed
position of p1
.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then XR
is instead set to the value of
X1
that was previously saved when the undo state was set to
GeometryTransformer.UndoState.SAVING
.
XR
- transformed transformX1
- transform to be transformedpublic abstract void computeTransform(AffineTransform3d XR, AffineTransform3d X1)
X1
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 transformX1
- transform to be transformedpublic void transform(RotationMatrix3d R, Vector3d r)
R
, located at reference
position r
, in place.
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 R1, Vector3d r)
R1
, located at reference
position r
, and returns the result in RR
.
Generally, this transform takes the form
RR = RF R1where
RF
is the right-handed rotational component
of the polar decomposition of the deformation gradient F
at the reference position.
If this transformer's undo state is set to GeometryTransformer.UndoState.RESTORING
, then RR
is instead set to the value of
R1
that was previously saved when the undo state was set to
GeometryTransformer.UndoState.SAVING
.
RR
- transformed rotationR1
- rotation to be transformedr
- reference position of the rotation, in original coordinatespublic abstract void computeTransform(RotationMatrix3d RR, RotationMatrix3d R1, Vector3d r)
R1
, located at reference
position r
, and returns the result in RR
.
This provides the low level implementation for the transformation of
rotation matrices and does not do any saving or restoring of data.RR
- transformed rotationR1
- rotation to be transformedr
- reference position of the rotation, in original coordinatespublic void transform(Matrix3d M, Vector3d ref)
M
, located at reference
position ref
, in place.
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 transformedref
- reference position of the matrix, in original coordinatespublic void transform(Matrix3d MR, Matrix3d M1, Vector3d ref)
M1
, located at reference
position ref
, and returns the result in MR
.
Generally, this transform takes the form
MR = F M1where
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
M1
that was previously saved when the undo state was set to
GeometryTransformer.UndoState.SAVING
.
MR
- transformed matrixM1
- matrix to be transformedref
- reference position of the matrix, in original coordinatespublic abstract void computeTransform(Matrix3d MR, Matrix3d M1, Vector3d r)
M1
, located at reference
position ref
, 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 matrixM1
- 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.
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 p1, Vector3d r)
p1
, located at reference position
ref
, 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
p1
that was previously saved when the undo state was set to
GeometryTransformer.UndoState.SAVING
.
pr
- transformed planep1
- plane to be transformedr
- reference position of the plane, in original coordinatespublic abstract void computeTransform(Plane pr, Plane p1, Vector3d r)
p1
, located at reference position
ref
, 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 planep1
- 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 transformWorld(MeshBase mesh)
p
are modified to accomodate 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 accomodate 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 AffineTransform3d computeRightAffineTransform(RigidTransform3d T)
T" = T' XX hence contains the non-rigid parts of T", expressed as a transform that is applied before T'. If
[ R p ] T = [ ] [ 0 1 ]and PF RF = F is the left polar decomposition of the deformation gradient F at p, then
[ RF R f(p) ] [ F R f(p) ] T' = [ ], T'' = [ ] [ 0 1 ] [ 0 1 ]and X takes the form
[ A 0 ] X = [ ] with A = R^T RF^T PF RF R [ 0 1 ]
T
- rigid transform for which the right affine transform is computed.T
.public AffineTransform3dBase computeLocalTransform(Vector3d r)
ref
,
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 created