sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 03/03: Use "stretching" for the name of operation that fit a color ramp to a given range of values. It seems to be the word used by ESRI.
Date Mon, 04 May 2020 16:05:16 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 df4585dd99adb3e5cc46d5e2bbeded8440e7a6df
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon May 4 17:40:01 2020 +0200

    Use "stretching" for the name of operation that fit a color ramp to a given range of values.
It seems to be the word used by ESRI.
---
 .../apache/sis/gui/coverage/CoverageCanvas.java    | 41 +++++++++++-----------
 .../apache/sis/gui/coverage/CoverageControls.java  |  7 ++--
 .../coverage/{RangeType.java => Stretching.java}   | 29 +++++++++------
 .../apache/sis/internal/gui/ImageRenderings.java   | 25 +++++++++----
 .../org/apache/sis/internal/gui/Resources.java     |  7 +---
 .../apache/sis/internal/gui/Resources.properties   |  1 -
 .../sis/internal/gui/Resources_fr.properties       |  1 -
 .../java/org/apache/sis/image/ImageProcessor.java  | 16 ++++-----
 .../org/apache/sis/util/resources/Vocabulary.java  | 10 ++++++
 .../sis/util/resources/Vocabulary.properties       |  2 ++
 .../sis/util/resources/Vocabulary_fr.properties    |  2 ++
 11 files changed, 84 insertions(+), 57 deletions(-)

diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java
index 769b90d..d38fba4 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java
@@ -78,16 +78,16 @@ public class CoverageCanvas extends MapCanvasAWT {
     /**
      * Different ways to represent the data. The {@link #data} field shall be one value from
this map.
      *
-     * @see #setImage(RangeType, RenderedImage)
+     * @see #setImage(Stretching, RenderedImage)
      */
-    private final EnumMap<RangeType,RenderedImage> dataAlternatives;
+    private final EnumMap<Stretching,RenderedImage> dataAlternatives;
 
     /**
      * Key of the currently selected alternative in {@link #dataAlternatives} map.
      *
-     * @see #setImage(RangeType, RenderedImage)
+     * @see #setImage(Stretching, RenderedImage)
      */
-    private RangeType currentDataAlternative;
+    private Stretching currentDataAlternative;
 
     /**
      * The data to show, or {@code null} if not yet specified. This image may be tiled,
@@ -110,8 +110,8 @@ public class CoverageCanvas extends MapCanvasAWT {
         super(Locale.getDefault());
         coverageProperty       = new SimpleObjectProperty<>(this, "coverage");
         sliceExtentProperty    = new SimpleObjectProperty<>(this, "sliceExtent");
-        dataAlternatives       = new EnumMap<>(RangeType.class);
-        currentDataAlternative = RangeType.DECLARED;
+        dataAlternatives       = new EnumMap<>(Stretching.class);
+        currentDataAlternative = Stretching.NONE;
         coverageProperty   .addListener((p,o,n) -> onImageSpecified());
         sliceExtentProperty.addListener((p,o,n) -> onImageSpecified());
     }
@@ -121,7 +121,7 @@ public class CoverageCanvas extends MapCanvasAWT {
      * {@link #dataAlternatives} map. All alternative images are computed from this source.
      */
     private RenderedImage getSourceData() {
-        return dataAlternatives.get(RangeType.DECLARED);
+        return dataAlternatives.get(Stretching.NONE);
     }
 
     /**
@@ -220,32 +220,33 @@ public class CoverageCanvas extends MapCanvasAWT {
     }
 
     /**
-     * Invoked when the user selected a new range of values to scale. Also invoked {@linkplain
#onImageSpecified after
+     * Invoked when the user selected a new color stretching mode. Also invoked {@linkplain
#onImageSpecified after
      * loading a new image or a new slice} for switching the new image to the same type of
range as previously selected.
      * If the image for the specified type is not already available, then this method computes
the image in a background
      * thread and refreshes the view after the computation completed.
      */
-    final void setRangeType(final RangeType rangeType) {
-        currentDataAlternative = rangeType;
-        final RenderedImage alt = dataAlternatives.get(rangeType);
+    final void setStretching(final Stretching type) {
+        currentDataAlternative = type;
+        final RenderedImage alt = dataAlternatives.get(type);
         if (alt != null) {
-            setImage(rangeType, alt);
+            setImage(type, alt);
         } else {
             final RenderedImage source = getSourceData();
             if (source != null) {
                 execute(new Task<RenderedImage>() {
                     /** Invoked in background thread for fetching the image. */
                     @Override protected RenderedImage call() {
-                        switch (rangeType) {
-                            case AUTOMATIC: return ImageRenderings.automaticScale(source);
-                            default:        return source;
+                        switch (type) {
+                            case VALUE_RANGE: return ImageRenderings.valueRangeStretching(source);
+                            case AUTOMATIC:   return ImageRenderings. automaticStretching(source);
+                            default:          return source;
                         }
                     }
 
                     /** Invoked in JavaFX thread on success. */
                     @Override protected void succeeded() {
                         if (source.equals(getSourceData())) {
-                            setImage(rangeType, getValue());
+                            setImage(type, getValue());
                         }
                     }
                 });
@@ -260,10 +261,10 @@ public class CoverageCanvas extends MapCanvasAWT {
      * @param  type  the type of range used for scaling the color ramp of given image.
      * @param  alt   the image or alternative image to show (can be {@code null}).
      */
-    private void setImage(final RangeType type, RenderedImage alt) {
+    private void setImage(final Stretching type, RenderedImage alt) {
         /*
          * Store the result but do not necessarily show it because maybe the user changed
the
-         * `RangeType` during the time the background thread was working. If the user did
not
+         * `Stretching` during the time the background thread was working. If the user did
not
          * changed the type, then the `alt` variable below will stay unchanged.
          */
         dataAlternatives.put(type, alt);
@@ -284,8 +285,8 @@ public class CoverageCanvas extends MapCanvasAWT {
      * @param  sliceExtent  the extent that was requested.
      */
     private void setImage(final RenderedImage image, final GridGeometry geometry, final GridExtent
sliceExtent) {
-        setImage(RangeType.DECLARED, image);
-        setRangeType(currentDataAlternative);
+        setImage(Stretching.NONE, image);
+        setStretching(currentDataAlternative);
         try {
             gridToCRS = AffineTransforms2D.castOrCopy(geometry.getGridToCRS(PixelInCell.CELL_CENTER));
         } catch (RuntimeException e) {                      // Conversion not defined or
not affine.
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageControls.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageControls.java
index 0cba213..e4308d2 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageControls.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageControls.java
@@ -84,6 +84,7 @@ final class CoverageControls extends Controls {
         /*
          * "Display" section with the following controls:
          *    - Coordinate reference system
+         *    - Color stretching
          *    - Background color
          */
         final VBox displayPane;
@@ -95,10 +96,10 @@ final class CoverageControls extends Controls {
             systemLabel.setPadding(CAPTION_MARGIN);
             systemLabel.setLabelFor(systems);
             final GridPane gp = createControlGrid(
-                label(vocabulary, Vocabulary.Keys.Background, createBackgroundButton(background)),
-                label(vocabulary, Vocabulary.Keys.ValueRange, RangeType.createButton((p,o,n)
-> view.setRangeType(n)))
+                label(vocabulary, Vocabulary.Keys.Stretching, Stretching.createButton((p,o,n)
-> view.setStretching(n))),
+                label(vocabulary, Vocabulary.Keys.Background, createBackgroundButton(background))
             );
-            final Label label = new Label(vocabulary.getLabel(Vocabulary.Keys.Image));
+            final Label label = new Label(vocabulary.getLabel(Vocabulary.Keys.Colors));
             label.setPadding(NEXT_CAPTION_MARGIN);
             label.setLabelFor(gp);
             displayPane = new VBox(systemLabel, systems, label, gp);
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/RangeType.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/Stretching.java
similarity index 66%
rename from application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/RangeType.java
rename to application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/Stretching.java
index 7339bd5..d99818b 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/RangeType.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/Stretching.java
@@ -20,37 +20,41 @@ import javafx.beans.value.ChangeListener;
 import javafx.scene.control.ChoiceBox;
 import javafx.scene.control.SingleSelectionModel;
 import org.apache.sis.util.resources.Vocabulary;
-import org.apache.sis.internal.gui.Resources;
 
 
 /**
- * The kind of range to use for scaling the color palette of an image.
+ * The kind of color ramp stretching for scaling the color palette of an image.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @version 1.1
  * @since   1.1
  * @module
  */
-enum RangeType {
+enum Stretching {
     /**
      * As declared in the data store.
      * This is the default value.
      */
-    DECLARED,
+    NONE,
 
     /**
      * Computed from statistics (minimum and maximum values).
      */
+    VALUE_RANGE,
+
+    /**
+     * Computed from statistics (minimum and maximum values) adjusted with standard deviation.
+     */
     AUTOMATIC;
 
     /**
      * Creates the button for selecting a type of range.
-     * The initial value is {@link #DECLARED}.
+     * The initial value is {@link #NONE}.
      */
-    static ChoiceBox<RangeType> createButton(final ChangeListener<RangeType>
listener) {
-        final ChoiceBox<RangeType> button = new ChoiceBox<>();
+    static ChoiceBox<Stretching> createButton(final ChangeListener<Stretching>
listener) {
+        final ChoiceBox<Stretching> button = new ChoiceBox<>();
         button.getItems().addAll(values());
-        final SingleSelectionModel<RangeType> select = button.getSelectionModel();
+        final SingleSelectionModel<Stretching> select = button.getSelectionModel();
         select.select(0);
         select.selectedItemProperty().addListener(listener);
         return button;
@@ -61,10 +65,13 @@ enum RangeType {
      */
     @Override
     public String toString() {
+        final short key;
         switch (this) {
-            case DECLARED:  return Resources .format(Resources.Keys.FromMetadata);
-            case AUTOMATIC: return Vocabulary.format(Vocabulary.Keys.Automatic);
-            default:        return super.toString();
+            case NONE:        key = Vocabulary.Keys.None;       break;
+            case VALUE_RANGE: key = Vocabulary.Keys.ValueRange; break;
+            case AUTOMATIC:   key = Vocabulary.Keys.Automatic;  break;
+            default:          return super.toString();
         }
+        return Vocabulary.format(key);
     }
 }
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ImageRenderings.java
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ImageRenderings.java
index 0cad35a..7ccd729 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ImageRenderings.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ImageRenderings.java
@@ -34,8 +34,7 @@ public final class ImageRenderings {
     /**
      * The set of operations to use.
      *
-     * @todo Creates our own instance which listen to logging messages.
-     *       We need to create a logging panel first.
+     * @todo Listen to logging messages. We need to create a logging panel first.
      */
     private static final ImageProcessor PROCESSOR = new ImageProcessor();
     static {
@@ -49,13 +48,25 @@ public final class ImageRenderings {
     }
 
     /**
-     * Rescale the given image between a minimum and maximum values determined from statistics.
-     * If the given image is null or can not be rescaled, then it is returned as-is.
+     * Stretches the color ramp of given image between a minimum and maximum values.
+     * If the given image is null or can not be stretched, then it is returned as-is.
      *
-     * @param  image  the image to rescale, or {@code null}.
-     * @return the rescaled image.
+     * @param  image  the image to stretch, or {@code null}.
+     * @return the stretched image.
      */
-    public static RenderedImage automaticScale(final RenderedImage image) {
+    public static RenderedImage valueRangeStretching(final RenderedImage image) {
+        return PROCESSOR.automaticColorRamp(image, Double.POSITIVE_INFINITY);
+    }
+
+    /**
+     * Stretches the color ramp of given image between a minimum and maximum values
+     * adjusted  with standard deviations. If the given image is null or can not be
+     * stretched, then it is returned as-is.
+     *
+     * @param  image  the image to stretch, or {@code null}.
+     * @return the stretched image.
+     */
+    public static RenderedImage automaticStretching(final RenderedImage image) {
         return PROCESSOR.automaticColorRamp(image, 3);
     }
 }
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java
index c165174..fadf98c 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java
@@ -156,11 +156,6 @@ public final class Resources extends IndexedResourceBundle {
         public static final short Exit = 20;
 
         /**
-         * From metadata
-         */
-        public static final short FromMetadata = 21;
-
-        /**
          * Full screen
          */
         public static final short FullScreen = 22;
@@ -228,7 +223,7 @@ public final class Resources extends IndexedResourceBundle {
         /**
          * Windows
          */
-        public static final short Windows = 35;
+        public static final short Windows = 21;
     }
 
     /**
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties
index cbbe4c2..f4f63ba 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties
@@ -40,7 +40,6 @@ ErrorClosingFile       = Error closing file
 ErrorCreatingCRS       = Error creating reference system
 ErrorDataAccess        = Error during data access
 Exit                   = Exit
-FromMetadata           = From metadata
 FullScreen             = Full screen
 GeospatialFiles        = Geospatial data files
 Loading                = Loading\u2026
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties
index 174cd52..9225439 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties
@@ -45,7 +45,6 @@ ErrorClosingFile       = Erreur \u00e0 la fermeture du fichier
 ErrorCreatingCRS       = Erreur \u00e0 la cr\u00e9ation du syst\u00e8me de r\u00e9f\u00e9rence
 ErrorDataAccess        = Erreur lors de l\u2019acc\u00e8s \u00e0 la donn\u00e9e
 Exit                   = Quitter
-FromMetadata           = Des m\u00e9ta-donn\u00e9es
 FullScreen             = Plein \u00e9cran
 GeospatialFiles        = Fichiers de donn\u00e9es g\u00e9ospatiales
 Loading                = Chargement\u2026
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/ImageProcessor.java b/core/sis-feature/src/main/java/org/apache/sis/image/ImageProcessor.java
index 1d93555..7bc3b56 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/ImageProcessor.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/ImageProcessor.java
@@ -368,23 +368,23 @@ public class ImageProcessor implements Cloneable {
     }
 
     /**
-     * Returns an image with the same sample values than the given image, but with its color
ramp rescaled between the specified bounds.
+     * Returns an image with the same sample values than the given image, but with its color
ramp stretched between the specified bounds.
      * For example in a gray scale image, pixels with the minimum value will be black and
pixels with the maximum value will be white.
      * This operation is a kind of <cite>tone mapping</cite>, a technique used
in image processing to map one set of colors to another.
      * The mapping applied by this method is conceptually a simple linear transform (a scale
and an offset)
      * applied on sample values before they are mapped to their colors.
      *
-     * <p>Current implementation can remap only gray scale images (it may be extended
to indexed color models
-     * in a future version). If this method can not rescale the color ramp, for example because
the given image
+     * <p>Current implementation can stretch only gray scale images (it may be extended
to indexed color models
+     * in a future version). If this method can not stretch the color ramp, for example because
the given image
      * is an RGB image, then the image is returned unchanged.</p>
      *
      * @param  source    the image to recolor (may be {@code null}).
      * @param  minimum   the sample value to display with the first color of the color ramp
(black in a grayscale image).
      * @param  maximum   the sample value to display with the last color of the color ramp
(white in a grayscale image).
-     * @return the image with color ramp rescaled between the given bounds, or {@code image}
unchanged if the operation
+     * @return the image with color ramp stretched between the given bounds, or {@code image}
unchanged if the operation
      *         can not be applied on the given image.
      */
-    public RenderedImage rescaleColorRamp(final RenderedImage source, final double minimum,
final double maximum) {
+    public RenderedImage stretchColorRamp(final RenderedImage source, final double minimum,
final double maximum) {
         ArgumentChecks.ensureFinite("minimum", minimum);
         ArgumentChecks.ensureFinite("maximum", maximum);
         if (!(minimum < maximum)) {
@@ -398,8 +398,8 @@ public class ImageProcessor implements Cloneable {
     }
 
     /**
-     * Returns an image with the same sample values than the given image, but with its color
ramp rescaled between
-     * automatically determined bounds. This is the same operation than {@link #rescaleColorRamp
rescaleColorRamp(…)}
+     * Returns an image with the same sample values than the given image, but with its color
ramp stretched between
+     * automatically determined bounds. This is the same operation than {@link #stretchColorRamp
rescaleColorRamp(…)}
      * except that the minimum and maximum values are determined by {@linkplain #statistics(RenderedImage)
statistics}
      * on the image: a range of value is determined first from the {@linkplain Statistics#minimum()
minimum} and
      * {@linkplain Statistics#maximum() maximum} values found in the image, optionally narrowed
to an interval
@@ -415,7 +415,7 @@ public class ImageProcessor implements Cloneable {
      * @param  deviations  multiple of standard deviations around the mean, of {@link Double#POSITIVE_INFINITY}
      *                     for not using standard deviation for narrowing the range of values.
      *                     Some values giving good results for a Gaussian distribution are
1.5, 2 or 3.
-     * @return the image with color ramp rescaled between the automatic bounds,
+     * @return the image with color ramp stretched between the automatic bounds,
      *         or {@code image} unchanged if the operation can not be applied on the given
image.
      */
     public RenderedImage automaticColorRamp(final RenderedImage source, double deviations)
{
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
index cea1a4d..d670e6a 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
@@ -205,6 +205,11 @@ public final class Vocabulary extends IndexedResourceBundle {
         public static final short ColorIndex = 30;
 
         /**
+         * Colors
+         */
+        public static final short Colors = 228;
+
+        /**
          * Commands
          */
         public static final short Commands = 31;
@@ -990,6 +995,11 @@ public final class Vocabulary extends IndexedResourceBundle {
         public static final short StartPoint = 187;
 
         /**
+         * Stretching
+         */
+        public static final short Stretching = 229;
+
+        /**
          * Subset of {0}
          */
         public static final short SubsetOf_1 = 188;
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
index 2814b2c..c3a53b0 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
@@ -42,6 +42,7 @@ Characteristics         = Characteristics
 Classpath               = Classpath
 Code                    = Code
 Code_1                  = {0} code
+Colors                  = Colors
 ColorIndex              = Color index
 Commands                = Commands
 ConstantPressureSurface = Constant pressure surface
@@ -201,6 +202,7 @@ SpatialRepresentation   = Spatial representation
 StandardDeviation       = Standard deviation
 StartDate               = Start date
 StartPoint              = Start point
+Stretching              = Stretching
 SubsetOf_1              = Subset of {0}
 Summary                 = Summary
 SupersededBy_1          = Superseded by {0}.
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
index afee42f..f2eeb0e 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
@@ -49,6 +49,7 @@ Characteristics         = Caract\u00e9ristiques
 Classpath               = Chemin de classes
 Code                    = Code
 Code_1                  = Code {0}
+Colors                  = Couleurs
 ColorIndex              = Indice de couleur
 Commands                = Commandes
 ConstantPressureSurface = Surface \u00e0 pression constante
@@ -211,6 +212,7 @@ StartPoint              = Point de d\u00e9part
 SubsetOf_1              = Sous-ensemble de {0}
 Summary                 = R\u00e9sum\u00e9
 SupersededBy_1          = Remplac\u00e9 par {0}.
+Stretching              = \u00c9tirement
 Temporal                = Temporel
 TemporalExtent          = Plage temporelle
 TemporaryFiles          = Fichiers temporaires


Mime
View raw message