sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1802672 - in /sis/branches/JDK8: core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/
Date Sat, 22 Jul 2017 10:45:12 GMT
Author: desruisseaux
Date: Sat Jul 22 10:45:12 2017
New Revision: 1802672

URL: http://svn.apache.org/viewvc?rev=1802672&view=rev
Log:
Add concatenation support for Proj.4 transform.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1D.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1D.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PowerTransform1D.java
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Transform.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java?rev=1802672&r1=1802671&r2=1802672&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
[UTF-8] Sat Jul 22 10:45:12 2017
@@ -792,7 +792,7 @@ public abstract class AbstractMathTransf
     }
 
     /**
-     * Concatenates in an optimized way this math transform with the given one.
+     * Concatenates or pre-concatenates in an optimized way this math transform with the
given one.
      * A new math transform is created to perform the combined transformation.
      * The {@code applyOtherFirst} value determines the transformation order as bellow:
      *
@@ -810,16 +810,20 @@ public abstract class AbstractMathTransf
      * {@link ConcatenatedTransform}.
      *
      * <p>The default implementation always returns {@code null}. This method is ought
to be overridden
-     * by subclasses capable of concatenating some combination of transforms in a special
way.
-     * Examples are {@link ExponentialTransform1D} and {@link LogarithmicTransform1D}.</p>
+     * by subclasses capable of concatenating some combination of transforms in a special
way.</p>
      *
-     * @param  other            the math transform to apply.
      * @param  applyOtherFirst  {@code true} if the transformation order is {@code other}
followed by {@code this}, or
      *                          {@code false} if the transformation order is {@code this}
followed by {@code other}.
+     * @param  other            the other math transform to (pre-)concatenate with this transform.
      * @param  factory          the factory which is (indirectly) invoking this method, or
{@code null} if none.
      * @return the combined math transform, or {@code null} if no optimized combined transform
is available.
+     * @throws FactoryException if an error occurred while combining the transforms.
+     *
+     * @see DefaultMathTransformFactory#createConcatenatedTransform(MathTransform, MathTransform)
+     *
+     * @since 0.8
      */
-    MathTransform concatenate(MathTransform other, boolean applyOtherFirst, MathTransformFactory
factory)
+    protected MathTransform tryConcatenate(boolean applyOtherFirst, MathTransform other,
MathTransformFactory factory)
             throws FactoryException
     {
         return null;

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java?rev=1802672&r1=1802671&r2=1802672&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
[UTF-8] Sat Jul 22 10:45:12 2017
@@ -330,13 +330,13 @@ class ConcatenatedTransform extends Abst
          * The main use case is Logarithmic vs Exponential transforms.
          */
         if (tr1 instanceof AbstractMathTransform) {
-            final MathTransform optimized = ((AbstractMathTransform) tr1).concatenate(tr2,
false, factory);
+            final MathTransform optimized = ((AbstractMathTransform) tr1).tryConcatenate(false,
tr2, factory);
             if (optimized != null) {
                 return optimized;
             }
         }
         if (tr2 instanceof AbstractMathTransform) {
-            final MathTransform optimized = ((AbstractMathTransform) tr2).concatenate(tr1,
true, factory);
+            final MathTransform optimized = ((AbstractMathTransform) tr2).tryConcatenate(true,
tr1, factory);
             if (optimized != null) {
                 return optimized;
             }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java?rev=1802672&r1=1802671&r2=1802672&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java
[UTF-8] Sat Jul 22 10:45:12 2017
@@ -915,7 +915,7 @@ next:   while (--numPts >= 0) {
          * </ul>
          */
         @Override
-        final MathTransform concatenate(final MathTransform other, final boolean applyOtherFirst,
+        protected MathTransform tryConcatenate(final boolean applyOtherFirst, final MathTransform
other,
                 final MathTransformFactory factory) throws FactoryException
         {
             if (!applyOtherFirst && withHeight && other instanceof LinearTransform
&& other.getTargetDimensions() == 2) {
@@ -937,7 +937,7 @@ next:   while (--numPts >= 0) {
                     }
                 }
             }
-            return super.concatenate(other, applyOtherFirst, factory);
+            return super.tryConcatenate(applyOtherFirst, other, factory);
         }
 
         /**
@@ -993,9 +993,12 @@ next:   while (--numPts >= 0) {
      *   <li>Allow use of the more efficient {@link java.awt.geom.AffineTransform}
before this transform
      *       instead than a transform based on a matrix of size 4×3.</li>
      * </ul>
+     *
+     * @return the combined math transform, or {@code null} if no optimized combined transform
is available.
+     * @throws FactoryException if an error occurred while combining the transforms.
      */
     @Override
-    final MathTransform concatenate(final MathTransform other, final boolean applyOtherFirst,
+    protected MathTransform tryConcatenate(final boolean applyOtherFirst, final MathTransform
other,
             final MathTransformFactory factory) throws FactoryException
     {
         if (applyOtherFirst && withHeight && other instanceof LinearTransform
&& other.getSourceDimensions() == 2) {
@@ -1017,7 +1020,7 @@ next:   while (--numPts >= 0) {
                 }
             }
         }
-        return super.concatenate(other, applyOtherFirst, factory);
+        return super.tryConcatenate(applyOtherFirst, other, factory);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1D.java?rev=1802672&r1=1802671&r2=1802672&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1D.java
[UTF-8] Sat Jul 22 10:45:12 2017
@@ -217,14 +217,14 @@ final class ExponentialTransform1D exten
      * {@code MathTransform}. This implementation can optimize some concatenation with
      * {@link LinearTransform1D} and {@link LogarithmicTransform1D}.
      *
-     * @param  other            the math transform to apply.
      * @param  applyOtherFirst  {@code true} if the transformation order is {@code other}
followed by {@code this}, or
      *                          {@code false} if the transformation order is {@code this}
followed by {@code other}.
+     * @param  other            the other math transform to (pre-)concatenate with this transform.
      * @param  factory          the factory which is (indirectly) invoking this method, or
{@code null} if none.
      * @return the combined math transform, or {@code null} if no optimized combined transform
is available.
      */
     @Override
-    final MathTransform concatenate(final MathTransform other, final boolean applyOtherFirst,
+    protected MathTransform tryConcatenate(final boolean applyOtherFirst, final MathTransform
other,
             final MathTransformFactory factory) throws FactoryException
     {
         if (other instanceof LinearTransform) {
@@ -243,7 +243,7 @@ final class ExponentialTransform1D exten
         } else if (other instanceof LogarithmicTransform1D) {
             return concatenateLog((LogarithmicTransform1D) other, applyOtherFirst);
         }
-        return super.concatenate(other, applyOtherFirst, factory);
+        return super.tryConcatenate(applyOtherFirst, other, factory);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1D.java?rev=1802672&r1=1802671&r2=1802672&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1D.java
[UTF-8] Sat Jul 22 10:45:12 2017
@@ -113,14 +113,14 @@ class LogarithmicTransform1D extends Abs
      * {@code MathTransform}. This implementation can optimize some concatenation with
      * {@link LinearTransform1D} and {@link ExponentialTransform1D}.
      *
-     * @param  other            the math transform to apply.
      * @param  applyOtherFirst  {@code true} if the transformation order is {@code other}
followed by {@code this}, or
      *                          {@code false} if the transformation order is {@code this}
followed by {@code other}.
+     * @param  other            the other math transform to (pre-)concatenate with this transform.
      * @param  factory          the factory which is (indirectly) invoking this method, or
{@code null} if none.
      * @return the combined math transform, or {@code null} if no optimized combined transform
is available.
      */
     @Override
-    final MathTransform concatenate(final MathTransform other, final boolean applyOtherFirst,
+    protected MathTransform tryConcatenate(final boolean applyOtherFirst, final MathTransform
other,
             final MathTransformFactory factory) throws FactoryException
     {
         if (other instanceof LinearTransform1D) {
@@ -138,7 +138,7 @@ class LogarithmicTransform1D extends Abs
         } else if (other instanceof ExponentialTransform1D) {
             return ((ExponentialTransform1D) other).concatenateLog(this, !applyOtherFirst);
         }
-        return super.concatenate(other, applyOtherFirst, factory);
+        return super.tryConcatenate(applyOtherFirst, other, factory);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PowerTransform1D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PowerTransform1D.java?rev=1802672&r1=1802671&r2=1802672&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PowerTransform1D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PowerTransform1D.java
[UTF-8] Sat Jul 22 10:45:12 2017
@@ -31,7 +31,7 @@ import org.apache.sis.util.ComparisonMod
  * Future version may expand on that.
  *
  * <p>Before to make this class public (if we do), we need to revisit the class name,
define parameters
- * and improve the {@link #concatenate(MathTransform, boolean, MathTransformFactory)} method.</p>
+ * and improve the {@link #tryConcatenate(boolean, MathTransform, MathTransformFactory)}
method.</p>
  *
  * <div class="section">Serialization</div>
  * Serialized instances of this class are not guaranteed to be compatible with future SIS
versions.
@@ -171,21 +171,22 @@ final class PowerTransform1D extends Abs
     /**
      * Concatenates in an optimized way a {@link MathTransform} {@code other} to this {@code
MathTransform}.
      *
-     * @param  other            the math transform to apply.
      * @param  applyOtherFirst  {@code true} if the transformation order is {@code other}
followed by {@code this},
      *                          or {@code false} if the transformation order is {@code this}
followed by {@code other}.
+     * @param  other            the other math transform to (pre-)concatenate with this transform.
      * @param  factory          the factory which is (indirectly) invoking this method, or
{@code null} if none.
      * @return the combined math transform, or {@code null} if no optimized combined transform
is available.
      */
     @Override
-    final MathTransform concatenate(final MathTransform other, final boolean applyOtherFirst,
+    protected MathTransform tryConcatenate(final boolean applyOtherFirst, final MathTransform
other,
             final MathTransformFactory factory) throws FactoryException
     {
         if (other instanceof PowerTransform1D) {
+            // Valid for both concatenation and pre-concatenation.
             return create(power + ((PowerTransform1D) other).power);
         }
         // TODO: more optimization could go here for logarithmic and exponential cases.
-        return super.concatenate(other, applyOtherFirst, factory);
+        return super.tryConcatenate(applyOtherFirst, other, factory);
     }
 
     /**

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Transform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Transform.java?rev=1802672&r1=1802671&r2=1802672&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Transform.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Transform.java
[UTF-8] Sat Jul 22 10:45:12 2017
@@ -25,11 +25,13 @@ import org.opengis.referencing.operation
 import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.TransformException;
+import org.opengis.referencing.operation.MathTransformFactory;
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.parameter.ParameterBuilder;
 import org.apache.sis.referencing.operation.DefaultOperationMethod;
 import org.apache.sis.referencing.operation.transform.AbstractMathTransform;
+import org.opengis.util.FactoryException;
 
 
 /**
@@ -176,4 +178,22 @@ final class Transform extends AbstractMa
         }
         return inverse;
     }
+
+    /**
+     * If both transforms are {@literal Proj.4} wrappers, returns a single transform without
intermediate step.
+     */
+    @Override
+    protected MathTransform tryConcatenate(final boolean applyOtherFirst, final MathTransform
other,
+            final MathTransformFactory factory) throws FactoryException
+    {
+        if (other instanceof Transform) {
+            final Transform tr = (Transform) other;
+            if (applyOtherFirst) {
+                return new Transform(tr.source, tr.source3D, target, target3D);
+            } else {
+                return new Transform(source, source3D, tr.target, tr.target3D);
+            }
+        }
+        return super.tryConcatenate(applyOtherFirst, other, factory);
+    }
 }



Mime
View raw message