public abstract class MatrixSIS extends Object implements Matrix, LenientComparable, Cloneable, Serializable
Matrix able to perform some operations of interest to Spatial Information Systems (SIS).
This class completes the GeoAPI Matrix interface with some operations used by sis-referencing.
It is not a MatrixSIS goal to provide all possible Matrix operations, as there is too many of them.
This class focuses on:
Matrices,
Serialized FormDefined in the sis-referencing module
| Modifier | Constructor and Description |
|---|---|
protected |
MatrixSIS()
For sub-class constructors.
|
| Modifier and Type | Method and Description |
|---|---|
static MatrixSIS |
castOrCopy(Matrix matrix)
Casts or copies the given matrix to a SIS implementation.
|
MatrixSIS |
clone()
Returns a clone of this matrix.
|
void |
convertAfter(int tgtDim,
Number scale,
Number offset)
Assuming that this matrix represents an affine transform, pre-concatenates a scale and a translation on the
given dimension.
|
void |
convertBefore(int srcDim,
Number scale,
Number offset)
Assuming that this matrix represents an affine transform, concatenates a scale and a translation on the
given dimension.
|
boolean |
equals(Matrix matrix,
double tolerance)
Compares the given matrices for equality, using the given absolute tolerance threshold.
|
boolean |
equals(Object object)
Returns
true if the specified object is of the same class than this matrix and
all of the data members are equal to the corresponding data members in this matrix. |
boolean |
equals(Object object,
ComparisonMode mode)
Compares this matrix with the given object for equality.
|
abstract double |
getElement(int row,
int column)
Retrieves the value at the specified row and column of this matrix.
|
double[] |
getElements()
Returns a copy of all matrix elements in a flat, row-major (column indices vary fastest) array.
|
Number |
getNumber(int row,
int column)
Retrieves the value at the specified row and column of this matrix, wrapped in a
Number. |
int |
hashCode()
Returns a hash code value based on the data values in this matrix.
|
MatrixSIS |
inverse()
Returns the inverse of this matrix.
|
boolean |
isAffine()
Returns
true if this matrix represents an affine transform. |
abstract boolean |
isIdentity()
Returns
true if this matrix is an identity matrix. |
double[] |
multiply(double[] vector)
Returns a new vector which is the result of multiplying this matrix with the specified vector.
|
MatrixSIS |
multiply(Matrix matrix)
Returns a new matrix which is the result of multiplying this matrix with the specified one.
|
void |
normalizeColumns()
Normalizes all columns in-place.
|
MatrixSIS |
removeColumns(int lower,
int upper)
Returns a new matrix with the same elements than this matrix except for the specified columns.
|
MatrixSIS |
removeRows(int lower,
int upper)
Returns a new matrix with the same elements than this matrix except for the specified rows.
|
abstract void |
setElements(double[] elements)
Sets all matrix elements from a flat, row-major (column indices vary fastest) array.
|
void |
setMatrix(Matrix matrix)
Sets this matrix to the values of another matrix.
|
void |
setNumber(int row,
int column,
Number value)
Modifies the value at the specified row and column of this matrix.
|
MatrixSIS |
solve(Matrix matrix)
Returns the value of U which solves
this × U = matrix. |
String |
toString()
Returns a unlocalized string representation of this matrix.
|
abstract void |
transpose()
Sets the value of this matrix to its transpose.
|
getNumCol, getNumRow, setElementpublic static MatrixSIS castOrCopy(Matrix matrix)
matrix is already
an instance of MatrixSIS, then it is returned unchanged. Otherwise all elements
are copied in a new MatrixSIS object.matrix - the matrix to cast or copy, or null.null argument),
or a copy of the given matrix otherwise.Matrices.copy(Matrix)public Number getNumber(int row, int column)
Number.
The Number type depends on the matrix accuracy.row - the row index, from 0 inclusive to Matrix.getNumRow() exclusive.column - the column index, from 0 inclusive to Matrix.getNumCol() exclusive.public void setNumber(int row,
int column,
Number value)
getNumber(int, int).row - the row index, from 0 inclusive to Matrix.getNumRow() exclusive.column - the column index, from 0 inclusive to Matrix.getNumCol() exclusive.value - the new matrix element value.Matrix.setElement(int, int, double)public abstract double getElement(int row,
int column)
getElement in interface Matrixrow - the row index, from 0 inclusive to Matrix.getNumRow() exclusive.column - the column index, from 0 inclusive to Matrix.getNumCol() exclusive.public double[] getElements()
Matrix.getNumRow() * Matrix.getNumCol().public abstract void setElements(double[] elements)
Matrix.getNumRow() * Matrix.getNumCol().elements - The new matrix elements in a row-major array.IllegalArgumentException - if the given array does not have the expected length.UnsupportedOperationException - if this matrix is unmodifiable.Matrices.create(int, int, double[])public void setMatrix(Matrix matrix) throws MismatchedMatrixSizeException
matrix - the matrix to copy.MismatchedMatrixSizeException - if the given matrix has a different size than this matrix.public boolean isAffine()
true if this matrix represents an affine transform.
A transform is affine if the matrix is square and its last row contains
only zeros, except in the last column which contains 1.true if this matrix represents an affine transform.Matrices.isAffine(Matrix),
LinearTransform.isAffine()public abstract boolean isIdentity()
true if this matrix is an identity matrix.
This method is equivalent to the following code, except that it is potentially more efficient:
return Matrices.isIdentity(this, 0.0);
isIdentity in interface Matrixtrue if this matrix is an identity matrix.Matrices.isIdentity(Matrix, double),
AffineTransform.isIdentity()public abstract void transpose()
UnsupportedOperationException - if this matrix is unmodifiable.public void normalizeColumns()
This method is useful when the matrix is a transform derivative. In such matrix, each column is a vector representing the displacement in target space when an ordinate in the source space is increased by one. Invoking this method turns those vectors into unitary vectors, which is useful for forming the basis of a new coordinate system.
UnsupportedOperationException - if this matrix is unmodifiable.public void convertBefore(int srcDim,
Number scale,
Number offset)
ordinates[srcDim] = ordinates[srcDim] * scale + offset, then apply the original matrix.
AffineTransform methodsAffineTransform, then invoking this method would
be equivalent to invoke the following AffineTransform methods in the order shown below:
MatrixSIS method |
AffineTransform methods |
|---|---|
concatenate(0, scale, offset) |
at.translate(offset, 0);
at.scale(scale, 1); |
concatenate(1, scale, offset) |
at.translate(0, offset);
at.scale(1, scale); |
srcDim - the dimension of the ordinate to rescale in the source coordinates.scale - the amount by which to multiply the source ordinate value before to apply the transform, or null if none.offset - the amount by which to translate the source ordinate value before to apply the transform, or null if none.UnsupportedOperationException - if this matrix is unmodifiable.AffineTransform.concatenate(AffineTransform)public void convertAfter(int tgtDim,
Number scale,
Number offset)
ordinates[tgtDim] = ordinates[tgtDim] * scale + offset.tgtDim - the dimension of the ordinate to rescale in the target coordinates.scale - the amount by which to multiply the target ordinate value after this transform, or null if none.offset - the amount by which to translate the target ordinate value after this transform, or null if none.UnsupportedOperationException - if this matrix is unmodifiable.AffineTransform.preConcatenate(AffineTransform)public MatrixSIS multiply(Matrix matrix) throws MismatchedMatrixSizeException
this × matrix.
Matrix.multiply(other) is equivalent to
AffineTransform.concatenate(other):
first transforms by the supplied transform and then transform the result by the original transform.matrix - the matrix to multiply to this matrix.this × matrix.MismatchedMatrixSizeException - if the number of rows in the given matrix is not equals to the
number of columns in this matrix.public double[] multiply(double[] vector)
this × vector. The length of the given vector must be
equal to the number of columns in this matrix, and the length of the returned vector will be
equal to the number of rows in this matrix.
Matrix.multiply(vector) is related to
AffineTransform.transform(…)
except that the last vector number is implicitly 1 in AffineTransform operations.
While this multiply(double[]) method could be used for coordinate transformation, it is not its purpose.
This method is designed for occasional uses when accuracy is more important than performance.vector - the vector to multiply to this matrix.this × vector.MismatchedMatrixSizeException - if the length of the given vector is not equals to the
number of columns in this matrix.public MatrixSIS solve(Matrix matrix) throws MismatchedMatrixSizeException, NoninvertibleMatrixException
this × U = matrix.
This is equivalent to first computing the inverse of this, then multiplying the result
by the given matrix.matrix - the matrix to solve.this × U = matrix.MismatchedMatrixSizeException - if the number of rows in the given matrix is not equals
to the number of columns in this matrix.NoninvertibleMatrixException - if this matrix is not invertible.public MatrixSIS inverse() throws NoninvertibleMatrixException
NoninvertibleMatrixException - if this matrix is not invertible.AffineTransform.createInverse()public MatrixSIS removeRows(int lower, int upper)
lower - index of the first row to remove (inclusive).upper - index after the last row to remove (exclusive).public MatrixSIS removeColumns(int lower, int upper)
lower - index of the first column to remove (inclusive).upper - index after the last column to remove (exclusive).public int hashCode()
public boolean equals(Object object)
true if the specified object is of the same class than this matrix and
all of the data members are equal to the corresponding data members in this matrix.equals in interface LenientComparableequals in class Objectobject - the object to compare with this matrix for equality.true if the given object is equal to this matrix.ComparisonMode.STRICTpublic boolean equals(Matrix matrix, double tolerance)
The matrix elements are compared as below:
Double.NaN values are considered equals to all other NaN values.matrix - the matrix to compare.tolerance - the tolerance value.true if this matrix is close enough to the given matrix given the tolerance value.Matrices.equals(Matrix, Matrix, double, boolean)public boolean equals(Object object, ComparisonMode mode)
mode argument:
STRICT:
the two matrices must be of the same class, have the same size and the same element values.BY_CONTRACT:
the two matrices must have the same size and the same element values,
but are not required to be the same implementation class (any Matrix is okay).IGNORE_METADATA: same as BY_CONTRACT.
APPROXIMATIVE:
the two matrices must have the same size, but the element values can differ up to some threshold.
The threshold value is determined empirically and may change in any future SIS versions.equals in interface LenientComparableobject - the object to compare to this.mode - the strictness level of the comparison.true if both objects are equal.Matrices.equals(Matrix, Matrix, ComparisonMode)public MatrixSIS clone()
clone in interface Matrixclone in class ObjectMatrices.copy(Matrix)public String toString()
toString in class ObjectMatrices.toString(Matrix)Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.