Author: desruisseaux
Date: Fri Jun 6 17:12:04 2014
New Revision: 1600964
URL: http://svn.apache.org/r1600964
Log:
Ported PassThroughTransformTest.
Added:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java
(with props)
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateDomain.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateDomain.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateDomain.java?rev=1600964&r1=1600963&r2=1600964&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateDomain.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateDomain.java
[UTF-8] Fri Jun 6 17:12:04 2014
@@ -40,7 +40,8 @@ public strictfp enum CoordinateDomain {
* Geocentric input coordinates. The input dimension must be 3.
*/
GEOCENTRIC {
- @Override double[] generateRandomInput(final Random random, final int
dimension, final int numPts) {
+ @Override
+ public double[] generateRandomInput(final Random random, final int
dimension, final int numPts) {
if (dimension != 3) {
throw new IllegalArgumentException();
}
@@ -64,7 +65,8 @@ public strictfp enum CoordinateDomain {
* Ordinates are in (<var>longitude</var>, <var>latitude</var>,
<var>height</var>) order.
*/
GEOGRAPHIC {
- @Override double generate(final Random random, final int dimension) {
+ @Override
+ double generate(final Random random, final int dimension) {
final double range;
switch (dimension) {
case 0: range = Longitude.MAX_VALUE; break; // Full longitude
range.
@@ -81,7 +83,8 @@ public strictfp enum CoordinateDomain {
* Ordinates are in (<var>longitude</var>, <var>latitude</var>,
<var>height</var>) order.
*/
GEOGRAPHIC_SAFE {
- @Override double generate(final Random random, final int dimension) {
+ @Override
+ double generate(final Random random, final int dimension) {
final double range;
switch (dimension) {
case 0: range = Longitude.MAX_VALUE - 1; break; // Longitude,
avoiding anti-meridian.
@@ -98,7 +101,8 @@ public strictfp enum CoordinateDomain {
* Ordinates are in (<var>longitude</var>, <var>latitude</var>,
<var>height</var>) order.
*/
GEOGRAPHIC_POLES {
- @Override double generate(final Random random, final int dimension) {
+ @Override
+ double generate(final Random random, final int dimension) {
final double range;
switch (dimension) {
case 0: range = Longitude.MAX_VALUE; break;
@@ -123,7 +127,8 @@ public strictfp enum CoordinateDomain {
* Ordinates are in (<var>lambda</var>, <var>phi</var>, <var>height</var>)
order.
*/
GEOGRAPHIC_RADIANS {
- @Override double generate(final Random random, final int dimension) {
+ @Override
+ double generate(final Random random, final int dimension) {
final double range;
switch (dimension) {
case 0: range = PI; break; // Longitude.
@@ -140,7 +145,8 @@ public strictfp enum CoordinateDomain {
* Ordinates are in (<var>lambda</var>, <var>phi</var>, <var>height</var>)
order.
*/
GEOGRAPHIC_RADIANS_HALF {
- @Override double generate(final Random random, final int dimension) {
+ @Override
+ double generate(final Random random, final int dimension) {
final double range;
switch (dimension) {
case 0: range = PI/2; break; // Longitude.
@@ -157,7 +163,8 @@ public strictfp enum CoordinateDomain {
* Ordinates are in (<var>lambda</var>, <var>phi</var>, <var>height</var>)
order.
*/
GEOGRAPHIC_RADIANS_NORTH {
- @Override double generate(final Random random, final int dimension) {
+ @Override
+ double generate(final Random random, final int dimension) {
final double range;
switch (dimension) {
case 0: range = PI; break;
@@ -174,7 +181,8 @@ public strictfp enum CoordinateDomain {
* Ordinates are in (<var>lambda</var>, <var>phi</var>, <var>height</var>)
order.
*/
GEOGRAPHIC_RADIANS_SOUTH {
- @Override double generate(final Random random, final int dimension) {
+ @Override
+ double generate(final Random random, final int dimension) {
final double range;
switch (dimension) {
case 0: range = PI; break;
@@ -191,7 +199,8 @@ public strictfp enum CoordinateDomain {
* Ordinates are in (<var>lambda</var>, <var>phi</var>, <var>height</var>)
order.
*/
GEOGRAPHIC_RADIANS_EAST {
- @Override double generate(final Random random, final int dimension) {
+ @Override
+ double generate(final Random random, final int dimension) {
final double range;
switch (dimension) {
case 0: return +PI*random.nextDouble();
@@ -208,7 +217,8 @@ public strictfp enum CoordinateDomain {
* Ordinates are in (<var>lambda</var>, <var>phi</var>, <var>height</var>)
order.
*/
GEOGRAPHIC_RADIANS_WEST {
- @Override double generate(final Random random, final int dimension) {
+ @Override
+ double generate(final Random random, final int dimension) {
final double range;
switch (dimension) {
case 0: return -PI*random.nextDouble();
@@ -225,7 +235,8 @@ public strictfp enum CoordinateDomain {
* Ordinates are in (<var>easting</var>, <var>northing</var>,
<var>height</var>) order.
*/
PROJECTED {
- @Override double generate(final Random random, final int dimension) {
+ @Override
+ double generate(final Random random, final int dimension) {
final double range;
switch (dimension) {
case 0: range = 350000; break; // Easting.
@@ -251,7 +262,7 @@ public strictfp enum CoordinateDomain {
* @param numPts The number of points to generate.
* @return An array of length {@code numPts*dimension} filled with random
input ordinate values.
*/
- double[] generateRandomInput(final Random random, final int dimension,
final int numPts) {
+ public double[] generateRandomInput(final Random random, final int
dimension, final int numPts) {
final double[] ordinates = new double[numPts * dimension];
for (int i=0; i<ordinates.length; i++) {
ordinates[i] = generate(random, i % dimension);
Added:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java?rev=1600964&view=auto
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java
(added)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java
[UTF-8] Fri Jun 6 17:12:04 2014
@@ -0,0 +1,248 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.referencing.operation.transform;
+
+import java.util.Arrays;
+import java.util.Random;
+import org.opengis.referencing.operation.Matrix;
+import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.TransformException;
+import org.apache.sis.referencing.operation.matrix.Matrix3;
+import org.apache.sis.internal.util.Numerics;
+
+// Test imports
+import org.junit.Test;
+import org.opengis.test.CalculationType;
+import org.opengis.test.ToleranceModifier;
+import org.apache.sis.test.TestUtilities;
+import org.apache.sis.util.ArraysExt;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests {@link PassThroughTransform}.
+ *
+ * <p>The {@link DimensionFilter} class is also tested in order to ensure that
it
+ * can gives back the original transform.</p>
+ *
+ * @author Martin Desruisseaux (IRD, Geomatys)
+ * @since 0.5 (derived from geotk-2.0)
+ * @version 0.5
+ * @module
+ */
+public final strictfp class PassThroughTransformTest extends
MathTransformTestCase {
+ /**
+ * The random number generator to be used in this test.
+ */
+ private Random random;
+
+ /**
+ * Verifies argument validation performed by {@link
PassThroughTransform#create(int, MathTransform, int)}.
+ */
+ @Test
+ public void testIllegalArgument() {
+ final MathTransform subTransform = MathTransforms.identity(1);
+ try {
+ PassThroughTransform.create(-1, subTransform, 0);
+ fail("An illegal argument should have been detected");
+ } catch (IllegalArgumentException e) {
+ final String message = e.getMessage();
+ assertTrue(message, message.contains("firstAffectedOrdinate"));
+ }
+ try {
+ PassThroughTransform.create(0, subTransform, -1);
+ fail("An illegal argument should have been detected");
+ } catch (IllegalArgumentException e) {
+ final String message = e.getMessage();
+ assertTrue(message, message.contains("numTrailingOrdinates"));
+ }
+
+ }
+
+ /**
+ * Tests the pass through transform using an identity transform.
+ * The "pass-through" of such transform shall be itself the identity
transform.
+ *
+ * @throws TransformException Should never happen.
+ */
+ @Test
+ public void testIdentity() throws TransformException {
+ final Matrix matrix = new Matrix3();
+ runTest(MathTransforms.linear(matrix), IdentityTransform.class);
+ }
+
+ /**
+ * Tests the pass-through transform using an affine transform.
+ * The "pass-through" of such transforms are optimized using matrix
arithmetic.
+ *
+ * @throws TransformException Should never happen.
+ */
+ @Test
+ public void testLinear() throws TransformException {
+ final Matrix matrix = new Matrix3(
+ 4, 0, 0,
+ 0, 3, 0,
+ 0, 0, 1);
+ runTest(MathTransforms.linear(matrix), LinearTransform.class);
+ }
+
+ /**
+ * Tests the general pass-through transform. This test needs a non-linear
sub-transform
+ * for preventing the factory method to optimize.
+ *
+ * @throws TransformException Should never happen.
+ */
+// TODO
+// @Test
+// public void testPassthrough() throws TransformException {
+// final ParameterValueGroup param =
mtFactory.getDefaultParameters("Exponential");
+// runTest(mtFactory.createParameterizedTransform(param),
PassThroughTransform.class);
+// }
+
+ /**
+ * Tests a pass-through transform built using the given sub-transform.
+ *
+ * @param subTransform The sub-transform to use for building
pass-through transform.
+ * @param expectedClass The expected implementation class of pass-through
transforms.
+ * @throws TransformException If a transform failed.
+ */
+ private void runTest(final MathTransform subTransform, final Class<?
extends MathTransform> expectedClass)
+ throws TransformException
+ {
+ random = TestUtilities.createRandomNumberGenerator();
+ /*
+ * Tests many combinations of "first affected ordinate" and "number of
trailing ordinates"
+ * parameters. For each combination we create a passthrough transform,
test it with the
+ * "verifyTransform" method, then try to split it back to the original
transform using
+ * the DimensionFilter class.
+ */
+// TODO final DimensionFilter filter = new DimensionFilter(mtFactory);
+ for (int firstAffectedOrdinate=0; firstAffectedOrdinate<=3;
firstAffectedOrdinate++) {
+ final int firstTrailingOrdinate = firstAffectedOrdinate +
subTransform.getSourceDimensions();
+ for (int numTrailingOrdinates=0; numTrailingOrdinates<=3;
numTrailingOrdinates++) {
+ final int numAdditionalOrdinates = firstAffectedOrdinate +
numTrailingOrdinates;
+ transform = PassThroughTransform.create(firstAffectedOrdinate,
subTransform, numTrailingOrdinates);
+ /*
+ * Test the PassthroughTransform.
+ */
+ if (numAdditionalOrdinates == 0) {
+ assertSame("Failed to recognize that no passthrough was
needed.", subTransform, transform);
+ continue;
+ }
+ assertNotSame(subTransform, transform);
+ assertTrue ("Wrong transform class.",
expectedClass.isInstance(transform));
+ assertEquals ("Wrong number of source dimensions.",
+ subTransform.getSourceDimensions() +
numAdditionalOrdinates, transform.getSourceDimensions());
+ assertEquals ("Wrong number of target dimensions.",
+ subTransform.getTargetDimensions() +
numAdditionalOrdinates, transform.getTargetDimensions());
+ verifyTransform(subTransform, firstAffectedOrdinate);
+ /*
+ * Split the PassthroughTransform back to the original
sub-transform.
+ */
+// if (firstAffectedOrdinate != 0) {
+// filter.addSourceDimensionRange(0, firstAffectedOrdinate);
+// assertTrue("Expected an identity transform.",
filter.separate(transform).isIdentity());
+// filter.clear();
+// }
+// if (numTrailingOrdinates != 0) {
+// filter.addSourceDimensionRange(firstTrailingOrdinate,
transform.getSourceDimensions());
+// assertTrue("Expected an identity transform.",
filter.separate(transform).isIdentity());
+// filter.clear();
+// }
+// filter.addSourceDimensionRange(firstAffectedOrdinate,
firstTrailingOrdinate);
+// assertEquals("Expected the sub-transform.", subTransform,
filter.separate(transform));
+// final int[] expectedDimensions = new
int[subTransform.getTargetDimensions()];
+// for (int i=0; i<expectedDimensions.length; i++) {
+// expectedDimensions[i] = firstAffectedOrdinate + i;
+// }
+// assertTrue("Unexpected output dimensions",
+// Arrays.equals(expectedDimensions,
filter.getTargetDimensions()));
+// filter.clear();
+ }
+ }
+ }
+
+ /**
+ * Tests the current {@linkplain #transform transform} using an array of
random coordinate values,
+ * and compares the result against the expected ones. This method computes
itself the expected results.
+ *
+ * @param subTransform The sub transform used by the current pass-through
transform.
+ * @param firstAffectedOrdinate First input/output dimension used by
{@code subTransform}.
+ * @throws TransformException If a transform failed.
+ */
+ private void verifyTransform(final MathTransform subTransform, final int
firstAffectedOrdinate)
+ throws TransformException
+ {
+ validate();
+ /*
+ * Prepare two arrays:
+ * - passthrough data, to be given to the transform to be tested.
+ * - sub-transform data, which we will use internally for verifying
the pass-through work.
+ */
+ final int passthroughDim = transform.getSourceDimensions();
+ final int subTransformDim = subTransform.getSourceDimensions();
+ final int numPts = ORDINATE_COUNT / passthroughDim;
+ final double[] passthroughData =
CoordinateDomain.GEOGRAPHIC.generateRandomInput(random, passthroughDim, numPts);
+ final double[] subTransformData = new double[numPts * subTransformDim];
+ Arrays.fill(subTransformData, Double.NaN);
+ for (int i=0; i<numPts; i++) {
+ System.arraycopy(passthroughData, firstAffectedOrdinate +
i*passthroughDim,
+ subTransformData, i*subTransformDim,
subTransformDim);
+ }
+ assertFalse("Error building test arrays.",
ArraysExt.hasNaN(subTransformData));
+ /*
+ * Build the array of expected data by applying ourself the
sub-transform.
+ */
+ subTransform.transform(subTransformData, 0, subTransformData, 0,
numPts);
+ final double[] expectedData = passthroughData.clone();
+ for (int i=0; i<numPts; i++) {
+ System.arraycopy(subTransformData, i*subTransformDim, expectedData,
+ firstAffectedOrdinate + i*passthroughDim,
subTransformDim);
+ }
+ assertEquals("Error building test arrays.", subTransform.isIdentity(),
+ Arrays.equals(passthroughData, expectedData));
+ /*
+ * Now process to the transform and compares the results with the
expected ones.
+ * We perform a copy of the source data before to transform them in
order to use
+ * the same values for running the GeoAPI tests as the next step.
+ */
+ tolerance = 0; // Results should be strictly identical because
we used the same inputs.
+ toleranceModifier = null;
+ final float[] sourceAsFloat = Numerics.copyAsFloats(passthroughData);
+ transform.transform(passthroughData, 0, passthroughData, 0, numPts);
+ assertCoordinatesEqual("Expected a plain copy.", passthroughDim,
+ expectedData, 0, passthroughData, 0, numPts,
CalculationType.IDENTITY);
+ /*
+ * Verify the consistency between different 'transform(…)' methods.
+ * We use a relatively high tolerance threshold because result are
+ * computed using inputs stored as float values.
+ */
+ tolerance = 1E-4f;
+ toleranceModifier = ToleranceModifier.RELATIVE;
+ final float[] targetAsFloat = verifyConsistency(sourceAsFloat);
+ assertEquals("Unexpected length of transformed array.",
expectedData.length, targetAsFloat.length);
+ assertCoordinatesEqual("A transformed value is wrong.", passthroughDim,
+ expectedData, 0, targetAsFloat, 0, numPts,
CalculationType.DIRECT_TRANSFORM);
+ /*
+ * Test inverse transform.
+ */
+ transform.inverse().transform(passthroughData, 0, passthroughData, 0,
numPts);
+ assertCoordinatesEqual("A transformed value is wrong.", passthroughDim,
+ sourceAsFloat, 0, passthroughData, 0, numPts,
CalculationType.DIRECT_TRANSFORM);
+ }
+}
Propchange:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1600964&r1=1600963&r2=1600964&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Fri Jun 6 17:12:04 2014
@@ -45,6 +45,7 @@ import org.junit.BeforeClass;
org.apache.sis.referencing.operation.transform.ProjectiveTransformTest.class,
org.apache.sis.referencing.operation.transform.LinearTransformTest.class,
org.apache.sis.referencing.operation.transform.CopyTransformTest.class,
+
org.apache.sis.referencing.operation.transform.PassThroughTransformTest.class,
org.apache.sis.internal.referencing.FormulasTest.class,
org.apache.sis.internal.referencing.VerticalDatumTypesTest.class,