Class TransMatrix
- java.lang.Object
-
- WildMagic.LibFoundation.Mathematics.Matrix4f
-
- gov.nih.mipav.model.structures.TransMatrix
-
- All Implemented Interfaces:
java.io.Serializable
public class TransMatrix extends WildMagic.LibFoundation.Mathematics.Matrix4f
Transformation matrix class is an affine homogeneous class that can be used to rotate objects like images and VOIs. It can constructed as a 2D(3x3) or 3D(4x4) homogeneous matrix for transform (rotation, translation, skew and zoom) images/VOIs. Skew is not commonly used.The MIPAV 3D model for 4 X 4 transformations is:
[ m00 m01 m02 m03 ] [ x ] [ x' ] [ m10 m11 m12 m13 ] . [ y ] = [ y' ] [ m20 m21 m22 m23 ] [ z ] [ z' ] [ m30 m31 m32 m33 ] [ w ] [ w' ] x' = m00*x + m01*y + m02*z + m03*w y' = m10*x + m11*y + m12*z + m13*w z' = m20*x + m21*y + m22*z + m23*w w' = m30*x + m31*y + m32*z + m33*w
However, because the transform type is limited, we can always set the third row to [ 0 0 0 1] and write instead:
[ m00 m01 m02 ] [ x ] [ t0 ] [ x' ] [ m10 m11 m12 ] . [ y ] + [ t1 ] = [ y' ] [ m20 m21 m22 ] [ z ] [ t2 ] [ z' ] x' = m00*x + m01*y + m02*z + t0 y' = m10*x + m11*y + m12*z + t1 z' = m20*x + m21*y + m22*z + t2
We still represent 4x4 m with a WildMagic Matrix4f, because of the existing implementations that assume a 4x4 matrix, and the use of the upper 3x3 matrix as a 2D transform.
We considered representing m with a WildMagic Matrix3f, and t with a Vector3f, as encapsulated in the WildMagic Transformation class, but it does not match typical Mipav usage.
ORDER OF TRANSFORMATIONS = TRANSLATE, ROTATE, ZOOM or TRANSLATE, ROTATE, SKEW, ZOOM
Row, Col format - right hand rule
2D Example
zoom_x theta tx theta zoom_y ty 0 0 1 represented in 3D by leaving Z the identity transform: zoom_x theta 0 tx theta zoom_y 0 ty 0 0 1 0 0 0 0 1
Note that for 2D, the tx and ty components are stored in M02 and M12, and not in M03 and M13, as might be guessed by the use of a Matrix4f to store both 2D and 3D transforms.
Note for 3D - ref. Foley, Van Dam p. 214
Axis of rotation Direction of positive rotation is x y to z y z to x z x to y
Order of rotation is important (i.e. not commutative) Rx Ry Ry != Ry Rx Rz
- Version:
- 2, July 24, 2008, original 0.1 Nov 15, 1997
- Author:
- Matthew J. McAuliffe, Ph.D., changes Aron Helser, Geometric Tools
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
TransMatrix.DataFileV2Keys
-
Field Summary
Fields Modifier and Type Field Description static int
DEGREES
used for setting rotationprivate boolean
m_Is2D
Transform was constructed to transform 2D vectors, instead of 3Dprivate boolean
m_IsNIFTI
boolean indicating whether this matrix is associated with a NIFTI image (special case handling)private boolean
m_IsQform
If true, nifti matrix codes for a qform matrix If false, nifti matrix codes for a sform matrix Value has no effect if not a nifti matrixprivate int
m_TransformID
Transform ID associated with the matrix.private static java.lang.String
MIPAV_DATA_FILE_V2_HEADER
static int
RADIANS
used for setting rotationprivate static long
serialVersionUID
Use serialVersionUID for interoperability.static int
TRANSFORM_ANOTHER_DATASET
Another Dataset transform ID.static int
TRANSFORM_COMPOSITE
Composite, dynamically generated matrix typeprivate static java.lang.String[]
TRANSFORM_ID_STR
Array of transform ID strings.static int
TRANSFORM_MNI_152
MNI 152 transform ID.static int
TRANSFORM_NIFTI_SCANNER_ANATOMICAL
Scanner anatomical matrix associated with NIFTI typestatic int
TRANSFORM_SCANNER_ANATOMICAL
Scanner Anatomical transform ID.static int
TRANSFORM_TALAIRACH_TOURNOUX
Talairach Tournoux transform ID.static int
TRANSFORM_UNKNOWN
Composite transform ID.
-
Constructor Summary
Constructors Constructor Description TransMatrix(int dim)
Construct a transformation matrix.TransMatrix(int dim, int id)
TransMatrix(int dim, int id, boolean is_nifti, boolean isQform)
TransMatrix(TransMatrix rkTM)
copy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description TransMatrix
clone()
void
Copy(TransMatrix rkTM)
copy, overwrite this.void
copyMatrix(double[][] newMatrix)
Copies provided transformation matrix.private static TransMatrix
createMatrixFromAfni(java.util.ArrayList<java.lang.Float> d)
private void
decodeLine(java.io.RandomAccessFile raFile, int row, WildMagic.LibFoundation.Mathematics.Matrix4f matrix)
Decodes the line in the matrix file.private static void
decodeLine(java.io.RandomAccessFile raFile, int row, WildMagic.LibFoundation.Mathematics.Matrix4f matrix, int dim)
Reads a row of the matrix from fileprivate void
decodeLine(java.lang.String str, int row, WildMagic.LibFoundation.Mathematics.Matrix4f matrix)
Decodes the line in the matrix file.void
decodeMatrixString(java.lang.String str)
Decodes the matrix from a string into the matrix array.boolean
decomposeMatrix(WildMagic.LibFoundation.Mathematics.Vector3f rotate, WildMagic.LibFoundation.Mathematics.Vector3f trans, WildMagic.LibFoundation.Mathematics.Vector3f scale, WildMagic.LibFoundation.Mathematics.Vector3f shear)
Decomposing a matrix into simple transformations TransMatrix transformation sequence: Scale(Sx, Sy, Sz)*ShearXY*ShearXZ*ShearYZ* RotateX*RotateY*RotateZ*Translate(tx, ty, tz) ( *Perspective(Px, Py, Pz, Pw), no longer supported)private boolean
getBooleanProperty(java.util.Properties props, java.lang.String key)
void
getColumn(int r, double[] column)
Copy our data into the provided double arrayint
getDim()
Return dimension passed to constructor.private float
getFloatProperty(java.util.Properties props, java.lang.String key)
private int
getIntProperty(java.util.Properties props, java.lang.String key)
private java.lang.String
getProperty(java.util.Properties props, java.lang.String key)
int
getTransformID()
Returns the transform ID associated with the matrix.static int
getTransformIDFromStr(java.lang.String s)
Returns the transform ID associated with a string.static java.lang.String[]
getTransformIDStr()
Return the list of transform ID strings (for edit attributes combo box.static java.lang.String
getTransformIDStr(int m)
Return the string associated with the matrix transform ID.void
Inverse()
Matrix inversion that replaces this objects matrix with an inverted matrix.boolean
isIdentity()
Reports whether transform is Identity transform, to within a small epsilon.boolean
isNIFTI()
Tells whether this matrix is associated with a NIFTI image this only matters when the matrix is being saved/when the composite matrix is being generated in MatrixHolderboolean
isQform()
Tells whether a NIFTI matrix is a qform matrix or a sform matrixstatic boolean
isV2MatrixDataFile(java.io.File f)
java.lang.String
matrixToString(int w, int d)
Produces a string of the matrix values.static TransMatrix
readAfniMatrix(java.io.RandomAccessFile raFile)
Reads AFNI-style matrix and does processing to generate TransMatrix resultprivate void
readLegacyFileParameters(java.io.RandomAccessFile raFile, int[] interp, float[] oXres, float[] oYres, float[] oZres, int[] oXdim, int[] oYdim, int[] oZdim, boolean[] tVOI, boolean[] clip, boolean[] pad)
void
readMatrix(java.io.RandomAccessFile raFile, boolean composite)
Reads transformation matrix to a text file.boolean
readMatrix(java.io.RandomAccessFile raFile, int[] interp, float[] sourceXres, float[] sourceYres, float[] sourceZres, float[] targetXres, float[] targetYres, float[] targetZres, int[] sourceXdim, int[] sourceYdim, int[] sourceZdim, int[] targetXdim, int[] targetYdim, int[] targetZdim, boolean[] tVOI, boolean[] clip, boolean[] pad, boolean composite)
Reads transformation matrix to a text file.void
readMatrix(java.io.RandomAccessFile raFile, int[] interp, float[] oXres, float[] oYres, float[] oZres, int[] oXdim, int[] oYdim, int[] oZdim, boolean[] tVOI, boolean[] clip, boolean[] pad, boolean composite)
Deprecated.static TransMatrix[]
readMultiMatrix(java.io.RandomAccessFile raFile)
Reads a file containing a list of multiple TransMatrix values.void
saveMatrix(java.io.RandomAccessFile raFile)
Saves transformation matrix to a text file MIPAV format.void
saveMatrix(java.io.RandomAccessFile raFile, int interp, float sourceXres, float sourceYres, float sourceZres, float targetXres, float targetYres, float targetZres, int sourceXdim, int sourceYdim, int sourceZdim, int targetXdim, int targetYdim, int targetZdim, boolean tVOI, boolean clip, boolean pad, java.lang.String message)
Saves transformation matrix to a text file MIPAV format.void
saveMatrix(java.io.RandomAccessFile raFile, int interp, float oXres, float oYres, float oZres, int oXdim, int oYdim, int oZdim, boolean tVOI, boolean clip, boolean pad, java.lang.String message)
Saves transformation matrix to a text file MIPAV formatvoid
saveMatrix(java.io.RandomAccessFile raFile, java.lang.String message)
Saves transformation matrix to a text file MIPAV format.void
saveMatrix(java.lang.String fileName)
Saves transformation matrix to a text file MIPAV formatvoid
saveMatrix(java.lang.String fileName, int interp, float sourceXres, float sourceYres, float sourceZres, float targetXres, float targetYres, float targetZres, int sourceXdim, int sourceYdim, int sourceZdim, int targetXdim, int targetYdim, int targetZdim, boolean tVOI, boolean clip, boolean pad, java.lang.String message)
void
saveMatrix(java.lang.String fileName, int interp, float oXres, float oYres, float oZres, int oXdim, int oYdim, int oZdim, boolean tVOI, boolean clip, boolean pad, java.lang.String message)
void
saveMatrix(java.lang.String fileName, java.lang.String message)
Saves transformation matrix to a text file MIPAV formatvoid
saveXFMMatrix(java.io.RandomAccessFile raFile)
Saves transformation matrix to McGill XFM formatTransMatrix
set(int r, int c, double val)
private void
setBooleanProperty(java.util.Properties props, java.lang.String key, boolean val)
private void
setFloatProperty(java.util.Properties props, java.lang.String key, float val)
private void
setIntProperty(java.util.Properties props, java.lang.String key, int val)
void
setIsNIFTI(boolean is_NIFTI)
Accessor that sets whether or not the matrix is a NIFTI matrix.void
setIsQform(boolean is_Qform)
Accessor that sets whether a nifti matrix is a qform matrix or a sform matrix.void
setMatrix(double[][] X)
Set a submatrix.void
setMatrix(int i0, int i1, int j0, int j1, double[][] X)
Set a submatrix.void
setRotate(double theta)
Sets the rotation (2D) of transformation matrix.void
setRotate(double thetaX, double thetaY, double thetaZ, int degreeORradian)
Sets rotation (3D) of transformation matrix.void
setRotate(WildMagic.LibFoundation.Mathematics.Vector3f alpha, WildMagic.LibFoundation.Mathematics.Vector3f beta, WildMagic.LibFoundation.Mathematics.Vector3f gamma)
Sets rotation (3D) of transformation matrix.void
setSkew(double x, double y)
Sets skew part of 2D matrix.void
setSkew(double x, double y, double z)
Sets the skew parts of 3D matrix (4D Homogenous).void
setTransform(double tX, double tY, double r)
Sets 2D transformation matrix.void
setTransform(double tX, double tY, double tZ, double rX, double rY, double rZ)
Sets the 3D transformation matrix [4x4].void
setTransform(double tX, double tY, double tZ, double rX, double rY, double rZ, double sX, double sY, double sZ, double skX, double skY, double skZ)
Sets the 3D transformation matrix [4x4].void
setTransformID(int t_id)
Sets the transform ID for the matrix.void
setTranslate(double x, double y)
Sets translation parts of 2D matrix.void
setTranslate(double x, double y, double z)
Sets the translation parts of 3D matrix (4D Homogenous).void
setZoom(double sx, double sy)
Sets the zoom parts of 2D matrix.void
setZoom(double sx, double sy, double sz)
Sets the zoom parts of 3D matrix.java.lang.String
toDialogString()
Produces a string of the matrix values, rows separated by tabs.java.lang.String
toString()
ToString method that includes the matrix printout as well as the transform ID of the transmatrixvoid
transform(double[] pt, double[] tPt)
Takes a 3D or 2D point (as a double array) and premultiplies it by the 3D transformation matrix.void
transform(double x, double y, double[] tPt)
Takes double components of a 2D point and premultiplies it by the 2d transformation matrix.void
transform(double x, double y, double z, double[] tPt)
Takes the double components of a 3D point and premultiplies it by the 3D transformation matrix.void
transform(float[] pt, float[] tPt)
Takes a 3D point, as a float array, and premultiplies it by the 3D transformation matrix.void
transform(float x, float y, float[] tPt)
Takes float components of a 2D point and premultiplies it by the 2d transformation matrix.void
transform(float x, float y, float z, float[] tPt)
Takes the float components of a 3D point and premultiplies it by the 3D transformation matrix.java.awt.Polygon
transform(java.awt.Polygon gon)
Tranforms a Polygon (2D).void
transformAsPoint2Df(WildMagic.LibFoundation.Mathematics.Vector2f[] vects, WildMagic.LibFoundation.Mathematics.Vector2f[] tVects)
Takes an array of Point2Df 2D vectors and multiplies them with the 2d transformation matrix.void
transformAsPoint3Df(WildMagic.LibFoundation.Mathematics.Vector3f pt, WildMagic.LibFoundation.Mathematics.Vector3f tPt)
Takes a Point3Df 3D point and multiplies it by the 3D transformation matrix.void
transformAsVector3Df(VOIBase vects, WildMagic.LibFoundation.Mathematics.Vector3f[] tVects)
Takes an array of Vector3Df 2D vectors and multiplies them with the 2d transformation matrix.void
transformAsVector3Df(WildMagic.LibFoundation.Mathematics.Vector3f[] vects, WildMagic.LibFoundation.Mathematics.Vector3f[] tVects)
Takes an array of Vector3Df 2D vectors and multiplies them with the 2d transformation matrix.-
Methods inherited from class WildMagic.LibFoundation.Mathematics.Matrix4f
adjoint, copy, determinant, equals, get, getColumnMajor, getData, identity, inverse, inverse, makeObliqueProjection, makePerspectiveProjection, makeReflection, makeZero, mult, mult, mult, mult, multLeft, multLeft, multLeft, multRight, multRight, qForm, set, set, timesTranspose, transpose, transpose, transposeTimes, transposeTimes
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Use serialVersionUID for interoperability.- See Also:
- Constant Field Values
-
TRANSFORM_UNKNOWN
public static final int TRANSFORM_UNKNOWN
Composite transform ID.- See Also:
- Constant Field Values
-
TRANSFORM_SCANNER_ANATOMICAL
public static final int TRANSFORM_SCANNER_ANATOMICAL
Scanner Anatomical transform ID.- See Also:
- Constant Field Values
-
TRANSFORM_ANOTHER_DATASET
public static final int TRANSFORM_ANOTHER_DATASET
Another Dataset transform ID.- See Also:
- Constant Field Values
-
TRANSFORM_TALAIRACH_TOURNOUX
public static final int TRANSFORM_TALAIRACH_TOURNOUX
Talairach Tournoux transform ID.- See Also:
- Constant Field Values
-
TRANSFORM_MNI_152
public static final int TRANSFORM_MNI_152
MNI 152 transform ID.- See Also:
- Constant Field Values
-
TRANSFORM_COMPOSITE
public static final int TRANSFORM_COMPOSITE
Composite, dynamically generated matrix type- See Also:
- Constant Field Values
-
TRANSFORM_NIFTI_SCANNER_ANATOMICAL
public static final int TRANSFORM_NIFTI_SCANNER_ANATOMICAL
Scanner anatomical matrix associated with NIFTI type- See Also:
- Constant Field Values
-
TRANSFORM_ID_STR
private static final java.lang.String[] TRANSFORM_ID_STR
Array of transform ID strings.
-
DEGREES
public static final int DEGREES
used for setting rotation- See Also:
- Constant Field Values
-
RADIANS
public static final int RADIANS
used for setting rotation- See Also:
- Constant Field Values
-
m_TransformID
private int m_TransformID
Transform ID associated with the matrix.
-
m_IsNIFTI
private boolean m_IsNIFTI
boolean indicating whether this matrix is associated with a NIFTI image (special case handling)
-
m_IsQform
private boolean m_IsQform
If true, nifti matrix codes for a qform matrix If false, nifti matrix codes for a sform matrix Value has no effect if not a nifti matrix
-
m_Is2D
private boolean m_Is2D
Transform was constructed to transform 2D vectors, instead of 3D
-
MIPAV_DATA_FILE_V2_HEADER
private static final java.lang.String MIPAV_DATA_FILE_V2_HEADER
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TransMatrix
public TransMatrix(int dim)
Construct a transformation matrix.- Parameters:
dim
- should be 3 or 4 (square matrix)
-
TransMatrix
public TransMatrix(int dim, int id)
-
TransMatrix
public TransMatrix(int dim, int id, boolean is_nifti, boolean isQform)
-
TransMatrix
public TransMatrix(TransMatrix rkTM)
copy constructor.- Parameters:
rkTM
- matrix to copy
-
-
Method Detail
-
getDim
public int getDim()
Return dimension passed to constructor.- Returns:
- 3 for 2D transform, 4 for 3D transform.
-
clone
public TransMatrix clone()
- Overrides:
clone
in classjava.lang.Object
- Returns:
- deep copy of this.
-
Copy
public void Copy(TransMatrix rkTM)
copy, overwrite this.- Parameters:
rkTM
- matrix to copy
-
decodeMatrixString
public void decodeMatrixString(java.lang.String str)
Decodes the matrix from a string into the matrix array.- Parameters:
str
- Matrix represented as a string.
-
decomposeMatrix
public boolean decomposeMatrix(WildMagic.LibFoundation.Mathematics.Vector3f rotate, WildMagic.LibFoundation.Mathematics.Vector3f trans, WildMagic.LibFoundation.Mathematics.Vector3f scale, WildMagic.LibFoundation.Mathematics.Vector3f shear)
Decomposing a matrix into simple transformations TransMatrix transformation sequence: Scale(Sx, Sy, Sz)*ShearXY*ShearXZ*ShearYZ* RotateX*RotateY*RotateZ*Translate(tx, ty, tz) ( *Perspective(Px, Py, Pz, Pw), no longer supported)- Parameters:
rotate
- rotation about x, y, z axis, in radianstrans
- translationscale
- scale, for each dimensionshear
- shear.X is XY, shear.Y is XZ, shear.Z is YZ- Returns:
- true if decompose was successful.
-
isIdentity
public boolean isIdentity()
Reports whether transform is Identity transform, to within a small epsilon.- Returns:
- true iff identity
-
isNIFTI
public boolean isNIFTI()
Tells whether this matrix is associated with a NIFTI image this only matters when the matrix is being saved/when the composite matrix is being generated in MatrixHolder- Returns:
- is this a nifti matrix
-
setIsNIFTI
public void setIsNIFTI(boolean is_NIFTI)
Accessor that sets whether or not the matrix is a NIFTI matrix.- Parameters:
is_NIFTI
- val to set
-
isQform
public boolean isQform()
Tells whether a NIFTI matrix is a qform matrix or a sform matrix- Returns:
- true if qform, false if sform.
-
setIsQform
public void setIsQform(boolean is_Qform)
Accessor that sets whether a nifti matrix is a qform matrix or a sform matrix.- Parameters:
is_Qform
- val to set
-
readMatrix
public void readMatrix(java.io.RandomAccessFile raFile, boolean composite)
Reads transformation matrix to a text file.This method reads two formats MIPAV format
4 // number of rows in matrix 4 // number of cols in matrix 0.234 0.33 0.22 5.0 // matrix info separated by a space 0.234 0.33 0.22 10.0 // matrix info separated by a space 0.234 0.33 0.22 12.0 // matrix info separated by a space 0.0 0.0 0.0 1.0 // matrix info separated by a space.
Note the above is a homogenous transformation matrix
FSL or alternate format supported
0.234 0.33 0.22 5.0 // matrix info separated by 2 spaces 0.234 0.33 0.22 5.0 // matrix info separated by 2 spaces 0.234 0.33 0.22 5.0 // matrix info separated by 2 spaces 0 0 0 1 // matrix info separated by 2 spaces
also note integer values
- Parameters:
raFile
- random access file pointercomposite
- if true make a composite matrix of the by multipling this matrix with the one to be read from the file. If false replace this object matrix with a new matrix read from the file.
-
readMatrix
public void readMatrix(java.io.RandomAccessFile raFile, int[] interp, float[] oXres, float[] oYres, float[] oZres, int[] oXdim, int[] oYdim, int[] oZdim, boolean[] tVOI, boolean[] clip, boolean[] pad, boolean composite)
Deprecated.Reads transformation matrix to a text file.This method reads two formats MIPAV format
4 // number of rows in matrix 4 // number of cols in matrix 0.234 0.33 0.22 5.0 // matrix info separated by a space 0.234 0.33 0.22 10.0 // matrix info separated by a space 0.234 0.33 0.22 12.0 // matrix info separated by a space 0.0 0.0 0.0 1.0 // matrix info separated by a space.
Note the above is a homogenous transformation matrix
FSL or alternate format supported
0.234 0.33 0.22 5.0 // matrix info separated by 2 spaces 0.234 0.33 0.22 5.0 // matrix info separated by 2 spaces 0.234 0.33 0.22 5.0 // matrix info separated by 2 spaces 0 0 0 1 // matrix info separated by 2 spaces
also note integer values
- Parameters:
raFile
- random access file pointercomposite
- if true make a composite matrix of the by multipling this matrix with the one to be read from the file. If false replace this object matrix with a new matrix read from the file.
-
readLegacyFileParameters
private void readLegacyFileParameters(java.io.RandomAccessFile raFile, int[] interp, float[] oXres, float[] oYres, float[] oZres, int[] oXdim, int[] oYdim, int[] oZdim, boolean[] tVOI, boolean[] clip, boolean[] pad) throws java.io.IOException
- Throws:
java.io.IOException
-
readMatrix
public boolean readMatrix(java.io.RandomAccessFile raFile, int[] interp, float[] sourceXres, float[] sourceYres, float[] sourceZres, float[] targetXres, float[] targetYres, float[] targetZres, int[] sourceXdim, int[] sourceYdim, int[] sourceZdim, int[] targetXdim, int[] targetYdim, int[] targetZdim, boolean[] tVOI, boolean[] clip, boolean[] pad, boolean composite)
Reads transformation matrix to a text file.This method reads version 2 MIPAV matrix data files (including legacy versions of these files)
MIPAV Matrix Data File v2 rows = 4 // number of rows in matrix (r0..rows-1 matrix keys below) cols = 4 // number of cols in matrix r0 = 0.234 0.33 0.22 5.0 // matrix info separated by a space r1 = 0.234 0.33 0.22 10.0 // matrix info separated by a space r2 = 0.234 0.33 0.22 12.0 // matrix info separated by a space r3 = 0.0 0.0 0.0 1.0 // matrix info separated by a space. \n // newline interpolation = 0 // 0 for trilinear interpolation, 2 for nearest neighbor, 3 for cubic bspline, 4 for quadratic bspline sourceXres = 0.5 // source x resolution sourceYres = 0.5 // source y resolution sourceZres = 0.2 // source z resolution targetXres = 0.5 // target x resolution targetYres = 0.5 // target y resolution targetZres = 0.2 // target z resolution sourceXdim = 256 // source x dimension sourceYdim = 256 // source y dimension sourceZdim = 128 // source z dimension targetXdim = 256 // target x dimension targetYdim = 256 // target y dimension targetZdim = 128 // target z dimension voi = true // transformVOI (true or false) clip = false // clip (true or false) output image range is clipped to input image range pad = true // pad (true of false) output image is padded so that all of the original image is present
Note the above is a homogenous transformation matrix
FSL or alternate format supported
0.234 0.33 0.22 5.0 // matrix info separated by 2 spaces 0.234 0.33 0.22 5.0 // matrix info separated by 2 spaces 0.234 0.33 0.22 5.0 // matrix info separated by 2 spaces 0 0 0 1 // matrix info separated by 2 spaces
also note integer values
- Parameters:
raFile
- random access file pointercomposite
- if true make a composite matrix of the by multipling this matrix with the one to be read from the file. If false replace this object matrix with a new matrix read from the file.
-
isV2MatrixDataFile
public static boolean isV2MatrixDataFile(java.io.File f)
-
getProperty
private java.lang.String getProperty(java.util.Properties props, java.lang.String key) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getIntProperty
private int getIntProperty(java.util.Properties props, java.lang.String key) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getFloatProperty
private float getFloatProperty(java.util.Properties props, java.lang.String key) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getBooleanProperty
private boolean getBooleanProperty(java.util.Properties props, java.lang.String key) throws java.lang.Exception
- Throws:
java.lang.Exception
-
setIntProperty
private void setIntProperty(java.util.Properties props, java.lang.String key, int val)
-
setFloatProperty
private void setFloatProperty(java.util.Properties props, java.lang.String key, float val)
-
setBooleanProperty
private void setBooleanProperty(java.util.Properties props, java.lang.String key, boolean val)
-
readMultiMatrix
public static TransMatrix[] readMultiMatrix(java.io.RandomAccessFile raFile)
Reads a file containing a list of multiple TransMatrix values. Returns the new TransMatrix array. Format is rows (int) columns (int) Matrix line 1 Matrix line 2 Matrix line 3 Matrix line 4 (optional) new line- Parameters:
raFile
-- Returns:
-
readAfniMatrix
public static TransMatrix readAfniMatrix(java.io.RandomAccessFile raFile)
Reads AFNI-style matrix and does processing to generate TransMatrix result
-
createMatrixFromAfni
private static TransMatrix createMatrixFromAfni(java.util.ArrayList<java.lang.Float> d)
-
saveMatrix
public void saveMatrix(java.lang.String fileName)
Saves transformation matrix to a text file MIPAV format- Parameters:
fileName
- - file name, including the path- See Also:
saveMatrix(java.io.RandomAccessFile)
-
saveMatrix
public void saveMatrix(java.lang.String fileName, java.lang.String message)
Saves transformation matrix to a text file MIPAV format- Parameters:
fileName
- - file name, including the pathmessage
- String, may be null for no message.- See Also:
saveMatrix(java.io.RandomAccessFile,java.lang.String)
-
saveMatrix
public void saveMatrix(java.io.RandomAccessFile raFile)
Saves transformation matrix to a text file MIPAV format. The format is:4 // number of rows in matrix 4 // number of cols in matrix 0.234 0.33 0.22 5.0 // matrix info separated by a space 0.234 0.33 0.22 10.0 // matrix info separated by a space 0.234 0.33 0.22 12.0 // matrix info separated by a space 0.0 0.0 0.0 1.0 // matrix info separated by a space.
- Parameters:
raFile
- random access file pointer- See Also:
saveMatrix(java.io.RandomAccessFile,java.lang.String)
-
saveMatrix
public void saveMatrix(java.io.RandomAccessFile raFile, java.lang.String message)
Saves transformation matrix to a text file MIPAV format. The format is:4 // number of rows in matrix 4 // number of cols in matrix 0.234 0.33 0.22 5.0 // matrix info separated by a space 0.234 0.33 0.22 10.0 // matrix info separated by a space 0.234 0.33 0.22 12.0 // matrix info separated by a space 0.0 0.0 0.0 1.0 // matrix info separated by a space.
- Parameters:
raFile
- random access file pointermessage
- String, may be null for no message.
-
saveMatrix
public void saveMatrix(java.lang.String fileName, int interp, float oXres, float oYres, float oZres, int oXdim, int oYdim, int oZdim, boolean tVOI, boolean clip, boolean pad, java.lang.String message)
-
saveMatrix
public void saveMatrix(java.lang.String fileName, int interp, float sourceXres, float sourceYres, float sourceZres, float targetXres, float targetYres, float targetZres, int sourceXdim, int sourceYdim, int sourceZdim, int targetXdim, int targetYdim, int targetZdim, boolean tVOI, boolean clip, boolean pad, java.lang.String message)
-
saveMatrix
public void saveMatrix(java.io.RandomAccessFile raFile, int interp, float oXres, float oYres, float oZres, int oXdim, int oYdim, int oZdim, boolean tVOI, boolean clip, boolean pad, java.lang.String message)
Saves transformation matrix to a text file MIPAV format4 // number of rows in matrix 4 // number of cols in matrix 0.234 0.33 0.22 5.0 // matrix info separated by a space 0.234 0.33 0.22 10.0 // matrix info separated by a space 0.234 0.33 0.22 12.0 // matrix info separated by a space 0.0 0.0 0.0 1.0 // matrix info separated by a space. \n // newline Have transform parameters 0 // 0 for trilinear interpolation, 2 for nearest neighbor, 3 for cubic bspline, 4 for quadratic bspline 0.5 // output x resolution 0.5 // output y resolution 0.2 // output z resolution 256 // output x dimension 256 // output y dimension 128 // output z dimension true // transformVOI (true or false) false // clip (true or false) output image range is clipped to input image range true // pad (true of false) output image is padded so that all of the original image is present
- Parameters:
raFile
- random access file pointerinterp
-oXres
-oYres
-oZres
-oXdim
-oYdim
-oZdim
-tVOI
-clip
-pad
-message
- String, may be null for no message.
-
saveMatrix
public void saveMatrix(java.io.RandomAccessFile raFile, int interp, float sourceXres, float sourceYres, float sourceZres, float targetXres, float targetYres, float targetZres, int sourceXdim, int sourceYdim, int sourceZdim, int targetXdim, int targetYdim, int targetZdim, boolean tVOI, boolean clip, boolean pad, java.lang.String message)
Saves transformation matrix to a text file MIPAV format. The format is an enhanced format with format version as well as name, value pairs. Matrix read functions are aware of both legacy and enhanced formats and will be able to read both formats properly.MIPAV Matrix Data File v2 rows = 4 // number of rows in matrix (r0..rows-1 matrix keys below) cols = 4 // number of cols in matrix r0 = 0.234 0.33 0.22 5.0 // matrix info separated by a space r1 = 0.234 0.33 0.22 10.0 // matrix info separated by a space r2 = 0.234 0.33 0.22 12.0 // matrix info separated by a space r3 = 0.0 0.0 0.0 1.0 // matrix info separated by a space. interpolation = 0 // 0 for trilinear interpolation, 2 for nearest neighbor, 3 for cubic bspline, 4 for quadratic bspline sourceXres = 0.5 // source x resolution sourceYres = 0.5 // source y resolution sourceZres = 0.2 // source z resolution targetXres = 0.5 // target x resolution targetYres = 0.5 // target y resolution targetZres = 0.2 // target z resolution sourceXdim = 256 // source x dimension sourceYdim = 256 // source y dimension sourceZdim = 128 // source z dimension targetXdim = 256 // target x dimension targetYdim = 256 // target y dimension targetZdim = 128 // target z dimension voi = true // transformVOI (true or false) clip = false // clip (true or false) output image range is clipped to input image range pad = true // pad (true of false) output image is padded so that all of the original image is present
-
saveXFMMatrix
public void saveXFMMatrix(java.io.RandomAccessFile raFile)
Saves transformation matrix to McGill XFM format- Parameters:
raFile
- random access file pointer
-
copyMatrix
public void copyMatrix(double[][] newMatrix)
Copies provided transformation matrix.- Parameters:
newMatrix
- 2D array to copy, 3x3 or 4x4
-
getColumn
public void getColumn(int r, double[] column)
Copy our data into the provided double array- Parameters:
r
- row to copycolumn
- place to put column data, length 3 or 4
-
set
public TransMatrix set(int r, int c, double val)
-
setMatrix
public void setMatrix(int i0, int i1, int j0, int j1, double[][] X)
Set a submatrix. Borrowed from Jama, useful for copying a Jama matrix M by passing in M.getArray() for param X- Parameters:
i0
- Initial row indexi1
- Final row indexj0
- Initial column indexj1
- Final column indexX
- A(i0:i1,j0:j1)- Throws:
java.lang.ArrayIndexOutOfBoundsException
- Submatrix indices
-
setMatrix
public void setMatrix(double[][] X)
Set a submatrix. Borrowed from Jama, useful for copying a Jama matrix M by passing in M.getArray() for param X- Parameters:
X
- A(i0:i1,j0:j1)- Throws:
java.lang.ArrayIndexOutOfBoundsException
- Submatrix indices
-
setRotate
public void setRotate(double theta)
Sets the rotation (2D) of transformation matrix.- Parameters:
theta
- angle of rotation, in degrees
-
setRotate
public void setRotate(WildMagic.LibFoundation.Mathematics.Vector3f alpha, WildMagic.LibFoundation.Mathematics.Vector3f beta, WildMagic.LibFoundation.Mathematics.Vector3f gamma)
Sets rotation (3D) of transformation matrix.- Parameters:
alpha
- row0beta
- row1gamma
- row2
-
setRotate
public void setRotate(double thetaX, double thetaY, double thetaZ, int degreeORradian)
Sets rotation (3D) of transformation matrix.- Parameters:
thetaX
- angle (degrees or radians) of rotation about the X axis;thetaY
- angle (degrees or radians) of rotation about the Y axis;thetaZ
- angle (degrees or radians) of rotation about the Z axis;degreeORradian
- DEGREES or RADIANS
-
setSkew
public void setSkew(double x, double y)
Sets skew part of 2D matrix.- Parameters:
x
- Skew x parameter.y
- Skew y parameter.
-
setSkew
public void setSkew(double x, double y, double z)
Sets the skew parts of 3D matrix (4D Homogenous).- Parameters:
x
- x skewy
- y skewz
- z skew
-
setTransform
public void setTransform(double tX, double tY, double r)
Sets 2D transformation matrix.- Parameters:
tX
- x translationtY
- y translationr
- rotation angle in degrees, about unseen z axis
-
setTransform
public void setTransform(double tX, double tY, double tZ, double rX, double rY, double rZ)
Sets the 3D transformation matrix [4x4].- Parameters:
tX
- x translationtY
- y translationtZ
- z translationrX
- x rotation angle in degreesrY
- y rotation angle in degreesrZ
- z rotation angle in degrees
-
setTransform
public void setTransform(double tX, double tY, double tZ, double rX, double rY, double rZ, double sX, double sY, double sZ, double skX, double skY, double skZ)
Sets the 3D transformation matrix [4x4].- Parameters:
tX
- x translationtY
- y translationtZ
- z translationrX
- x rotation angle in degreesrY
- y rotation angle in degreesrZ
- z rotation angle in degreessX
- x scalesY
- y scalesZ
- z scaleskX
- x skewskY
- y skewskZ
- z skew
-
setTranslate
public void setTranslate(double x, double y)
Sets translation parts of 2D matrix.- Parameters:
x
- x translationy
- y translation
-
setTranslate
public void setTranslate(double x, double y, double z)
Sets the translation parts of 3D matrix (4D Homogenous).- Parameters:
x
- x translationy
- y translationz
- z translation
-
setZoom
public void setZoom(double sx, double sy)
Sets the zoom parts of 2D matrix.- Parameters:
sx
- zoom in the x coordinatesy
- zoom in the y coordinate
-
setZoom
public void setZoom(double sx, double sy, double sz)
Sets the zoom parts of 3D matrix.- Parameters:
sx
- zoom in the x coordinatesy
- zoom in the y coordinatesz
- zoom in the z coordinate
-
toDialogString
public java.lang.String toDialogString()
Produces a string of the matrix values, rows separated by tabs.- Returns:
- formatted string
-
transform
public final java.awt.Polygon transform(java.awt.Polygon gon)
Tranforms a Polygon (2D).- Parameters:
gon
- input polygon- Returns:
- returns new transformed Polygon
-
transformAsPoint2Df
public final void transformAsPoint2Df(WildMagic.LibFoundation.Mathematics.Vector2f[] vects, WildMagic.LibFoundation.Mathematics.Vector2f[] tVects)
Takes an array of Point2Df 2D vectors and multiplies them with the 2d transformation matrix.- Parameters:
vects
- float vectors to be transformedtVects
- transformed vectors
-
transformAsVector3Df
public final void transformAsVector3Df(WildMagic.LibFoundation.Mathematics.Vector3f[] vects, WildMagic.LibFoundation.Mathematics.Vector3f[] tVects)
Takes an array of Vector3Df 2D vectors and multiplies them with the 2d transformation matrix.- Parameters:
vects
- float vectors to be transformedtVects
- transformed vectors
-
transformAsVector3Df
public final void transformAsVector3Df(VOIBase vects, WildMagic.LibFoundation.Mathematics.Vector3f[] tVects)
Takes an array of Vector3Df 2D vectors and multiplies them with the 2d transformation matrix.- Parameters:
vects
- float vectors to be transformedtVects
- transformed vectors
-
transform
public final void transform(double[] pt, double[] tPt)
Takes a 3D or 2D point (as a double array) and premultiplies it by the 3D transformation matrix.- Parameters:
pt
- coordinate to be transformedtPt
- transformed point
-
transform
public final void transform(float[] pt, float[] tPt)
Takes a 3D point, as a float array, and premultiplies it by the 3D transformation matrix.- Parameters:
pt
- coordinate to be transformedtPt
- the transformed point
-
transformAsPoint3Df
public final void transformAsPoint3Df(WildMagic.LibFoundation.Mathematics.Vector3f pt, WildMagic.LibFoundation.Mathematics.Vector3f tPt)
Takes a Point3Df 3D point and multiplies it by the 3D transformation matrix.- Parameters:
pt
- 3D float point to be transformedtPt
- transformed point
-
transform
public final void transform(double x, double y, double[] tPt)
Takes double components of a 2D point and premultiplies it by the 2d transformation matrix.- Parameters:
x
- x coordinate to be transformdy
- y coordinate to be transformdtPt
- transformed point
-
transform
public final void transform(float x, float y, float[] tPt)
Takes float components of a 2D point and premultiplies it by the 2d transformation matrix.- Parameters:
x
- x coordinate to be transformedy
- y coordinate to be transformedtPt
- transformed point
-
transform
public final void transform(double x, double y, double z, double[] tPt)
Takes the double components of a 3D point and premultiplies it by the 3D transformation matrix.- Parameters:
x
- x coordinate to be transformedy
- y coordinate to be transformedz
- z coordinate to be transformedtPt
- transformed point
-
transform
public final void transform(float x, float y, float z, float[] tPt)
Takes the float components of a 3D point and premultiplies it by the 3D transformation matrix.- Parameters:
x
- x coordinate to be transformedy
- y coordinate to be transformedz
- z coordinate to be transformedtPt
- the transformed point
-
getTransformID
public final int getTransformID()
Returns the transform ID associated with the matrix.- Returns:
- int transform ID
-
getTransformIDFromStr
public static int getTransformIDFromStr(java.lang.String s)
Returns the transform ID associated with a string.- Parameters:
s
- String to test- Returns:
- data type
-
getTransformIDStr
public static java.lang.String[] getTransformIDStr()
Return the list of transform ID strings (for edit attributes combo box.- Returns:
- string [] of transform ID
-
getTransformIDStr
public static java.lang.String getTransformIDStr(int m)
Return the string associated with the matrix transform ID.- Parameters:
m
- transform ID- Returns:
- the string associated with the transform ID
-
setTransformID
public void setTransformID(int t_id)
Sets the transform ID for the matrix.- Parameters:
t_id
- transform ID
-
toString
public java.lang.String toString()
ToString method that includes the matrix printout as well as the transform ID of the transmatrix- Overrides:
toString
in classWildMagic.LibFoundation.Mathematics.Matrix4f
- Returns:
- printout
-
decodeLine
private void decodeLine(java.io.RandomAccessFile raFile, int row, WildMagic.LibFoundation.Mathematics.Matrix4f matrix)
Decodes the line in the matrix file.- Parameters:
raFile
- file pointerrow
- row reference to store transformation matrixmatrix
- the matrix where the data is to be stored
-
decodeLine
private void decodeLine(java.lang.String str, int row, WildMagic.LibFoundation.Mathematics.Matrix4f matrix)
Decodes the line in the matrix file.- Parameters:
raFile
- file pointerrow
- row reference to store transformation matrixmatrix
- the matrix where the data is to be stored
-
decodeLine
private static void decodeLine(java.io.RandomAccessFile raFile, int row, WildMagic.LibFoundation.Mathematics.Matrix4f matrix, int dim)
Reads a row of the matrix from file- Parameters:
raFile
- file containing matrix datarow
- rowmatrix
- matrixdim
- column dimension
-
Inverse
public void Inverse()
Matrix inversion that replaces this objects matrix with an inverted matrix. Special handling for 2D vs 3D cases.
-
matrixToString
public java.lang.String matrixToString(int w, int d)
Produces a string of the matrix values.- Parameters:
w
- Column width.d
- Number of digits after the decimal.- Returns:
- String containing the values from the matrix.
-
-