sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1684685 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/referencing/operation/transform/ test/java/org/apache/sis/referencing/operation/transform/
Date Wed, 10 Jun 2015 14:40:39 GMT
Author: desruisseaux
Date: Wed Jun 10 14:40:38 2015
New Revision: 1684685

URL: http://svn.apache.org/r1684685
Log:
Added a MathTransforms.compound(MathTransform...) convenience method.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PassThroughTransform.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java?rev=1684685&r1=1684684&r2=1684685&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
[UTF-8] Wed Jun 10 14:40:38 2015
@@ -52,7 +52,7 @@ import static org.apache.sis.util.Argume
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.5
- * @version 0.5
+ * @version 0.6
  * @module
  *
  * @see MathTransformFactory
@@ -147,6 +147,52 @@ public final class MathTransforms extend
     }
 
     /**
+     * Puts together a list of independent math transforms, each of them operating on a subset
of ordinate values.
+     * This method is often used for defining 4-dimensional (<var>x</var>,<var>y</var>,<var>z</var>,<var>t</var>)
+     * transform as an aggregation of 3 simpler transforms operating on (<var>x</var>,<var>y</var>),
(<var>z</var>)
+     * and (<var>t</var>) values respectively.
+     *
+     * <p>Invariants:</p>
+     * <ul>
+     *   <li>The {@linkplain AbstractMathTransform#getSourceDimensions() source dimensions}
of the returned transform
+     *       is equals to the sum of the source dimensions of all given transforms.</li>
+     *   <li>The {@linkplain AbstractMathTransform#getTargetDimensions() target dimensions}
of the returned transform
+     *       is equals to the sum of the target dimensions of all given transforms.</li>
+     * </ul>
+     *
+     * @param  transforms The transforms to aggregate in a single transform, in the given
order.
+     * @return The aggregation of all given transforms, or {@code null} if the given {@code
transforms} array was empty.
+     *
+     * @see PassThroughTransform
+     * @see org.apache.sis.referencing.crs.DefaultCompoundCRS
+     *
+     * @since 0.6
+     */
+    public static MathTransform compound(final MathTransform... transforms) {
+        ensureNonNull("transforms", transforms);
+        int sum = 0;
+        final int[] dimensions = new int[transforms.length];
+        for (int i=0; i<transforms.length; i++) {
+            final MathTransform tr = transforms[i];
+            ensureNonNullElement("transforms", i, tr);
+            sum += (dimensions[i] = tr.getSourceDimensions());
+        }
+        MathTransform compound = null;
+        int firstAffectedOrdinate = 0;
+        for (int i=0; i<transforms.length; i++) {
+            MathTransform tr = transforms[i];
+            tr = PassThroughTransform.create(firstAffectedOrdinate, tr, sum - (firstAffectedOrdinate
+= dimensions[i]));
+            if (compound == null) {
+                compound = tr;
+            } else {
+                compound = ConcatenatedTransform.create(compound, tr);
+            }
+        }
+        assert isValid(getSteps(compound)) : compound;
+        return compound;
+    }
+
+    /**
      * Concatenates the two given transforms. The returned transform will implement
      * {@link MathTransform1D} or {@link MathTransform2D} if the dimensions of the
      * concatenated transform are equal to 1 or 2 respectively.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PassThroughTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PassThroughTransform.java?rev=1684685&r1=1684684&r2=1684685&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PassThroughTransform.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PassThroughTransform.java
[UTF-8] Wed Jun 10 14:40:38 2015
@@ -61,6 +61,8 @@ import static org.apache.sis.util.Argume
  * @since   0.5
  * @version 0.5
  * @module
+ *
+ * @see MathTransforms#compound(MathTransform...)
  */
 public class PassThroughTransform extends AbstractMathTransform implements Serializable {
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java?rev=1684685&r1=1684684&r2=1684685&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java
[UTF-8] Wed Jun 10 14:40:38 2015
@@ -18,6 +18,9 @@ package org.apache.sis.referencing.opera
 
 import java.util.List;
 import org.opengis.referencing.operation.MathTransform;
+import org.apache.sis.referencing.operation.matrix.Matrices;
+import org.apache.sis.referencing.operation.matrix.Matrix2;
+import org.apache.sis.referencing.operation.matrix.Matrix3;
 import org.apache.sis.referencing.operation.matrix.Matrix4;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
@@ -30,7 +33,7 @@ import static org.opengis.test.Assert.*;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.5
- * @version 0.5
+ * @version 0.6
  * @module
  */
 public final strictfp class MathTransformsTest extends TestCase {
@@ -86,4 +89,35 @@ public final strictfp class MathTransfor
         assertMatrixEquals("Step 3", swap,  MathTransforms.getMatrix(steps.get(2)), STRICT);
         assertInstanceOf  ("Step 2", PassThroughTransform.class, steps.get(1));
     }
+
+    /**
+     * Tests {@link MathTransforms#compound(MathTransform...)}.
+     * This test uses linear transforms because they are easy to test, but the
+     * {@code MathTransforms.compound(…)} method should work with any transforms.
+     */
+    @Test
+    public void testCompound() {
+        final MathTransform t1 = MathTransforms.linear(new Matrix2(
+            3, -1,   // Random numbers (no real meaning)
+            0,  1));
+        final MathTransform t2 = MathTransforms.linear(new Matrix4(
+            0,  8,  0,  9,
+            5,  0,  0, -7,
+            0,  0,  2,  0,
+            0,  0,  0,  1));
+        final MathTransform t3 = MathTransforms.linear(new Matrix3(
+            0, -5, -3,
+            7,  0, -9,
+            0,  0,  1));
+        final MathTransform r = MathTransforms.compound(t1, t2, t3);
+        assertMatrixEquals("compound", Matrices.create(7, 7, new double[] {
+            3,  0,  0,  0,  0,  0, -1,
+            0,  0,  8,  0,  0,  0,  9,
+            0,  5,  0,  0,  0,  0, -7,
+            0,  0,  0,  2,  0,  0,  0,
+            0,  0,  0,  0,  0, -5, -3,
+            0,  0,  0,  0,  7,  0, -9,
+            0,  0,  0,  0,  0,  0,  1
+        }), MathTransforms.getMatrix(r), STRICT);
+    }
 }



Mime
View raw message