sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 03/03: Initialize LocalizationGridBuilder in a more efficient way.
Date Thu, 07 Feb 2019 15:56:44 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 db4eba6f22646e492a97142db6a7771b179c729b
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Thu Feb 7 16:01:25 2019 +0100

    Initialize LocalizationGridBuilder in a more efficient way.
---
 .../operation/builder/LinearTransformBuilder.java  | 28 +++++++++++++++++++++-
 .../operation/builder/LocalizationGridBuilder.java | 14 +++++++++++
 .../java/org/apache/sis/internal/netcdf/Axis.java  | 11 +--------
 3 files changed, 42 insertions(+), 11 deletions(-)

diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java
index 972f768..0a69897 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java
@@ -107,7 +107,7 @@ public class LinearTransformBuilder extends TransformBuilder {
     private double[][] targets;
 
     /**
-     * The product of all {@link #gridSize} values, or 0 if none if {@link #gridSize} is
null.
+     * The product of all {@link #gridSize} values, or 0 if none or if {@link #gridSize}
is null.
      * If non-zero, then this is the length of {@link #targets} arrays to create.
      */
     final int gridLength;
@@ -894,6 +894,32 @@ search:         for (int j=domain(); --j >= 0;) {
     }
 
     /**
+     * Sets all control points. This method can be invoked only for points on a grid.
+     * The length of given vectors must be equal to the total number of cells in the grid.
+     * The first vector provides the <var>x</var> coordinates; the second vector
provides the <var>y</var> coordinates,
+     * <i>etc.</i>. Coordinates are stored in row-major order (column index varies
faster, followed by row index).
+     *
+     * @param  coordinates coordinates in each target dimensions, stored in row-major order.
+     */
+    final void setControlPoints(final Vector... coordinates) {
+        assert gridSize != null;
+        final int tgtDim = coordinates.length;
+        final double[][] result = new double[tgtDim][];
+        for (int i=0; i<tgtDim; i++) {
+            final Vector c = coordinates[i];
+            ArgumentChecks.ensureNonNullElement("coordinates", i, c);
+            final int size = c.size();
+            if (size != gridLength) {
+                throw new IllegalArgumentException(Errors.format(Errors.Keys.UnexpectedArrayLength_2,
gridLength, size));
+            }
+            result[i] = c.doubleValues();
+        }
+        targets     = result;
+        transform   = null;
+        correlation = null;
+    }
+
+    /**
      * More straightforward version of {@link #getControlPoint(int[])} for the case where
this
      * {@code LinearTransformBuilder} is known to have been built for grid source coordinates.
      * This method is for {@link LocalizationGridBuilder#create(MathTransformFactory)} internal
usage.
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilder.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilder.java
index f940417..b43a0c2 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilder.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilder.java
@@ -346,6 +346,20 @@ public class LocalizationGridBuilder extends TransformBuilder {
     }
 
     /**
+     * Sets all control points. The length of given vectors must be equal to the total number
of cells in the grid.
+     * The first vector provides the <var>x</var> coordinates; the second vector
provides the <var>y</var> coordinates,
+     * <i>etc.</i>. Coordinates are stored in row-major order (column index varies
faster, followed by row index).
+     *
+     * @param  coordinates coordinates in each target dimensions, stored in row-major order.
+     *
+     * @since 1.0
+     */
+    public void setControlPoints(final Vector... coordinates) {
+        ArgumentChecks.ensureNonNull("coordinates", coordinates);
+        linear.setControlPoints(coordinates);
+    }
+
+    /**
      * Sets a single matching control point pair. Source position is assumed precise and
target position is assumed uncertain.
      * If the given source position was already associated with another target position,
then the old target position is discarded.
      *
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
index 4485dda..d0ebae9 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
@@ -607,16 +607,7 @@ main:   switch (getDimension()) {
                     final LocalizationGridBuilder grid = new LocalizationGridBuilder(width,
height);
                     final Vector vx =  this.read();
                     final Vector vy = other.read();
-                    final double[] target = new double[2];
-                    int index = 0;
-                    for (int y=0; y<height; y++) {
-                        for (int x=0; x<width; x++) {
-                            target[0] = vx.doubleValue(index);
-                            target[1] = vy.doubleValue(index);
-                            grid.setControlPoint(x, y, target);
-                            index++;
-                        }
-                    }
+                    grid.setControlPoints(vx, vy);
                     return grid;
                 }
             }


Mime
View raw message