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: Change the API in the GridCoverage method returning a RenderedImage. We need a way to specify which two-dimensional slice is desired.
Date Tue, 11 Dec 2018 20:59:07 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 30ea394  Change the API in the GridCoverage method returning a RenderedImage. We
need a way to specify which two-dimensional slice is desired.
30ea394 is described below

commit 30ea3940209c09c78e30acc4e51e0776d51b22bf
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Dec 11 21:58:36 2018 +0100

    Change the API in the GridCoverage method returning a RenderedImage. We need a way to
specify which two-dimensional slice is desired.
---
 .../org/apache/sis/coverage/grid/GridCoverage.java | 34 ++++++++++++++++++----
 .../org/apache/sis/util/collection/Containers.java | 16 ++++------
 .../java/org/apache/sis/storage/netcdf/Image.java  | 17 ++++-------
 3 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java
index 300de53..d9eef03 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java
@@ -19,6 +19,9 @@ package org.apache.sis.coverage.grid;
 import java.util.List;
 import java.util.Collection;
 import java.awt.image.RenderedImage;
+import org.opengis.geometry.DirectPosition;
+import org.opengis.coverage.CannotEvaluateException;
+import org.opengis.coverage.PointOutsideCoverageException;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.apache.sis.internal.util.UnmodifiableArrayList;
 import org.apache.sis.coverage.SampleDimension;
@@ -103,14 +106,33 @@ public abstract class GridCoverage {
     }
 
     /**
-     * Returns a two-dimensional slice of grid data as a rendered image.
-     * This method tries to return a view as much as possible (i.e. sample values are not
copied).
+     * Returns a two-dimensional slice of grid data as a rendered image. The given {@code
slicePoint} argument specifies
+     * the coordinates of the slice in all dimensions that are not in the two-dimensional
image. For example if this grid
+     * coverage has (<var>x</var>, <var>y</var>, <var>z</var>,
<var>t</var>) dimensions and we want a rendered image of
+     * data in the (<var>x</var>, <var>y</var>) dimensions, then
the given {@code slicePoint} shall contain the
+     * (<var>z</var>, <var>t</var>) coordinates of the desired slice.
The two coordinates of the data to be shown
+     * (<var>x</var> and <var>y</var> in our example) shall be excluded
from the slice point in one of the following ways:
      *
-     * @param  xAxis  dimension to use for <var>x</var> axis.
-     * @param  yAxis  dimension to use for <var>y</var> axis.
-     * @return the grid data as a rendered image in the given CRS dimensions.
+     * <ul>
+     *   <li>The {@code slicePoint} has a CRS with two dimensions less than this grid
coverage CRS.</li>
+     *   <li>The {@code slicePoint} has the same CRS than this grid coverage, but the
two coordinates to
+     *       exclude are set to {@link Double#NaN}.</li>
+     * </ul>
+     *
+     * If the {@code slicePoint} CRS is different than this grid coverage CRS (except for
the number of dimensions),
+     * a coordinate transformation will be applied. If the {@code slicePoint} CRS is {@code
null}, it is assumed the
+     * same than this grid coverage CRS. If this grid coverage is two-dimensional or can
render only one image for
+     * other reason, then the {@code slicePoint} can be null.
+     *
+     * <p>Implementations should return a view as much as possible, without copying
sample values.</p>
+     *
+     * @param  slicePoint  coordinates of the slice in all dimensions other than the two
dimensions to be shown on the image.
+     *         May be {@code null} if this coverage can render only one image, for example
because its CRS is two-dimensional.
+     * @return the grid slice as a rendered image.
+     * @throws PointOutsideCoverageException if the given slice point is illegal.
+     * @throws CannotEvaluateException if this method can not produce the render image for
another reason.
      */
-    public abstract RenderedImage asRenderedImage(int xAxis, int yAxis);
+    public abstract RenderedImage render(DirectPosition slicePoint) throws CannotEvaluateException;
 
     /**
      * Returns a string representation of this grid coverage for debugging purpose.
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/collection/Containers.java
b/core/sis-utility/src/main/java/org/apache/sis/util/collection/Containers.java
index 5bdce5a..d285af8 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/collection/Containers.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/collection/Containers.java
@@ -263,17 +263,11 @@ public final class Containers extends Static {
      * @return the minimal initial capacity to be given to the hash map constructor.
      */
     public static int hashMapCapacity(final int count) {
-        if (count > 0) {
-            /*
-             * Dividing 'count' by 0.75 is equivalent to multiplying by 1.333333…
-             */
-            int r = count / 3;
-            if ((count % 3) != 0) {
-                r++;
-            }
-            return count + r;
-        }
-        return 0;
+        /*
+         * Dividing 'count' by 0.75 is equivalent to multiplying by 1.333333…
+         * rounded to next integer.
+         */
+        return (count * 4 + 2) / 3;
     }
 
     /**
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/Image.java b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/Image.java
index d539b12..c63e18f 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/Image.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/Image.java
@@ -23,6 +23,7 @@ import java.awt.image.ColorModel;
 import java.awt.image.BufferedImage;
 import java.awt.image.RenderedImage;
 import java.awt.image.WritableRaster;
+import org.opengis.geometry.DirectPosition;
 import org.apache.sis.coverage.SampleDimension;
 import org.apache.sis.coverage.grid.GridCoverage;
 import org.apache.sis.coverage.grid.GridGeometry;
@@ -60,20 +61,14 @@ final class Image extends GridCoverage {
 
     /**
      * Returns a two-dimensional slice of grid data as a rendered image.
-     * This method tries to return a view as much as possible (i.e. sample values are not
copied).
-     *
-     * @param  xAxis  dimension to use for <var>x</var> axis.
-     * @param  yAxis  dimension to use for <var>y</var> axis.
-     * @return the grid data as a rendered image in the given CRS dimensions.
+     * This returns a view as much as possible; sample values are not copied.
      */
     @Override
-    public RenderedImage asRenderedImage(final int xAxis, final int yAxis) {
-        if (xAxis != 0 || yAxis != 1) {
-            throw new IllegalArgumentException();       // TODO
-        }
+    public RenderedImage render(final DirectPosition slicePoint) {
+        // TODO: use slicePoint.
         final GridExtent extent = getGridGeometry().getExtent();
-        final int width  = Math.toIntExact(extent.getSize(xAxis));
-        final int height = Math.toIntExact(extent.getSize(yAxis));
+        final int width  = Math.toIntExact(extent.getSize(0));
+        final int height = Math.toIntExact(extent.getSize(1));
         final WritableRaster raster = RasterFactory.createBandedRaster(data, width, height,
width, null, null, null);
         final ColorModel colors = ColorModelFactory.createColorModel(getSampleDimensions(),
VISIBLE_BAND, data.getDataType(),
                 (category) -> category.isQuantitative() ? new Color[] {Color.BLACK, Color.WHITE}
: null);


Mime
View raw message