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: Center the image.
Date Wed, 04 Mar 2020 13:40:10 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 8f5c507  Center the image.
8f5c507 is described below

commit 8f5c5076edf0a38cbb93e6a17693e44c23060512
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Mar 4 14:39:30 2020 +0100

    Center the image.
---
 .../org/apache/sis/gui/coverage/CoverageView.java  |  6 ++--
 .../sis/referencing/operation/matrix/Matrices.java | 36 +++++++++++++++++-----
 2 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageView.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageView.java
index 57b1a40..5499897 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageView.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageView.java
@@ -42,6 +42,7 @@ import org.apache.sis.coverage.grid.GridGeometry;
 import org.apache.sis.internal.gui.ImageRenderings;
 import org.apache.sis.internal.map.RenderException;
 import org.apache.sis.gui.map.MapCanvas;
+import org.apache.sis.geometry.Envelope2D;
 import org.apache.sis.util.collection.BackingStoreException;
 import org.apache.sis.referencing.operation.matrix.Matrices;
 import org.apache.sis.referencing.operation.matrix.MatrixSIS;
@@ -383,8 +384,9 @@ final class CoverageView extends MapCanvas {
             }
             LinearTransform tr;
             if (bounds != null) {
-                final MatrixSIS m = Matrices.createTransform(bounds, getDisplayBounds());
-                Matrices.forceUniformScale(m, 0);
+                final Envelope2D db = getDisplayBounds();
+                final MatrixSIS m = Matrices.createTransform(bounds, db);
+                Matrices.forceUniformScale(m, 0, new double[] {db.width / 2, db.height /
2});
                 tr = MathTransforms.linear(m);
             } else {
                 tr = MathTransforms.identity(ImageLoader.BIDIMENSIONAL);
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
index aefa7dc..a69d52d 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
@@ -824,20 +824,39 @@ public final class Matrices extends Static {
      *       {@linkplain MathFunctions#magnitude(double...) magnitude}.</li>
      * </ul>
      *
-     * The scale factors are adjusted for the smallest magnitude if {@code sp} is 0, the
largest magnitude
-     * if {@code sp} is 1, or an intermediate value if {@code sp} has any value between 0
and 1.
+     * The coefficients are multiplied by factors which result in the smallest magnitude
if {@code selector} is 0,
+     * the largest magnitude if {@code selector} is 1, or an intermediate value if {@code
selector} is any value
+     * between 0 and 1. In the common case where the matrix has no rotation and no shear
terms, the magnitude is
+     * directly the scale factors on the matrix diagonal and {@code selector=0} sets all
those scales to the smallest
+     * value while {@code selector=1} sets all those scales to the largest value (ignoring
sign).
      *
-     * @param  matrix  the matrix in which to uniformize scale factors. Will be modified
in-place.
-     * @param  sp      0 for smallest magnitude, 1 for largest magnitude, or any intermediate
value.
+     * <p>Translation terms can be compensated for scale changes if the {@code shift}
argument is non-null.
+     * The {@code shift} values should be proportional to {@linkplain Envelope#getSpan(int)
envelope spans}.
+     * For example if the matrix is for transforming coordinates to a screen device, then:</p>
+     *
+     * <ul>
+     *   <li>{@code shift[i] = 0} will keep translation term unchanged in the dimension
<var>i</var>.
+     *       For rendering on screen, it means that the image will stay on the left border
(<var>i</var> = 0)
+     *       or upper border (<var>i</var> = 1).</li>
+     *   <li>{@code shift[i] = span} where {@code span} is the window width (<var>i</var> = 0)
or height
+     *       (<var>i</var> = 1) will translate the image to the right border
or to the bottom border respectively.</li>
+     *   <li>{@code shift[i] = span / 2} where {@code span} is as above will translate
the image to the window center.</li>
+     *   <li>Any intermediate values are allowed.</li>
+     * </ul>
+     *
+     * @param  matrix    the matrix in which to uniformize scale factors. Will be modified
in-place.
+     * @param  selector  a value between 0 for smallest scale magnitude and 1 for largest
scale magnitude (inclusive).
+     * @param  shift     compensation for the translation terms, or {@code null} if none.
      * @return {@code true} if the given matrix changed as a result of this method call.
      *
      * @since 1.1
      */
-    public static boolean forceUniformScale(final Matrix matrix, final double sp) {
+    public static boolean forceUniformScale(final Matrix matrix, final double selector, final
double[] shift) {
         ArgumentChecks.ensureNonNull("matrix", matrix);
-        ArgumentChecks.ensureBetween("sp", 0, 1, sp);
+        ArgumentChecks.ensureBetween("selector", 0, 1, selector);
         final int srcDim = matrix.getNumCol() - 1;
         final int tgtDim = matrix.getNumRow() - 1;
+        ArgumentChecks.ensureDimensionMatches("shift", tgtDim, shift);
         final double[] row = new double[srcDim];
         final double[] mgn = new double[tgtDim];
         double min = Double.POSITIVE_INFINITY;
@@ -853,7 +872,7 @@ public final class Matrices extends Static {
         }
         boolean changed = false;
         if (min < max) {
-            final double scale = (1 - sp)*min + sp*max;
+            final double scale = (1 - selector)*min + selector*max;
             for (int j=0; j<tgtDim; j++) {
                 final double rescale = scale / mgn[j];
                 for (int i=0; i<srcDim; i++) {
@@ -861,6 +880,9 @@ public final class Matrices extends Static {
                     changed |= (e != (e *= rescale));
                     matrix.setElement(j, i, e);
                 }
+                double e = matrix.getElement(j, srcDim);
+                changed |= (e != (e += shift[j] * (1 - rescale)));
+                matrix.setElement(j, srcDim, e);
             }
         }
         return changed;


Mime
View raw message