Search in sources :

Example 1 with MathTransform1D

use of org.opengis.referencing.operation.MathTransform1D in project sis by apache.

the class ExponentialTransform1DTest method testAffinePreConcatenation.

/**
 * Implementation of {@link #testAffinePreConcatenation()} for the given base.
 */
private void testAffinePreConcatenation(final double base) throws TransformException {
    transform = MathTransforms.concatenate(LinearTransform1D.create(C1, C0), ExponentialTransform1D.create(base, SCALE));
    run(ExponentialTransform1D.class, base, SCALE, true, false);
    /*
         * Find back the original linear coefficients as documented in the ExponentialTransform1D class javadoc.
         */
    final double offset = -log(SCALE) / log(base);
    final MathTransform1D log = LogarithmicTransform1D.create(base, offset);
    transform = (LinearTransform1D) MathTransforms.concatenate(transform, log);
    assertEquals("C1", C1, ((LinearTransform1D) transform).scale, EPS);
    assertEquals("C0", C0, ((LinearTransform1D) transform).offset, EPS);
}
Also used : MathTransform1D(org.opengis.referencing.operation.MathTransform1D)

Example 2 with MathTransform1D

use of org.opengis.referencing.operation.MathTransform1D in project sis by apache.

the class LinearInterpolator1DTest method verifyConsistency.

/**
 * Transforms point and verifies that the result is consistent with the inverse transform and the derivative.
 */
private void verifyConsistency(final double min, final double max, final long randomSeed) throws TransformException {
    transform = LinearInterpolator1D.create(preimage, values);
    tolerance = 1E-10;
    derivativeDeltas = new double[] { 0.1 };
    /*
         * Convert a x value to y value, then back to x.
         * This code is provided mostly as a convenience place where to step into with a debugger.
         */
    if (isInverseTransformSupported) {
        final double xm = (min + max) / 2;
        final double ym = ((MathTransform1D) transform).transform(xm);
        assertEquals(xm, ((MathTransform1D) transform.inverse()).transform(ym), tolerance);
    }
    /*
         * The actual test: 100 random values, test all transform methods
         * (including those working on arrays), verify consistency and derivatives.
         */
    verifyInDomain(new double[] { min }, new double[] { max }, new int[] { 100 }, new Random(randomSeed));
}
Also used : Random(java.util.Random) MathTransform1D(org.opengis.referencing.operation.MathTransform1D)

Example 3 with MathTransform1D

use of org.opengis.referencing.operation.MathTransform1D in project sis by apache.

the class LogarithmicTransform1DTest method testAffineConcatenations.

/**
 * Implementation of {@link #testAffineConcatenations()} for the given base.
 */
private void testAffineConcatenations(final double base) throws TransformException {
    final MathTransform1D linear = LinearTransform1D.create(C1, C0);
    transform = MathTransforms.concatenate(linear, LogarithmicTransform1D.create(base, OFFSET), linear);
    run(ConcatenatedTransformDirect1D.class, base, OFFSET, true, true);
}
Also used : MathTransform1D(org.opengis.referencing.operation.MathTransform1D)

Example 4 with MathTransform1D

use of org.opengis.referencing.operation.MathTransform1D in project sis by apache.

the class TransferFunctionTest method testLinear.

/**
 * Tests the creation of a linear transfer function.
 */
@Test
public void testLinear() {
    final TransferFunction f = new TransferFunction();
    assertEquals("type", TransferFunctionType.LINEAR, f.getType());
    assertEquals("base", 1, f.getBase(), STRICT);
    assertEquals("scale", 1, f.getScale(), STRICT);
    assertEquals("offset", 0, f.getOffset(), STRICT);
    assertEquals("toString", "y = x", f.toString());
    f.setScale(0.15);
    f.setOffset(-2);
    assertEquals("toString", "y = 0.15⋅x − 2", f.toString());
    final MathTransform1D transform = f.getTransform();
    assertInstanceOf("transform", LinearTransform.class, transform);
    assertMatrixEquals("transform.matrix", new Matrix2(0.15, -2, 0, 1), ((LinearTransform) transform).getMatrix(), STRICT);
    /*
         * Get back the coefficients.
         */
    final TransferFunction b = new TransferFunction();
    b.setTransform(transform);
    assertEquals("type", TransferFunctionType.LINEAR, b.getType());
    assertEquals("base", 1, b.getBase(), STRICT);
    assertEquals("scale", 0.15, b.getScale(), STRICT);
    assertEquals("offset", -2, b.getOffset(), STRICT);
}
Also used : MathTransform1D(org.opengis.referencing.operation.MathTransform1D) Matrix2(org.apache.sis.referencing.operation.matrix.Matrix2) Test(org.junit.Test)

Example 5 with MathTransform1D

use of org.opengis.referencing.operation.MathTransform1D in project sis by apache.

the class ProjectiveTransformTest method ensureImplementRightInterface.

/**
 * Executed after every test in order to ensure that the {@linkplain #transform transform}
 * implements the {@link MathTransform1D} or {@link MathTransform2D} interface as needed.
 * In addition, all Apache SIS classes for linear transforms shall implement
 * {@link LinearTransform} and {@link Parameterized} interfaces.
 */
@After
public final void ensureImplementRightInterface() {
    if (transform instanceof TransformResultComparator) {
        transform = ((TransformResultComparator) transform).tested;
    }
    /*
         * Below is a copy of MathTransformTestCase.validate(), with minor modifications
         * due to the fact that this class does not extend MathTransformTestCase.
         */
    assertNotNull("The 'transform' field shall be assigned a value.", transform);
    Validators.validate(transform);
    final int dimension = transform.getSourceDimensions();
    if (transform.getTargetDimensions() == dimension && !skipInterfaceCheckForDimension(dimension)) {
        assertEquals("MathTransform1D", dimension == 1, (transform instanceof MathTransform1D));
        assertEquals("MathTransform2D", dimension == 2, (transform instanceof MathTransform2D));
    } else {
        assertFalse("MathTransform1D", transform instanceof MathTransform1D);
        assertFalse("MathTransform2D", transform instanceof MathTransform2D);
    }
    assertInstanceOf("Parameterized", Parameterized.class, transform);
    /*
         * End of MathTransformTestCase.validate(). Remaining is specific to LinearTransform implementations.
         */
    assertInstanceOf("Not a LinearTransform.", LinearTransform.class, transform);
    final Matrix tm = ((LinearTransform) transform).getMatrix();
    assertTrue("The matrix declared by the MathTransform is not equal to the one given at creation time.", Matrices.equals(matrix, tm, tolerance, false));
    assertSame("ParameterDescriptor", Affine.getProvider(transform.getSourceDimensions(), transform.getTargetDimensions(), true).getParameters(), ((Parameterized) transform).getParameterDescriptors());
}
Also used : Matrix(org.opengis.referencing.operation.Matrix) MathTransform1D(org.opengis.referencing.operation.MathTransform1D) MathTransform2D(org.opengis.referencing.operation.MathTransform2D) After(org.junit.After)

Aggregations

MathTransform1D (org.opengis.referencing.operation.MathTransform1D)13 Test (org.junit.Test)5 DependsOnMethod (org.apache.sis.test.DependsOnMethod)3 MathTransform2D (org.opengis.referencing.operation.MathTransform2D)2 NoninvertibleTransformException (org.opengis.referencing.operation.NoninvertibleTransformException)2 Random (java.util.Random)1 Matrix2 (org.apache.sis.referencing.operation.matrix.Matrix2)1 After (org.junit.After)1 MismatchedDimensionException (org.opengis.geometry.MismatchedDimensionException)1 MathTransform (org.opengis.referencing.operation.MathTransform)1 Matrix (org.opengis.referencing.operation.Matrix)1 TransformException (org.opengis.referencing.operation.TransformException)1 FactoryException (org.opengis.util.FactoryException)1