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 65a4ca1 Add a GridRoundingMode.CONTAINED for completness.
65a4ca1 is described below
commit 65a4ca1f6f6ba7446d59da713c0ecbb6e037d70e
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Jun 3 00:16:55 2020 +0200
Add a GridRoundingMode.CONTAINED for completness.
---
.../apache/sis/coverage/grid/GridDerivation.java | 1 +
.../org/apache/sis/coverage/grid/GridExtent.java | 13 +++++++++++
.../apache/sis/coverage/grid/GridRoundingMode.java | 25 ++++++++++++++++++++--
.../sis/coverage/grid/ResampledGridCoverage.java | 4 ++--
4 files changed, 39 insertions(+), 4 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 39e9bf6..2d21a2c 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
@@ -1012,6 +1012,7 @@ public class GridDerivation {
switch (rounding) {
default: throw new AssertionError(rounding);
case NEAREST: s = (int) Math.min(Math.round(scales[i]), Integer.MAX_VALUE);
break;
+ case CONTAINED: // Assume user wants more data in source (ENCLOSING)
or target (CONTAINED) grid.
case ENCLOSING: s = (int) Math.nextUp(scales[i]); break;
}
subsamplings[i] = Math.max(1, s);
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
index fa98774..c837147 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
@@ -416,6 +416,19 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
if (lower != upper) upper--; // For making
the coordinate inclusive.
break;
}
+ case CONTAINED: {
+ final double lo = Math.ceil (min);
+ final double hi = Math.floor(max);
+ if (lo > hi) {
+ lower = (long) ((lo - min > max - hi) ? hi : lo); // Take
the value closest to integer.
+ upper = lower;
+ } else {
+ lower = (long) lo;
+ upper = (long) hi;
+ if (lower != upper) upper--; // For making
the coordinate inclusive.
+ }
+ break;
+ }
case NEAREST: {
lower = Math.round(min);
upper = Math.round(max);
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridRoundingMode.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridRoundingMode.java
index 529f43d..14e80ac 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridRoundingMode.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridRoundingMode.java
@@ -24,7 +24,7 @@ package org.apache.sis.coverage.grid;
* {@linkplain GridExtent#getSize(int) size} integer values.
*
* @author Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.1
* @since 1.0
* @module
*/
@@ -59,6 +59,27 @@ public enum GridRoundingMode {
* <li>Grid {@linkplain GridExtent#getLow(int) low} are converted to integers
with {@link Math#floor(double)}.</li>
* <li>Grid {@linkplain GridExtent#getHigh(int) high} are converted to integers
with {@link Math#ceil(double)}.</li>
* </ul>
+ *
+ * In operations receiving grid coverages as inputs and producing grid coverages as outputs,
+ * this rounding mode is convenient for computing the <em>inputs</em> extent
because it gives
+ * an extent large enough for providing data in the whole region to be computed.
+ */
+ ENCLOSING,
+
+ /**
+ * Converts grid low and high to values that are fully contained in the envelope.
+ * This mode applies the following steps:
+ *
+ * <ul>
+ * <li>Grid {@linkplain GridExtent#getLow(int) low} are converted to integers
with {@link Math#ceil(double)}.</li>
+ * <li>Grid {@linkplain GridExtent#getHigh(int) high} are converted to integers
with {@link Math#floor(double)}.</li>
+ * </ul>
+ *
+ * In operations receiving grid coverages as inputs and producing grid coverages as outputs,
+ * this rounding mode is convenient for computing the <em>outputs</em> extent
because it gives
+ * an extent small enough for allowing inputs to provide data in the whole region.
+ *
+ * @since 1.1
*/
- ENCLOSING
+ CONTAINED
}
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ResampledGridCoverage.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ResampledGridCoverage.java
index c2d14d0..9f8474d 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ResampledGridCoverage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ResampledGridCoverage.java
@@ -400,8 +400,8 @@ final class ResampledGridCoverage extends GridCoverage {
*
* <div class="note"><b>Note on rounding mode:</b>
* calculation of source envelope should use {@link GridRoundingMode#ENCLOSING} for making
sure that we include
- * all needed data. On the opposite, calculation of target envelope should use a "fully
included" rounding mode
- * for making sure that we interpolate only values where data are available. However
such "fully included" mode
+ * all needed data. On the opposite, calculation of target envelope should use {@link
GridRoundingMode#CONTAINED}
+ * for making sure that we interpolate only values where data are available. However
such "fully contained" mode
* is often overly strict because a very small rounding error can cause the lost of an
image row or column,
* while using extrapolations for those values produce no perceptible errors. Consequently
this method uses
* {@link GridRoundingMode#NEAREST} as a compromise.</div>
|