Class EarthDataView
- All Implemented Interfaces:
Cloneable
,Renderable
- Direct Known Subclasses:
ColorComposite
,ColorEnhancement
,HybridView
,SolidBackground
The EarthDataView
class sets up a correspondence between 2D Earth
locatable data variables (possibly more than one) and a visual
image. A view has a certain size in width and height and a
translation between earth locations and image coordinates. A view
may also have a number of data overlays for annotation. For a
swath transform, the data view forces north to be in the upwards
direction, at the top of the image. If the transform is such that
data locations with larger indices have a greater latitude, the
sense of the image transform is flipped so that north appears at
the top.
A view maintains its image to data scaling information using the center data location and image scale factor. All view manipulations are relative to these quantities.
In order to help implement child classes, it may be of interest to
developers to know how view rendering works. The main
render()
method is called by any user of the view to
render the view to a graphics context. In some cases, this
graphics context may be from a GUI panel on the screen, or in
others it may be an offscreen image buffer that will be copied to
the screen or saved to an image file. In either case, the
render()
method relies on a two-step process for
rendering the view. It first renders the protected
BufferedImage image
variable to the graphics context.
Secondly, it loops over each overlay in order and renders it to
the graphics context. This two-step process may involve delays,
both in rendering the main image and the overlays. For example, a
delay may occur when translating data values into image colours, or
in translating overlay earth locations to image coordinates.
In order to help handle delays, two protected variables are used:
changed
and progress
. The changed flag
indicates that something in the view has changed since the last
time the render()
method was called. If the view has
changed, then any saved image buffer that was used to capture the
results of the render()
method may no longer be used
and should be discarded. If the view has not changed, then
rendering again will produce the exact same output and there is no
need to render again if the output was saved. The progress flag
indicates that the user wants to see progress updates during the
delay in which the image is being rendered. In addition to these
flags, the two methods prepare()
and
isPrepared()
are used to determine how much of a delay
may be involved in rendering. If the protected image
variable is not built or one of the overlays is not ready to be
immediately rendered in screen coordinates, then the view is "not
prepared". The view may be explicitly prepared by calling the
prepare()
method and passing it the graphics context
to which preparation progress should be written. Once prepared,
the user may call render()
and expect to have no
delay.
To handle interruptions in rendering so that a user-interface using
the view appears responsive, the stopRendering()
method may be used. The method sets the protected
stopRendering
flag to indicate to the child class that
it should stop inside any currently executing rendering loop and
return. The isRendering()
method may be used to
determine if a rendering loop is currently active. Generally,
these methods are only useful in a multithreaded application in
which the rendering is running in a separate thread from the
user-interface.
- Since:
- 3.1.0
- Author:
- Peter Hollemans
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
The view changed flag, true if the view changed after rendering.protected BufferedImage
The buffered image used for rendering.protected Dimension
The view image dimensions.protected LinkedList<EarthDataOverlay>
A number of data overlays.protected boolean
The rendering progress flag, true to show rendering progress.protected boolean
The rendering stop flag, true to stop rendering in progress.protected EarthImageTransform
The earth to image coordinate transform.static final double
The update frequency as a fraction of the total image size.protected boolean
The verbose mode flag. -
Constructor Summary
ModifierConstructorDescriptionprotected
EarthDataView
(int[] dataDims, EarthTransform earthTrans) Constructs a new view using the specified parameters.protected
EarthDataView
(EarthDataView view) Creates a new view using the geometry of the specified view. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addOverlay
(EarthDataOverlay overlay) Adds an overlay to the view.void
addOverlays
(List overlays) Adds a list of overlays to the view.clone()
Creates and returns a copy of this object.void
computeCaches
(Grid grid) Creates a set of caches to speed image-to-data transforms.boolean
containsOverlay
(EarthDataOverlay overlay) Checks if this view contains the specified overlay.getArea()
Gets the geographic area of this view.Gets the bounds of this view.Gets the center data location of this view.Deprecated.Gets the current image affine transform.Gets a legend for annotation of the data view.Gets the view orientation affine.Gets the current list of overlays.boolean
Gets the rendering progress mode flag.double
Calculates the view resolution at the center data location in km/pixel.double
getScale()
Gets the scale of this view.Gets the rendered view dimensions.Deprecated.Gets the earth image transform.boolean
Deprecated.As of 3.3.1, usegetOrientationAffine()
.boolean
hasCompatibleCaches
(Grid grid) Returns true if this view has coordinate caches that are compatible with the specified grid navigation transform.boolean
Returns true if this view has coordinate caches available.void
Invalidates the view.boolean
Gets the status of the view changed flag.boolean
Gets the status of view and overlay preparation.boolean
Returns true if the view is currently being rendered, or false if not.void
magnify
(double factor) Magnifies this view around the current center location.void
Magnifies the specified area to occupy the entire view.void
magnify
(DataLocation center, double factor) Magnifies this view around a center location.static void
Tests this class.protected abstract void
Prepares this view for rendering using the specified graphics object.void
removeOverlay
(EarthDataOverlay overlay) Removes an overlay from the view.void
render
(Graphics2D g) Renders this view using the graphics object.void
reset()
Resets the view to the full data resolution.void
resize
(double factor) Changes the view size by the specified factor.void
Changes the view size to the specified dimensions.void
resizeHeight
(int imageHeight) Changes the view size to the specified height.void
resizeMaxAspect
(int imageSize) Changes the view size to the specified maximum dimension.void
resizeWidth
(int imageWidth) Changes the view size to the specified width.void
setCenter
(DataLocation center) Sets the view center to a new data location.void
setCenterAndScale
(DataLocation center, double scale) Set the center and scale of this viewvoid
Sets the changed flag.void
setImageAffine
(AffineTransform affine) Sets the image affine transform.void
setProgress
(boolean flag) Sets the rendering progress mode flag.void
setProperties
(EarthDataView view) Sets the properties of this view based on the specified view.void
Sets the view to a new size.void
setVerbose
(boolean flag) Sets the verbose mode flag.void
showSubregion
(Subregion subregion) Deprecated.void
Sets the stop rendering flag to indicate that any current rendering loop should stop and return.int[]
Transforms an image point to an integer data location using precomputed coordinate caching.void
Transforms an image point to an integer data location using precomputed coordinate caching.
-
Field Details
-
UPDATE_FRACTION
public static final double UPDATE_FRACTIONThe update frequency as a fraction of the total image size. This should be used by any rendering routine that wants to show the progress of view construction while it is taking place.- See Also:
-
trans
The earth to image coordinate transform. This is used to translate between earth (lat,lon) and view image (x,y). It holds both the image transform for view image (x,y) to data (row,col) and the earth transform for data (row,col) to earth (lat,lon). -
imageDims
The view image dimensions. This is the height and width of the view graphics when delivered by therender()
method. -
overlays
A number of data overlays. The overlays are rendered in the view image after sorting according to level. -
image
The buffered image used for rendering. The buffered image is used by child classes to render a specific image based on their own variables. This image is independent of the list of overlays and should only contain graphics specific to the child. It is subsequently used by this class to assemble the complete view graphics. -
verbose
protected boolean verboseThe verbose mode flag. When true, the status of the main image rendering is printed, along with each overlay rendering step. -
changed
protected boolean changedThe view changed flag, true if the view changed after rendering. The changed flag must be set if any change is made to the view that would change the view graphics generated by a call to therender()
method. -
progress
protected boolean progressThe rendering progress flag, true to show rendering progress. When rendering progress mode is on, the child class should periodically update the view graphics in theprepare()
method at a frequency determined byUPDATE_FRACTION
. -
stopRendering
protected boolean stopRenderingThe rendering stop flag, true to stop rendering in progress. This flag is set to false at the start of any rendering call, and should be used by child classes to break out of the rendering loop.
-
-
Constructor Details
-
EarthDataView
Creates a new view using the geometry of the specified view.- Parameters:
view
- the view to copy.- Since:
- 3.7.1
-
EarthDataView
protected EarthDataView(int[] dataDims, EarthTransform earthTrans) throws NoninvertibleTransformException Constructs a new view using the specified parameters. The view dimensions are initialized to the data dimensions, and the ratio of data to image pixel count to 1. A check is performed on the transform to determine if it should be oriented differently for display, and flipped or rotated if so. The verbose mode and progress mode flags are initially set to false.- Parameters:
dataDims
- the data dimensions as [rows, columns].earthTrans
- the earth transform.- Throws:
NoninvertibleTransformException
- if the image to data transform is not invertible.
-
-
Method Details
-
getUpsideDown
Deprecated.As of 3.3.1, usegetOrientationAffine()
.Gets the upside-down flag.- Returns:
- true if the view is being corrected from its normal orientation so that north is in the up direction, or false if not.
-
getOrientationAffine
Gets the view orientation affine. The orientation affine transforms data coordinates for display, rotating or flipping as needed so that the north direction is at the top of the screen.- Returns:
- the orientation affine (possibly the identity).
- Since:
- 3.3.1
-
getImageAffine
Gets the current image affine transform.- Returns:
- the current transform or null for no transform.
- See Also:
-
setImageAffine
Sets the image affine transform. When the view is rendered, the new image affine will be used to transform the image coordinates prior to rendering. Any overlays rendered will be unaffected.- Parameters:
affine
- the image affine transform, or null for no transform.
-
stopRendering
public void stopRendering()Sets the stop rendering flag to indicate that any current rendering loop should stop and return. -
isRendering
public boolean isRendering()Returns true if the view is currently being rendered, or false if not. -
getOverlays
Gets the current list of overlays. -
addOverlays
Adds a list of overlays to the view. -
setVerbose
public void setVerbose(boolean flag) Sets the verbose mode flag. -
getProgress
public boolean getProgress()Gets the rendering progress mode flag. -
setProgress
public void setProgress(boolean flag) Sets the rendering progress mode flag. When rendering progress mode is on, a call torender
shows the progress of rendering by drawing successive images to the destination graphics device. -
hasCoordinateCaches
public boolean hasCoordinateCaches()Returns true if this view has coordinate caches available.- See Also:
-
hasCompatibleCaches
Returns true if this view has coordinate caches that are compatible with the specified grid navigation transform. Returns false if the coordinate caches are incompatible or if there are no coordinate caches. -
transform
Transforms an image point to an integer data location using precomputed coordinate caching.- Parameters:
p
- the image point.- Returns:
- the integer data location as
[row, column]
. This view must have coordinate caches available. - See Also:
-
transform
Transforms an image point to an integer data location using precomputed coordinate caching.- Parameters:
p
- the image point.coords
- the output coordinates array. The array entries are modified to contain the integer data location as[row, column]
.- See Also:
-
computeCaches
Creates a set of caches to speed image-to-data transforms. The navigation transform of the specified grid is taken into account in the cache. Note that this is only useful when the navigation is either the identity or a translation.- Parameters:
grid
- the grid variable to use for navigation corrections, or null to compute caches without any navigation transform.- Since:
- Public as of 3.5.1, and the grid parameter may now be null if desired.
-
setChanged
public void setChanged()Sets the changed flag. This method should be called if some existing overlay property has been updated, or some other change made to the view that would require the view buffer to be updated. Normally, the change flag is set internally but in some cases it may be necessary to "force" the view to acknowledge a change. -
invalidate
public void invalidate()Invalidates the view. This causes the view to be completely reconstructed upon the next call torender()
. -
addOverlay
Adds an overlay to the view. -
removeOverlay
Removes an overlay from the view. -
containsOverlay
Checks if this view contains the specified overlay. -
getTransform
Gets the earth image transform. -
getCorners
Deprecated.As of 3.3.1, usegetBounds()
.Gets the data corners of this view as [upperLeft, lowerRight]. -
getBounds
Gets the bounds of this view.- Returns:
- the array of data location bounds as [minimum(row,col), maximum(row,col)].
- Since:
- 3.3.1
-
getCenter
Gets the center data location of this view. -
getScale
public double getScale()Gets the scale of this view.- Returns:
- the ratio of data pixels to view image pixels.
-
getArea
Gets the geographic area of this view. -
setCenter
Sets the view center to a new data location. The image dimensions and image scaling factor are unaffected.- Parameters:
center
- the new center data location.- Throws:
NoninvertibleTransformException
- if the image to data transform is not invertible.
-
setCenterAndScale
public void setCenterAndScale(DataLocation center, double scale) throws NoninvertibleTransformException Set the center and scale of this view- Parameters:
center
- the new center data location.scale
- the new scaling factor for the view (desired ratio of data pixels to image pixels).- Throws:
NoninvertibleTransformException
- See Also:
-
setProperties
Sets the properties of this view based on the specified view. The two views should have compatible earth transforms and data grids. The overlays, earth transform, and verbose mode are all copied.- Parameters:
view
- the source view to copy properties from.
-
resizeMaxAspect
Changes the view size to the specified maximum dimension. The view dimensions are changed, as well as the data to image scaling so that approximately the same data is displayed in the resized view. The center data location is unaffected.- Parameters:
imageSize
- the new image maximum dimension.- Throws:
NoninvertibleTransformException
- if the image to data transform is not invertible.
-
resizeWidth
Changes the view size to the specified width. The view dimensions are changed, as well as the data to image scaling so that approximately the same data is displayed in the resized view. The center data location is unaffected.- Parameters:
imageWidth
- the new image width.- Throws:
NoninvertibleTransformException
- if the image to data transform is not invertible.
-
resizeHeight
Changes the view size to the specified height. The view dimensions are changed, as well as the data to image scaling so that approximately the same data is displayed in the resized view. The center data location is unaffected.- Parameters:
imageHeight
- the new image height.- Throws:
NoninvertibleTransformException
- if the image to data transform is not invertible.
-
resize
Changes the view size to the specified dimensions. The view dimensions are changed, as well as the data to image scaling so that approximately the same data is displayed in the resized view. The center data location is unaffected.- Parameters:
imageDims
- the new image dimensions.- Throws:
NoninvertibleTransformException
- if the image to data transform is not invertible.
-
resize
Changes the view size by the specified factor. The view dimensions are changed, as well as the data to image scaling so that the same data is displayed in the resized view. The center data location is unaffected.- Parameters:
factor
- the factor by which to change the view size. Factors greater than 1 increase the view size and factors less than 1 decrease the view size.- Throws:
NoninvertibleTransformException
- if the image to data transform is not invertible.
-
magnify
Magnifies this view around a center location. The view dimensions are unaffected.- Parameters:
center
- the new center data location.factor
- the factor by which to magnify. Factors greater than 1 increase the magnification and factors less than 1 decrease the magnification.- Throws:
NoninvertibleTransformException
- if the image to data transform is not invertible.
-
magnify
Magnifies this view around the current center location. The view dimensions are unaffected.- Parameters:
factor
- the factor by which to magnify. Factors greater than 1 increase the magnification and factors less than 1 decrease the magnification.- Throws:
NoninvertibleTransformException
- if the image to data transform is not invertible.- See Also:
-
magnify
Magnifies the specified area to occupy the entire view. The center data location is changed to match the center of the specified rectangle. The scaling factor is changed so that the maximum dimension of the rectangle fits within the view dimensions.- Parameters:
upperLeft
- the upper-left corner point.lowerRight
- the lower-right corner point.- Throws:
NoninvertibleTransformException
- if the image to data transform is not invertible.
-
reset
Resets the view to the full data resolution. The center data location is reset to the center of the data, the image:data scaling factor to 1, and the image dimensions to the full data dimensions.- Throws:
NoninvertibleTransformException
- if the image to data transform is not invertible.
-
setSize
Sets the view to a new size. The data center location and image scaling factor remain unaffected.- Parameters:
imageDims
- the new image dimensions.- Throws:
NoninvertibleTransformException
- if the image to data transform is not invertible.
-
getResolution
public double getResolution()Calculates the view resolution at the center data location in km/pixel.- Returns:
- the resolution in km/pixel.
-
prepare
Prepares this view for rendering using the specified graphics object. This method is called when any changes have occurred that require the view to be completely reconstructed, such as a change in view size or data window. -
isPrepared
public boolean isPrepared()Gets the status of view and overlay preparation. If the view is prepared, a render call will return after almost no delay. If not, the render may require time to complete due to loading data from disk or cache, converting earth locations to screen points, and so on. -
isChanged
public boolean isChanged()Gets the status of the view changed flag. If the view is modified after rendering by resizing or changing overlays, then the view is changed and may require re-rendering. -
render
Renders this view using the graphics object.- Specified by:
render
in interfaceRenderable
- Parameters:
g
- the graphics context for rendering.
-
getLegend
Gets a legend for annotation of the data view. This default method returns null, but subclasses may override this method to provide a legend.- Returns:
- a legend or null if no legend is available.
-
getSize
Gets the rendered view dimensions.- Specified by:
getSize
in interfaceRenderable
- Parameters:
g
- the graphics context for rendering. In this class, the graphics context is ignored and may be null.- Returns:
- the rendered view dimensions.
-
clone
Creates and returns a copy of this object. Child classes should override this method if they contain any deep structure that needs copying. -
showSubregion
Deprecated.Magnifies this view to show the specified subregion. If the limits of the subregion cannot be determined for the view, no operation is performed.- Parameters:
subregion
- the subregion to show.- See Also:
-
getSubregion
Deprecated.Gets the subregion currently displayed by this view.- Returns:
- the subregion displayed.
- See Also:
-
main
Tests this class.- Parameters:
argv
- the array of command line parameters.- Throws:
Exception
-
getBounds()
.