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 d1c2db3c24b7100f3ad858fc12ff2fc49a4d969d Author: Martin Desruisseaux <[email protected]> AuthorDate: Fri Jan 15 11:53:09 2021 +0100 Remove `PlanarCanvas.getAreaOfInterest()` because subclass needs to perform a slightly different computation, for example with addition of a margin. --- .../apache/sis/gui/coverage/CoverageCanvas.java | 47 ++++++++++++++----- .../org/apache/sis/portrayal/PlanarCanvas.java | 52 ---------------------- 2 files changed, 36 insertions(+), 63 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 91abb4a..c2ae8f6 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 @@ -57,7 +57,9 @@ import org.apache.sis.coverage.grid.ImageRenderer; import org.apache.sis.internal.gui.ExceptionReporter; import org.apache.sis.referencing.operation.matrix.AffineTransforms2D; import org.apache.sis.referencing.operation.transform.LinearTransform; +import org.apache.sis.referencing.operation.transform.MathTransforms; import org.apache.sis.geometry.Envelope2D; +import org.apache.sis.geometry.Shapes2D; import org.apache.sis.image.PlanarImage; import org.apache.sis.image.Interpolation; import org.apache.sis.coverage.Category; @@ -549,9 +551,11 @@ public class CoverageCanvas extends MapCanvasAWT { private final Envelope2D displayBounds; /** - * Value of {@link CoverageCanvas#getAreaOfInterest()} at the time this worker has been initialized. - * This is the bounds of the are shown in the widget, converted to objective CRS. + * Bounds of the currently visible area (plus margin) in units of objective CRS. + * The AOI can be used as a hint, for example in order to clip data for faster rendering. * This is needed only if {@link #isolines} is non-null. + * + * @see CoverageCanvas#getAreaOfInterest() */ private Rectangle2D objectiveAOI; @@ -622,15 +626,18 @@ public class CoverageCanvas extends MapCanvasAWT { displayBounds.y -= margin.getTop(); displayBounds.height += margin.getTop() + margin.getBottom(); } - if (canvas.isolines != null) { + if (canvas.isolines != null) try { isolines = canvas.isolines.prepare(); - objectiveAOI = canvas.getAreaOfInterest(); + objectiveAOI = Shapes2D.transform(MathTransforms.bidimensional(objectiveToDisplay.inverse()), displayBounds, null); + } catch (TransformException e) { + unexpectedException(e); // Should never happen. } } /** - * Returns the bounds of the image part which is currently shown. This method can be invoked - * only after {@link #render()}. It returns {@code null} if the visible bounds are unknown. + * Returns the region of source image which is currently shown, in units of source coverage pixels. + * This method can be invoked only after {@link #render()}. It returns {@code null} if the visible + * bounds are unknown. * * @see CoverageCanvas#getVisibleImageBounds() */ @@ -787,16 +794,16 @@ public class CoverageCanvas extends MapCanvasAWT { } /** - * Returns the bounds of the image part which is currently shown. This method performs the same work - * than {@link Worker#getVisibleImageBounds()} in a less efficient way. It is used when no worker is - * available. + * Returns the region of source image which is currently shown, in units of source coverage pixels. + * This method performs the same work than {@link Worker#getVisibleImageBounds()} in a less efficient way. + * It is used when no worker is available. * * @see Worker#getVisibleImageBounds() */ private Rectangle getVisibleImageBounds() { final Envelope2D displayBounds = getDisplayBounds(); - final AffineTransform resampledToDisplay = data.getTransform(getObjectiveToDisplay()); - try { + if (displayBounds != null) try { + final AffineTransform resampledToDisplay = data.getTransform(getObjectiveToDisplay()); return (Rectangle) AffineTransforms2D.inverseTransform(resampledToDisplay, displayBounds, new Rectangle()); } catch (NoninvertibleTransformException e) { unexpectedException(e); // Should never happen. @@ -805,6 +812,24 @@ public class CoverageCanvas extends MapCanvasAWT { } /** + * Returns the bounds of the currently visible area in units of objective CRS. + * This AOI changes when the {@linkplain #getDisplayBounds() display bounds} or + * the {@linkplain #getObjectiveToDisplay() objective to display transform} changed. + * The AOI can be used as a hint, for example in order to clip data for faster rendering. + * + * @return bounds of currently visible area in objective CRS, or {@code null} if unavailable. + * + * @see Worker#objectiveAOI + */ + private Rectangle2D getAreaOfInterest() throws TransformException { + final Envelope2D displayBounds = getDisplayBounds(); + if (displayBounds == null) { + return null; + } + return Shapes2D.transform(MathTransforms.bidimensional(getObjectiveToDisplay().inverse()), displayBounds, null); + } + + /** * Invoked by {@link CoverageControls} when the user selected a new color stretching mode. * The sample values are assumed the same; only the image appearance is modified. */ diff --git a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/PlanarCanvas.java b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/PlanarCanvas.java index 2edef76..fcc59cc 100644 --- a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/PlanarCanvas.java +++ b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/PlanarCanvas.java @@ -17,12 +17,10 @@ package org.apache.sis.portrayal; import java.util.Locale; -import java.awt.geom.Rectangle2D; import java.awt.geom.AffineTransform; import org.opengis.geometry.Envelope; import org.opengis.geometry.DirectPosition; import org.opengis.metadata.spatial.DimensionNameType; -import org.opengis.referencing.operation.NoninvertibleTransformException; import org.apache.sis.measure.Units; import org.apache.sis.geometry.Envelope2D; import org.apache.sis.geometry.DirectPosition2D; @@ -30,8 +28,6 @@ import org.apache.sis.referencing.CommonCRS; import org.apache.sis.referencing.operation.matrix.AffineTransforms2D; import org.apache.sis.referencing.operation.transform.LinearTransform; import org.apache.sis.internal.referencing.j2d.AffineTransform2D; -import org.apache.sis.internal.system.Modules; -import org.apache.sis.util.logging.Logging; /** @@ -68,12 +64,6 @@ public abstract class PlanarCanvas extends Canvas { protected final AffineTransform objectiveToDisplay; /** - * The display bounds in objective CRS, or {@code null} if this value needs to be recomputed. - * This value is invalidated every time that {@link #objectiveToDisplay} transform changes. - */ - private Rectangle2D areaOfInterest; - - /** * Creates a new two-dimensional canvas. * * @param locale the locale to use for labels and some messages, or {@code null} for default. @@ -114,19 +104,6 @@ public abstract class PlanarCanvas extends Canvas { } /** - * Sets the size and location of the display device in pixel coordinates. - * The given envelope shall be two-dimensional. If the given value is different than the previous value, - * then a change event is sent to all listeners registered for the {@value #DISPLAY_BOUNDS_PROPERTY} property. - * - * @see #getDisplayBounds() - */ - @Override - public void setDisplayBounds(final Envelope newValue) throws RenderException { - areaOfInterest = null; - super.setDisplayBounds(newValue); - } - - /** * Returns the size and location of the display device. The unit of measurement is * {@link Units#PIXEL} and coordinate values are usually (but not necessarily) integers. * @@ -145,32 +122,6 @@ public abstract class PlanarCanvas extends Canvas { } /** - * Returns the bounds of the currently visible area in objective CRS. - * New Area Of Interests (AOI) are computed when the {@linkplain #getDisplayBounds() display bounds} - * or the {@linkplain #getObjectiveToDisplay() objective to display transform} change. - * The AOI can be used as a hint, for example in order to clip data for faster rendering. - * - * @return bounds of currently visible area in objective CRS, or {@code null} if unavailable. - */ - public Rectangle2D getAreaOfInterest() { - if (areaOfInterest == null) { - final Envelope2D bounds = getDisplayBounds(); - if (bounds != null) try { - /* - * Following cast is safe because of the way `updateObjectiveToDisplay()` is implemented. - * The `inverse()` method is invoked on `LinearTransform` instead than `AffineTransform` - * because the former is cached. - */ - final AffineTransform displayToObjective = (AffineTransform) super.getObjectiveToDisplay().inverse(); - areaOfInterest = AffineTransforms2D.transform(displayToObjective, bounds, null); - } catch (NoninvertibleTransformException e) { - Logging.unexpectedException(Logging.getLogger(Modules.PORTRAYAL), PlanarCanvas.class, "getAreaOfInterest", e); - } - } - return (areaOfInterest != null) ? (Rectangle2D) areaOfInterest.clone() : null; - } - - /** * Returns the affine conversion from objective CRS to display coordinate system. * The transform returned by this method is a snapshot taken at the time this method is invoked; * subsequent changes in the <cite>objective to display</cite> conversion are not reflected in @@ -202,7 +153,6 @@ public abstract class PlanarCanvas extends Canvas { */ @Override final void updateObjectiveToDisplay(final LinearTransform newValue) { - areaOfInterest = null; objectiveToDisplay.setTransform(AffineTransforms2D.castOrCopy(newValue.getMatrix())); super.updateObjectiveToDisplay(newValue); } @@ -216,7 +166,6 @@ public abstract class PlanarCanvas extends Canvas { */ public void transformObjectiveCoordinates(final AffineTransform before) { if (!before.isIdentity()) { - areaOfInterest = null; final LinearTransform old = hasListener(OBJECTIVE_TO_DISPLAY_PROPERTY) ? getObjectiveToDisplay() : null; objectiveToDisplay.concatenate(before); invalidateObjectiveToDisplay(old); @@ -232,7 +181,6 @@ public abstract class PlanarCanvas extends Canvas { */ public void transformDisplayCoordinates(final AffineTransform after) { if (!after.isIdentity()) { - areaOfInterest = null; final LinearTransform old = hasListener(OBJECTIVE_TO_DISPLAY_PROPERTY) ? getObjectiveToDisplay() : null; objectiveToDisplay.preConcatenate(after); invalidateObjectiveToDisplay(old);
