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: Enable testWindowOnImage() in LinearIteratorTest.
Date Wed, 08 May 2019 18:41:21 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 57ad67d  Enable testWindowOnImage() in LinearIteratorTest.
57ad67d is described below

commit 57ad67dc38985bda4daa26110d811507d0228085
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed May 8 20:40:17 2019 +0200

    Enable testWindowOnImage() in LinearIteratorTest.
---
 .../org/apache/sis/image/DefaultIteratorTest.java  | 89 +++++++++++++++++-----
 .../org/apache/sis/image/LinearIteratorTest.java   | 25 ++++--
 2 files changed, 85 insertions(+), 29 deletions(-)

diff --git a/core/sis-raster/src/test/java/org/apache/sis/image/DefaultIteratorTest.java b/core/sis-raster/src/test/java/org/apache/sis/image/DefaultIteratorTest.java
index ad968e4..825307c 100644
--- a/core/sis-raster/src/test/java/org/apache/sis/image/DefaultIteratorTest.java
+++ b/core/sis-raster/src/test/java/org/apache/sis/image/DefaultIteratorTest.java
@@ -241,6 +241,8 @@ public strictfp class DefaultIteratorTest extends TestCase {
      *
      * @param  subArea  the ranges of pixel coordinates in which to iterate.
      * @return sequence of (x,y) tuples inside the given ranges, in the order to be traversed
by the iterator.
+     *
+     * @see #getExpectedWindowValues(Rectangle, float[])
      */
     int[] getCoordinatesInExpectedOrder(final Rectangle subArea) {
         final int[] coordinates = new int[subArea.width * subArea.height * 2];
@@ -268,24 +270,31 @@ public strictfp class DefaultIteratorTest extends TestCase {
      * that the given (x,y) should be the third point in iteration (iteration starts at index
zero).
      * This method must be overridden for each kind of iterator to test.
      *
-     * @param  bounds  the image bounds.
-     * @param  x       <var>x</var> coordinate for which the iterator position
is desired.
-     * @param  y       <var>y</var> coordinate for which the iterator position
is desired.
+     * @param  x  <var>x</var> coordinate for which the iterator position is
desired.
+     * @param  y  <var>y</var> coordinate for which the iterator position is
desired.
      * @return point index in iterator order for the given (x,y) coordinates.
      */
-    int getIndexOf(final Rectangle bounds, int x, int y) {
-        x -= bounds.x;
-        y -= bounds.y;
+    int getIndexOf(int x, int y) {
+        x -= xmin;
+        y -= ymin;
         if (tileWidth == 0 && tileHeight == 0) {
-            return y * bounds.width + x;
+            return y * width + x;
         }
         final int tx = x / tileWidth;
         final int ty = y / tileHeight;
-        final int numTileX = (bounds.width + tileWidth - 1) / tileWidth;
+        final int numTileX = (width + tileWidth - 1) / tileWidth;
         return ((ty * (numTileX - 1) + tx) * tileHeight + y - tx) * tileWidth + x;
     }
 
     /**
+     * Returns the bounds of the image or raster to be tested.
+     * This method is provided for subclasses information purposes.
+     */
+    final Rectangle getImageBounds() {
+        return new Rectangle(xmin, ymin, width, height);
+    }
+
+    /**
      * Returns the expected sequence type. Subclasses may need to override.
      *
      * @param  singleTile  {@code true} if iteration occurs in a single tile, or {@code false} for
the whole image.
@@ -1024,7 +1033,7 @@ public strictfp class DefaultIteratorTest extends TestCase {
          * Compute index of the (x,y) position in the array of expected values.
          * Iteration verification will need to begin at that value.
          */
-        int i = getIndexOf(new Rectangle(xmin, ymin, width, height), x, y) * numBands;
+        int i = getIndexOf(x, y) * numBands;
         /*
          * Iteration verification happens here. Note that contrarily to 'verifyIteration(boolean)'
method,
          * we use a do … while loop instead than a while loop because the call to 'moveTo(x,
y)' should be
@@ -1082,26 +1091,18 @@ public strictfp class DefaultIteratorTest extends TestCase {
     private void verifyWindow(final Dimension window) {
         final PixelIterator.Window<FloatBuffer> w = iterator.createWindow(TransferType.FLOAT);
         final FloatBuffer values = w.values;
-        final int tileSize   = tileWidth * tileHeight;
-        final int tileStride = tileSize * (width / tileWidth);
+        final float[] windowValues = new float[window.width * window.height * numBands];
         while (iterator.next()) {
             final Point pos = iterator.getPosition();
             pos.translate(-xmin, -ymin);
             w.update();
+            getExpectedWindowValues(new Rectangle(pos, window), windowValues);
+            int indexOfExpected = 0;
             for (int y=0; y<window.height; y++) {
-                int p,t;
-                p  = pos.y + y;
-                t  = p / tileHeight;
-                p %=     tileHeight;
-                final int start = t * tileStride + p * tileWidth;
                 for (int x=0; x<window.width; x++) {
-                    p  = pos.x + x;
-                    t  = p / tileWidth;
-                    p %=     tileWidth;
-                    int offset = (start + t * tileSize + p) * numBands;
                     for (int b=0; b<numBands; b++) {
-                        final float e = expected[offset++];
                         final float a = values.get();
+                        final float e = windowValues[indexOfExpected++];
                         if (Float.floatToRawIntBits(a) != Float.floatToRawIntBits(e)) {
                             fail("Index (" + x + ", " + y + ") in window starting at index
("
                                     + pos.x + ", " + pos.y + "), band " + b + ": expected
" + e + " but got " + a);
@@ -1114,6 +1115,52 @@ public strictfp class DefaultIteratorTest extends TestCase {
     }
 
     /**
+     * Returns the values of the given sub-region, organized in a {@link SequenceType#LINEAR}
fashion.
+     * This method is invoked for {@link #verifyWindow(Dimension)} purpose. This method is
responsible
+     * for reordering the {@link #expected} values in a linear order.
+     *
+     * @param  window  the sub-region for which to get values in a linear fashion.
+     * @param  values  where to store the expected window values in linear order.
+     */
+    void getExpectedWindowValues(final Rectangle window, final float[] values) {
+        final int tileSize   = tileWidth * tileHeight;
+        final int tileStride = tileSize * (width / tileWidth);
+        int index = 0;
+        for (int y=0; y<window.height; y++) {
+            int p,t;
+            p  = window.y + y;
+            t  = p / tileHeight;
+            p %=     tileHeight;
+            final int start = t * tileStride + p * tileWidth;
+            for (int x=0; x<window.width; x++) {
+                p  = window.x + x;
+                t  = p / tileWidth;
+                p %=     tileWidth;
+                final int offset = start + t * tileSize + p;
+                copyExpectedPixels(offset, values, index++, 1);
+            }
+        }
+        assertEquals(values.length, index * numBands);
+    }
+
+    /**
+     * Copies the expected values of all bands of pixels starting at the given index.
+     * The index arguments are indices of the points (not the indices of sample values);
+     * the number of bands will be multiplied to all given arguments.
+     *
+     * <p>This is a helper method for {@link #getExpectedWindowValues(Rectangle, float[])}
+     * implementation by subclasses.</p>
+     *
+     * @param  srcPts       index of the first pixel to copy.
+     * @param  destination  where to copy pixel values.
+     * @param  dstPts       index of the first pixel to write in the destination array.
+     * @param  numPixels    number of pixels to write.
+     */
+    final void copyExpectedPixels(final int srcPts, final float[] destination, final int
dstPts, final int numPixels) {
+        System.arraycopy(expected, srcPts * numBands, destination, dstPts * numBands, numPixels
* numBands);
+    }
+
+    /**
      * Tests {@link PixelIterator#createWindow(TransferType)} on a single tile.
      */
     @Test
diff --git a/core/sis-raster/src/test/java/org/apache/sis/image/LinearIteratorTest.java b/core/sis-raster/src/test/java/org/apache/sis/image/LinearIteratorTest.java
index b355c7f..99f9f93 100644
--- a/core/sis-raster/src/test/java/org/apache/sis/image/LinearIteratorTest.java
+++ b/core/sis-raster/src/test/java/org/apache/sis/image/LinearIteratorTest.java
@@ -22,8 +22,6 @@ import java.awt.image.DataBuffer;
 import java.awt.image.WritableRaster;
 import java.awt.image.WritableRenderedImage;
 import org.opengis.coverage.grid.SequenceType;
-import org.junit.Ignore;
-import org.junit.Test;
 
 import static org.junit.Assert.*;
 
@@ -71,13 +69,13 @@ public final strictfp class LinearIteratorTest extends DefaultIteratorTest
{
      * that the given (x,y) should be the third point in iteration (iteration starts at index
zero).
      * This method must be overridden for each kind of iterator to test.
      *
-     * @param  bounds  the image bounds.
      * @param  x       <var>x</var> coordinate for which the iterator position
is desired.
      * @param  y       <var>y</var> coordinate for which the iterator position
is desired.
      * @return point index in iterator order for the given (x,y) coordinates.
      */
     @Override
-    int getIndexOf(final Rectangle bounds, int x, int y) {
+    int getIndexOf(int x, int y) {
+        final Rectangle bounds = getImageBounds();
         x -= bounds.x;
         y -= bounds.y;
         return y * bounds.width + x;
@@ -124,11 +122,22 @@ public final strictfp class LinearIteratorTest extends DefaultIteratorTest
{
     }
 
     /**
-     * Tests {@link PixelIterator#createWindow(TransferType)} on a tiled image.
+     * Returns the values of the given sub-region, organized in a {@link SequenceType#LINEAR}
fashion.
+     * This method is invoked for {@link #verifyWindow(Dimension)} purpose.
+     *
+     * @param  window  the sub-region for which to get values in a linear fashion.
+     * @param  values  where to store the expected window values in linear order.
      */
-    @Test
     @Override
-    @Ignore("TODO")
-    public void testWindowOnImage() {
+    void getExpectedWindowValues(final Rectangle window, final float[] values) {
+        final Rectangle bounds = getImageBounds();
+        int index = 0;
+        int source = window.x + window.y * bounds.width;
+        for (int y=0; y<window.height; y++) {
+            final int length = window.width;
+            copyExpectedPixels(source, values, index, length);
+            source += bounds.width;
+            index += length;
+        }
     }
 }


Mime
View raw message