sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: When no source dimensions were specified, TransformSeparator should keep only the source dimensions needed for the target dimensions. https://issues.apache.org/jira/browse/SIS-458
Date Tue, 04 Jun 2019 23:17:40 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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new d515e82  When no source dimensions were specified, TransformSeparator should keep
only the source dimensions needed for the target dimensions. https://issues.apache.org/jira/browse/SIS-458
d515e82 is described below

commit d515e82eeb690e6a9e2d583ae35c30ba149f9771
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Jun 5 01:16:41 2019 +0200

    When no source dimensions were specified, TransformSeparator should keep only the source
dimensions needed for the target dimensions.
    https://issues.apache.org/jira/browse/SIS-458
---
 .../apache/sis/coverage/grid/GridDerivation.java   |  1 -
 .../operation/transform/TransformSeparator.java    | 65 +++++++---------------
 .../transform/TransformSeparatorTest.java          | 13 +++--
 3 files changed, 28 insertions(+), 51 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
index f4af7d6..05f9e79 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
@@ -618,7 +618,6 @@ public class GridDerivation {
     {
         if (dimension < cornerToCRS.getSourceDimensions()) {
             final TransformSeparator sep = new TransformSeparator(cornerToCRS);
-            sep.setTrimSourceDimensions(true);
             cornerToCRS = sep.separate();
             modifiedDimensions = sep.getSourceDimensions();
             if (modifiedDimensions.length != dimension) {
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/TransformSeparator.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/TransformSeparator.java
index 83b0caf..6a12a80 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/TransformSeparator.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/TransformSeparator.java
@@ -97,12 +97,13 @@ public class TransformSeparator {
     private final MathTransformsOrFactory factory;
 
     /**
-     * Whether to remove unused source dimensions. If {@code true}, then {@link #separate()}
will try to
-     * reduce the set of source dimensions to the smallest set required for computing the
target dimensions.
+     * Whether {@link #sourceDimensions} have been specified explicitly. If {@code false},
then {@link #separate()}
+     * will try to reduce the set of source dimensions to the smallest set required for computing
the target dimensions.
      *
-     * @see #getTrimSourceDimensions()
+     * <p>The default value is {@code false}. The value become {@code true} if the
user specified explicitly the desired
+     * source dimensions, in which case removing source dimensions become disallowed.</p>
      */
-    private boolean trimSourceDimensions;
+    private boolean isSourceSpecified;
 
     /**
      * Constructs a separator for the given transform.
@@ -127,15 +128,14 @@ public class TransformSeparator {
 
     /**
      * Resets this transform separator in the same state than after construction. This method
clears any
-     * {@linkplain #getSourceDimensions() source dimensions} and {@linkplain #getTargetDimensions()
target dimensions}
-     * settings together with the {@linkplain #trimSourceDimensions trim source dimensions}
flag.
+     * {@linkplain #getSourceDimensions() source dimensions} and {@linkplain #getTargetDimensions()
target dimensions} settings.
      * This method can be invoked when the same {@code MathTransform} needs to be separated
in more than one part,
      * for example an horizontal and a vertical component.
      */
     public void clear() {
-        sourceDimensions = null;
-        targetDimensions = null;
-        trimSourceDimensions = false;
+        sourceDimensions  = null;
+        targetDimensions  = null;
+        isSourceSpecified = false;
     }
 
     /**
@@ -254,6 +254,7 @@ public class TransformSeparator {
     public void addSourceDimensions(final int... dimensions) throws IllegalArgumentException
{
         ArgumentChecks.ensureNonNull("dimensions", dimensions);
         sourceDimensions = add(sourceDimensions, dimensions, transform.getSourceDimensions());
+        isSourceSpecified = true;
     }
 
     /**
@@ -267,6 +268,7 @@ public class TransformSeparator {
      */
     public void addSourceDimensionRange(final int lower, final int upper) throws IllegalArgumentException
{
         sourceDimensions = add(sourceDimensions, lower, upper, transform.getSourceDimensions());
+        isSourceSpecified = true;
     }
 
     /**
@@ -276,17 +278,18 @@ public class TransformSeparator {
      * <ol class="verbose">
      *   <li>Source dimensions have been explicitly set by at least one call to {@link
#addSourceDimensions(int...)}
      *       or {@link #addSourceDimensionRange(int, int)} since construction or since last
call to {@link #clear()}.
-     *       In such case, this method returns all specified source dimensions if {@link
#getTrimSourceDimensions()}
-     *       is {@code false}, or a subset of the specified source dimensions if {@code getTrimSourceDimensions()}
-     *       is {@code true} and {@link #separate()} has been invoked.</li>
+     *       In such case, this method returns all specified source dimensions.</li>
      *
      *   <li>No source dimensions were set but {@link #separate()} has been invoked.
      *       In such case, this method returns the sequence of source dimensions that {@code
separate()} chooses to retain.
-     *       It is often, but not necessarily, all source dimensions of the transform given
at construction time.</li>
+     *       It may be all source dimensions of the transform given at construction time,
but not necessarily.</li>
      *
      *   <li>Otherwise an exception is thrown.</li>
      * </ol>
      *
+     * If source dimensions have not been set explicitly, {@code TransformSeparator} tries
to reduce
+     * the set of source dimensions to the smallest set required for computing the target
dimensions.
+     *
      * @return the input dimension as a sequence of strictly increasing values.
      * @throws IllegalStateException if input dimensions have not been set and
      *         {@link #separate()} has not yet been invoked.
@@ -360,41 +363,15 @@ public class TransformSeparator {
     }
 
     /**
-     * Returns whether to remove unused source dimensions. If {@code true}, then {@link #separate()}
will try
-     * to reduce the set of source dimensions to the smallest set required for computing
the target dimensions.
-     * The default value is {@code false}.
-     *
-     * @return whether to remove unused source dimensions after transform separation.
-     *
-     * @since 1.0
-     */
-    public boolean getTrimSourceDimensions() {
-        return trimSourceDimensions;
-    }
-
-    /**
-     * Sets whether to remove unused source dimensions.
-     * The default value is {@code false}.
-     *
-     * @param trim whether to remove unused source dimensions after transform separation.
-     *
-     * @since 1.0
-     */
-    public void setTrimSourceDimensions(final boolean trim) {
-        trimSourceDimensions = trim;
-    }
-
-    /**
      * Separates the math transform specified at construction time for given dimension indices.
      * This method creates a math transform that use only the {@linkplain #addSourceDimensions(int...)
specified
      * source dimensions} and return only the {@linkplain #addTargetDimensions(int...) specified
target dimensions}.
      * If the source or target dimensions were not specified, then they will be inferred
as below:
      *
      * <ul class="verbose">
-     *   <li>If source dimensions were unspecified, then the returned transform will
keep at least all source
-     *       dimensions needed for computing the specified target dimensions. In many cases
the returned transform
-     *       unconditionally keep all source dimensions, but not necessarily. If all source
dimensions need to be
-     *       kept, it is better to {@linkplain #addSourceDimensionRange(int, int) specify
that explicitly}.</li>
+     *   <li>If source dimensions were unspecified, then the returned transform will
keep only the source dimensions
+     *       needed for computing the specified target dimensions. If all source dimensions
need to be kept,
+     *       then they should be {@linkplain #addSourceDimensionRange(int, int) specified
explicitly}.</li>
      *
      *   <li>If target dimensions were unspecified, then the returned transform will
expect only the specified
      *       source dimensions as inputs, and the target dimensions will be inferred automatically.</li>
@@ -458,7 +435,7 @@ public class TransformSeparator {
             expected = targetDimensions.length;
             actual   = tr.getTargetDimensions();
             if (actual == expected) {
-                if (trimSourceDimensions) {
+                if (!isSourceSpecified) {
                     tr = removeUnusedSourceDimensions(tr);
                 }
                 return tr;
@@ -713,7 +690,7 @@ reduce:     for (int j=0; j <= numTgt; j++) {
 
     /**
      * Removes the sources dimensions that are not required for computing the target dimensions.
-     * This method is invoked only if {@link #trimSourceDimensions} is {@code true}.
+     * This method is invoked only if {@link #isSourceSpecified} is {@code false}.
      * This method can operate only on the first transform of a transformation chain.
      * If this method succeed, then {@link #sourceDimensions} will be updated.
      *
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TransformSeparatorTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TransformSeparatorTest.java
index d9c38c7..6793ab5 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TransformSeparatorTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TransformSeparatorTest.java
@@ -141,6 +141,7 @@ public final strictfp class TransformSeparatorTest extends TestCase {
         });
         s.clear();
         s.addTargetDimensions(0, 2);
+        s.addSourceDimensionRange(0, 3);
         assertMatrixEquals("transform", matrix, ((LinearTransform) s.separate()).getMatrix(),
STRICT);
         assertArrayEquals("sourceDimensions", new int[] {0, 1, 2}, s.getSourceDimensions());
         assertArrayEquals("targetDimensions", new int[] {0, 2},    s.getTargetDimensions());
@@ -263,6 +264,7 @@ public final strictfp class TransformSeparatorTest extends TestCase {
         });
         s.clear();
         s.addTargetDimensions(1, 2, 7);
+        s.addSourceDimensionRange(0, 7);
         MathTransform result = s.separate();
         assertArrayEquals("sourceDimensions", new int[] {0, 1, 2, 3, 4, 5, 6}, s.getSourceDimensions());
         assertArrayEquals("targetDimensions", new int[] {1, 2, 7}, s.getTargetDimensions());
@@ -280,6 +282,7 @@ public final strictfp class TransformSeparatorTest extends TestCase {
         });
         s.clear();
         s.addTargetDimensions(1, 5, 7);
+        s.addSourceDimensionRange(0, 7);
         result = s.separate();
         assertArrayEquals ("sourceDimensions", new int[] {0, 1, 2, 3, 4, 5, 6}, s.getSourceDimensions());
         assertArrayEquals ("targetDimensions", new int[] {1, 5, 7}, s.getTargetDimensions());
@@ -413,13 +416,13 @@ public final strictfp class TransformSeparatorTest extends TestCase
{
     }
 
     /**
-     * Tests {@link TransformSeparator#getTrimSourceDimensions()}.
+     * Tests {@link TransformSeparator} with removal of unused source dimensions.
      *
      * @throws FactoryException if an error occurred while creating a new transform.
      */
     @Test
     @DependsOnMethod("testLinearTransform")
-    public void testGetTrimSourceDimensions() throws FactoryException {
+    public void testTrimSourceDimensions() throws FactoryException {
         MathTransform tr = MathTransforms.linear(Matrices.create(3, 4, new double[] {
             0,   0.5, 0,  -90,
             0.5, 0,   0, -180,
@@ -428,7 +431,7 @@ public final strictfp class TransformSeparatorTest extends TestCase {
          * Verify that TransformSeparator does not trim anything if not requested so.
          */
         TransformSeparator s = new TransformSeparator(tr);
-        assertFalse("trimSourceDimensions", s.getTrimSourceDimensions());
+        s.addSourceDimensionRange(0, tr.getSourceDimensions());
         assertSame("No source dimensions should be trimmed if not requested.", tr, s.separate());
         assertArrayEquals(new int[] {0, 1, 2}, s.getSourceDimensions());
         assertArrayEquals(new int[] {0, 1   }, s.getTargetDimensions());
@@ -439,8 +442,7 @@ public final strictfp class TransformSeparatorTest extends TestCase {
             0,   0.5, -90,
             0.5, 0,  -180,
             0,   0,     1);
-        s.setTrimSourceDimensions(true);
-        assertTrue("trimSourceDimensions", s.getTrimSourceDimensions());
+        s.clear();
         MathTransform reduced = s.separate();
         assertNotEquals("separate()", tr, reduced);
         assertArrayEquals(new int[] {0, 1}, s.getSourceDimensions());
@@ -455,7 +457,6 @@ public final strictfp class TransformSeparatorTest extends TestCase {
             0, 0,   0,     1}));
 
         s = new TransformSeparator(tr);
-        s.setTrimSourceDimensions(true);
         reduced = s.separate();
         assertNotEquals("separate()", tr, reduced);
         assertArrayEquals(new int[] {1, 2}, s.getSourceDimensions());


Mime
View raw message