sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 04/05: Add a test verifying more deeply PassThroughTransform.tryConcatenate(…) work.
Date Thu, 29 Nov 2018 18:09:20 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit f248e6b621ccf08e32a4db21b06810dd9fe86eba
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Thu Nov 29 18:08:42 2018 +0100

    Add a test verifying more deeply PassThroughTransform.tryConcatenate(…) work.
---
 .../apache/sis/coverage/grid/GridGeometryTest.java | 47 +++++++++++++++++---
 .../transform/PassThroughTransformTest.java        | 51 ++++++++++++++++++++++
 2 files changed, 93 insertions(+), 5 deletions(-)

diff --git a/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
b/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
index 2da4f77..28ebd88 100644
--- a/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
+++ b/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
@@ -176,7 +176,7 @@ public final strictfp class GridGeometryTest extends TestCase {
                     DimensionNameType.VERTICAL,
                     DimensionNameType.TIME
                 },
-                new long[] {0,     0, 2, 6},
+                new long[] {  0,   0, 2, 6},
                 new long[] {100, 200, 3, 9}, false);
         final MathTransform horizontal = MathTransforms.linear(new Matrix3(
                 0.5, 0,    12,
@@ -248,9 +248,46 @@ public final strictfp class GridGeometryTest extends TestCase {
         envelope = new GeneralEnvelope(HardCodedCRS.WGS84);
         envelope.setRange(0, -70.001, +80.002);
         envelope.setRange(1,   4.997,  15.003);
-        final GridExtent extent = grid.getExtent(envelope);
-        assertExtentEquals(
-                new long[] {370,  40,  4},
-                new long[] {389, 339, 10}, extent);
+        assertExtentEquals(new long[] {370,  40,  4},
+                           new long[] {389, 339, 10}, grid.getExtent(envelope));
+    }
+
+    /**
+     * Tests {@link GridGeometry#getExtent(Envelope)} with a non-linear "grid to CRS" transform.
+     *
+     * @throws TransformException if an error occurred while using the "grid to CRS" transform.
+     */
+    @Test
+    @DependsOnMethod("testNonLinear")
+    public void testGetExtentNonLinear() throws TransformException {
+        final GridExtent extent = new GridExtent(
+                new DimensionNameType[] {
+                    DimensionNameType.COLUMN,
+                    DimensionNameType.ROW,
+                    DimensionNameType.VERTICAL
+                },
+                new long[] {  0,  0, 2},
+                new long[] {180, 90, 5}, false);
+        final MathTransform linear = MathTransforms.linear(new Matrix4(
+                2, 0, 0, -180,
+                0, 2, 0,  -90,
+                0, 0, 5,   10,
+                0, 0, 0,    1));
+        final MathTransform latitude  = MathTransforms.interpolate(new double[] {0, 20, 50,
70, 90}, new double[] {-90, -45, 0, 45, 90});
+        final MathTransform gridToCRS = MathTransforms.concatenate(linear, MathTransforms.passThrough(1,
latitude, 1));
+        final GridGeometry  grid      = new GridGeometry(extent, PixelInCell.CELL_CENTER,
gridToCRS, HardCodedCRS.WGS84_3D);
+        /*
+         * Following tests is similar to the one executed in testGetExtent(). Expected values
are only
+         * anti-regression values, except the vertical range which is expected to cover all
cells. The
+         * main purpose of this test is to verify that TransformSeparator has been able to
extract the
+         * two-dimensional transform despite its non-linear component.
+         */
+        final GeneralEnvelope envelope = new GeneralEnvelope(HardCodedCRS.WGS84);
+        envelope.setRange(0, -70.001, +80.002);
+        envelope.setRange(1,  -4.997,  15.003);
+        final GridExtent actual = grid.getExtent(envelope);
+        assertEquals(extent.getAxisType(0), actual.getAxisType(0));
+        assertExtentEquals(new long[] { 56, 69, 2},
+                           new long[] {130, 73, 4}, actual);
     }
 }
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java
index c24d007..c15833f 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java
@@ -16,11 +16,15 @@
  */
 package org.apache.sis.referencing.operation.transform;
 
+import java.util.List;
 import java.util.Arrays;
 import java.util.Random;
+import org.opengis.util.FactoryException;
 import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.MathTransformFactory;
 import org.opengis.referencing.operation.TransformException;
+import org.apache.sis.referencing.operation.matrix.Matrices;
 import org.apache.sis.referencing.operation.matrix.Matrix3;
 import org.apache.sis.internal.util.Numerics;
 import org.apache.sis.util.ArraysExt;
@@ -251,4 +255,51 @@ public final strictfp class PassThroughTransformTest extends MathTransformTestCa
                     sourceDim, expectedData, 0, targetAsFloat, 0, numPts, CalculationType.DIRECT_TRANSFORM);
         }
     }
+
+    /**
+     * Tests {@link PassThroughTransform#tryConcatenate(boolean, MathTransform, MathTransformFactory)}.
+     * This tests creates a non-linear transform of 6→7 dimensions, then applies a filter
keeping only
+     * target dimensions 1, 4 and 6 (corresponding to source dimensions 1 and 5).
+     *
+     * @throws FactoryException if an error occurred while combining the transforms.
+     */
+    @Test
+    public void testTryConcatenate() throws FactoryException {
+        PassThroughTransform ps = PassThroughTransform.newInstance(2, new PseudoTransform(2,
3), 2);
+        MathTransform c = ps.tryConcatenate(false, MathTransforms.linear(Matrices.create(4,
8, new double[] {
+                0, 1, 0, 0, 0, 0, 0, 0,
+                0, 0, 0, 0, 1, 0, 0, 0,
+                0, 0, 0, 0, 0, 0, 1, 0,
+                0, 0, 0, 0, 0, 0, 0, 1})), null);
+
+        final List<MathTransform> steps = MathTransforms.getSteps(c);
+        assertEquals("Number of steps", 3, steps.size());
+        /*
+         * We need to remove source dimensions 0, 2, 3 and 4. We can not remove dimensions
2 and 3 before
+         * pass-through because they are used by the sub-transform. It leaves us dimensions
0 and 4 which
+         * can be removed here.
+         */
+        assertMatrixEquals("Expected removal of dimensions 0 and 4 before pass-through",
Matrices.create(5, 7, new double[] {
+                0, 1, 0, 0, 0, 0, 0,
+                0, 0, 1, 0, 0, 0, 0,
+                0, 0, 0, 1, 0, 0, 0,
+                0, 0, 0, 0, 0, 1, 0,
+                0, 0, 0, 0, 0, 0, 1}), MathTransforms.getMatrix(steps.get(0)), null);
+        /*
+         * The number of pass-through dimensions have decreased from 2 to 1 on both sides
of the sub-transform.
+         */
+        final PassThroughTransform reduced = (PassThroughTransform) steps.get(1);
+        assertEquals("firstAffectedOrdinate", 1, reduced.firstAffectedOrdinate);
+        assertEquals("numTrailingOrdinates",  1, reduced.numTrailingOrdinates);
+        assertSame  ("subTransform", ps.subTransform, reduced.subTransform);
+        /*
+         * We still have to remove source dimensions 2 and 3. Since we removed dimension
0 in previous step,
+         * the indices of dimensions to removed have shifted to 1 and 2.
+         */
+        assertMatrixEquals("Expected removal of dimensions 1 and 2 after pass-through", Matrices.create(4,
6, new double[] {
+                1, 0, 0, 0, 0, 0,
+                0, 0, 0, 1, 0, 0,
+                0, 0, 0, 0, 1, 0,
+                0, 0, 0, 0, 0, 1}), MathTransforms.getMatrix(steps.get(2)), null);
+    }
 }


Mime
View raw message