Search in sources :

Example 1 with AffineTransform2D

use of org.apache.sis.internal.referencing.j2d.AffineTransform2D in project sis by apache.

the class ConcatenatedTransformTest method testGeneric.

/**
 * Tests the concatenation of two affine transforms than can not be represented as a
 * {@link ConcatenatedTransformDirect}. The slower {@link ConcatenatedTransform} shall be used.
 *
 * @throws FactoryException if an error occurred while creating the math transform to test.
 * @throws TransformException if an error occurred while transforming the test coordinate.
 */
@Test
@org.junit.Ignore("Missing implementation of DimensionFilter.")
public void testGeneric() throws FactoryException, TransformException {
    // MathTransforms.dimensionFilter(4, new int[] {1,3});
    final MathTransform first = null;
    // scale(0.5, 0.25);
    final AffineTransform2D second = new AffineTransform2D(0.5, 0, 0, 0.25, 0, 0);
    transform = new ConcatenatedTransform(first, second);
    isInverseTransformSupported = false;
    validate();
    final double[] source = generateRandomCoordinates(CoordinateDomain.PROJECTED, 0);
    // Going from 4 to 2 dimensions.
    final double[] target = new double[source.length / 2];
    first.transform(source, 0, target, 0, target.length / 2);
    second.transform(target, 0, target, 0, target.length / 2);
    verifyTransform(source, target);
    // Optimized case.
    transform = ConcatenatedTransform.create(first, second, null);
    assertInstanceOf("Expected optimized concatenation through matrix multiplication.", ProjectiveTransform.class, transform);
    validate();
    verifyTransform(source, target);
}
Also used : MathTransform(org.opengis.referencing.operation.MathTransform) AffineTransform2D(org.apache.sis.internal.referencing.j2d.AffineTransform2D) Test(org.junit.Test)

Example 2 with AffineTransform2D

use of org.apache.sis.internal.referencing.j2d.AffineTransform2D in project sis by apache.

the class ConcatenatedTransformTest method testDirect2D.

/**
 * Tests the concatenation of two affine transforms than can be represented
 * as a {@link ConcatenatedTransformDirect2D}.
 *
 * @throws TransformException if an error occurred while transforming the test coordinate.
 */
@Test
public void testDirect2D() throws TransformException {
    // translate(2, 4)
    final AffineTransform2D first = new AffineTransform2D(1, 0, 0, 1, 2.00, 4.00);
    // translate(0.25, 0.75);
    final AffineTransform2D second = new AffineTransform2D(1, 0, 0, 1, 0.25, 0.75);
    // Direct for 2D case.
    tolerance = 1E-10;
    transform = new ConcatenatedTransformDirect2D(first, second);
    validate();
    final double[] source = generateRandomCoordinates(CoordinateDomain.PROJECTED, 0);
    final double[] target = new double[source.length];
    first.transform(source, 0, target, 0, source.length / 2);
    second.transform(target, 0, target, 0, target.length / 2);
    verifyTransform(source, target);
    // Non-direct for 2D case.
    transform = new ConcatenatedTransform2D(first, second);
    validate();
    verifyTransform(source, target);
    // Direct for general case - can't be validated.
    transform = new ConcatenatedTransformDirect(first, second);
    verifyTransform(source, target);
    // Most general case - can't be validated.
    transform = new ConcatenatedTransform(first, second);
    verifyTransform(source, target);
    // Optimized case.
    transform = MathTransforms.concatenate(first, second);
    assertInstanceOf("Expected optimized concatenation through matrix multiplication.", AffineTransform2D.class, transform);
    validate();
    verifyTransform(source, target);
}
Also used : AffineTransform2D(org.apache.sis.internal.referencing.j2d.AffineTransform2D) Test(org.junit.Test)

Example 3 with AffineTransform2D

use of org.apache.sis.internal.referencing.j2d.AffineTransform2D 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();
}
Also used : ExtendedPrecisionMatrix(org.apache.sis.internal.referencing.ExtendedPrecisionMatrix) AffineTransform2D(org.apache.sis.internal.referencing.j2d.AffineTransform2D)

Aggregations

AffineTransform2D (org.apache.sis.internal.referencing.j2d.AffineTransform2D)3 Test (org.junit.Test)2 ExtendedPrecisionMatrix (org.apache.sis.internal.referencing.ExtendedPrecisionMatrix)1 MathTransform (org.opengis.referencing.operation.MathTransform)1