use of org.apache.sis.internal.referencing.ExtendedPrecisionMatrix in project sis by apache.
the class ScaleTransformTest method testExtendedPrecision.
/**
* Verifies that {@link ScaleTransform} stores the error terms when they exist.
*/
@Test
@DependsOnMethod("testConstantDimension")
public void testExtendedPrecision() {
final Number O = 0;
final Number l = 1;
final DoubleDouble r = DoubleDouble.createDegreesToRadians();
final MatrixSIS matrix = Matrices.create(4, 4, new Number[] { r, O, O, O, O, r, O, O, O, O, l, O, O, O, O, l });
final double[] elements = ((ExtendedPrecisionMatrix) matrix).getExtendedElements();
assertTrue(r.value > r.error);
// Paranoiac checks for making sure that next assertion will test something.
assertFalse(r.error == 0);
assertArrayEquals(new double[] { // Paranoiac check for making sure that getExtendedElements() is not broken.
r.value, 0, 0, 0, 0, r.value, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, r.error, 0, 0, 0, 0, r.error, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, elements, 0);
final ScaleTransform tr = new ScaleTransform(4, 4, elements);
assertEquals("sourceDimensions", 3, tr.getSourceDimensions());
assertEquals("targetDimensions", 3, tr.getTargetDimensions());
Assert.assertMatrixEquals("matrix", matrix, tr.getMatrix(), 0.0);
assertArrayEquals("elements", elements, tr.getExtendedElements(), 0.0);
transform = tr;
validate();
}
use of org.apache.sis.internal.referencing.ExtendedPrecisionMatrix in project sis by apache.
the class MatrixSIS method setMatrix.
/**
* Sets this matrix to the values of another matrix.
* The given matrix must have the same size.
*
* @param matrix the matrix to copy.
* @throws MismatchedMatrixSizeException if the given matrix has a different size than this matrix.
*
* @since 0.7
*/
public void setMatrix(final Matrix matrix) throws MismatchedMatrixSizeException {
ArgumentChecks.ensureNonNull("matrix", matrix);
final int numRow = getNumRow();
final int numCol = getNumCol();
ensureSizeMatch(numRow, numCol, matrix);
final int count = numRow * numCol;
final double[] elements;
/*
* If both matrices use extended precision, the elements array will have twice the expected length
* with the matrix values in the first half and the error terms in the second half. If we want to
* preserve the extended precision, we have to transfer the values between the two matrices with a
* DoubleDouble object.
*/
if (isExtendedPrecision() && matrix instanceof ExtendedPrecisionMatrix) {
elements = ((ExtendedPrecisionMatrix) matrix).getExtendedElements();
if (elements.length > count) {
final DoubleDouble t = new DoubleDouble();
for (int i = 0; i < count; i++) {
t.value = elements[i];
t.error = elements[i + count];
set(i / numCol, i % numCol, t);
}
return;
}
} else {
// Fallback for matrices that do not use extended precision.
elements = new double[count];
getElements(matrix, numRow, numCol, elements);
}
setElements(elements);
}
use of org.apache.sis.internal.referencing.ExtendedPrecisionMatrix in project sis by apache.
the class MathTransforms method linear.
/**
* Creates an arbitrary linear transform from the specified matrix. Usually the matrix
* {@linkplain org.apache.sis.referencing.operation.matrix.MatrixSIS#isAffine() is affine},
* but this is not mandatory. Non-affine matrix will define a projective transform.
*
* <p>If the transform input dimension is {@code M}, and output dimension is {@code N},
* then the given matrix shall have size {@code [N+1][M+1]}.
* The +1 in the matrix dimensions allows the matrix to do a shift, as well as a rotation.
* The {@code [M][j]} element of the matrix will be the <var>j</var>'th ordinate of the moved origin.</p>
*
* @param matrix the matrix used to define the linear transform.
* @return the linear (usually affine) transform.
*
* @see #getMatrix(MathTransform)
* @see DefaultMathTransformFactory#createAffineTransform(Matrix)
*/
public static LinearTransform linear(final Matrix matrix) {
ArgumentChecks.ensureNonNull("matrix", matrix);
final int sourceDimension = matrix.getNumCol() - 1;
final int targetDimension = matrix.getNumRow() - 1;
if (sourceDimension == targetDimension) {
if (matrix.isIdentity()) {
return identity(sourceDimension);
}
if (Matrices.isAffine(matrix)) {
switch(sourceDimension) {
case 1:
{
return linear(matrix.getElement(0, 0), matrix.getElement(0, 1));
}
case 2:
{
if (matrix instanceof ExtendedPrecisionMatrix) {
return new AffineTransform2D(((ExtendedPrecisionMatrix) matrix).getExtendedElements());
} else {
return new AffineTransform2D(matrix.getElement(0, 0), matrix.getElement(1, 0), matrix.getElement(0, 1), matrix.getElement(1, 1), matrix.getElement(0, 2), matrix.getElement(1, 2));
}
}
}
} else if (sourceDimension == 2) {
return new ProjectiveTransform2D(matrix);
}
}
final LinearTransform candidate = CopyTransform.create(matrix);
if (candidate != null) {
return candidate;
}
return new ProjectiveTransform(matrix).optimize();
}
Aggregations