Class TLcdGXYImagePainter

java.lang.Object
com.luciad.view.gxy.ALcdGXYPainter
com.luciad.view.gxy.painter.TLcdGXYImagePainter
All Implemented Interfaces:
ILcdCloneable, ILcdPropertyChangeSource, ILcdGXYPainter, ILcdGXYPainterProvider, Serializable, Cloneable

public class TLcdGXYImagePainter extends ALcdGXYPainter
Painter for ALcdImage objects in an ILcdGXYView.

Supported objects

This painter can optionally apply operators to images via the setOperatorChain(com.luciad.imaging.operator.ALcdImageOperatorChain) method. This painter supports all ALcdImage variants (ALcdBasicImage, ALcdMultilevelImage, ALcdImageMosaic and ALcdMultilevelImageMosaic), as well as ILcdRaster, ILcdMultilevelRaster and ILcdEarthTileSet.

Visualization

This painter can warp images between different coordinate systems, if required, or just paint linearly scaled images, if possible.

It paints the visible portion of the image if the scale of the ILcdGXYView on which to paint is such that the screen resolution is inside the range defined by the properties startResolutionFactor and stopResolutionFactor. Outside of this range, it paints only the outline of the image. The resolution factor defines the ratio between the resolution of the raster and the resolution of the screen. For example, a resolution factor of 4 indicates that 4 image pixels are used to color a single screen pixel. A factor of 0.25 indicates that a single image pixel will be used to paint four screen pixels. Typical values for startResolutionFactor and stopResolutionFactor are 2 and 0.5, respectively, indicating that as we zoom in, the image becomes visible at a point where 2 raster pixels are merged into a single screen pixel, and the image becomes invisible at a point where a single raster pixel is blurred into two screen pixels.

The value of the startResolutionFactor, the dimensions of the tiles and the dimension of the ILcdGXYView on which to paint, determine the maximum number of tiles that need to be loaded in memory, when painting the visible portion of the image. The minimum value of the maximum number of tiles is always four because the visible portion can always be pointed at the intersection of four tiles. Suppose we have tiles of 1024 by 1024 pixels, and a maximum ILcdGXYView size of 800 by 600. Suppose further that we we choose a startResolutionFactor of 9. Then, there may be a maximum of 3 by 2 tiles needed to paint the 800 by 600 ILcdGXYView, thus requiring 6 tiles to be in memory. This calculation is a rough approximation because of the non-linear transformation between the data reference of the image and the data reference of the ILcdGXYView. For example, at a small scale, an ILcdGXYView with a data reference based on an Orthographic projection may require more tiles than calculated with the above procedure. Therefore, as a rule of thumb, allocate twice the amount of memory to hold the maximum number of tiles calculated.

Given a multilevel image, the painter picks the level to be painted based on the pixel density of the images and on the resolution of the view. It essentially picks the first level for which image pixels are not projected across multiple view pixels. This approach avoids pixelation effects. The levelSwitchFactor property allows to adjust this behavior.

Incremental visualization

This painter supports incremental visualization if:
  • the image is a ALcdMultilevelImageMosaic independently of its tile structure
  • the individual tiles are relatively small (ex. 256x256 pixels)
  • each level has the same sampling mode (AREA or POINT)
This means that the tiles will be requested asynchronously and the view will be repainted as the tiles become available. To enable this the isAsynchronousTileRequestAllowed() and isRepaintViewWhenTileAvailable() should be set to true (default).

Visualizing non-color data

When visualizing non-color data such as elevation data or multiband/hyperspectral data the painter needs to convert the data to displayable colors. You can configure an image operator chain to control the conversion to colors. Typically this can be done by selecting bands and either interpreting them as color bands or mapping values to colors. By default the painter converts elevation data to color using the default color map or otherwise maps the first band to gray-scale values.

Since:
2014.0
See Also:
  • Constructor Details

    • TLcdGXYImagePainter

      public TLcdGXYImagePainter()
      Create a new painter which uses the default shared imaging engine.
    • TLcdGXYImagePainter

      public TLcdGXYImagePainter(ALcdImagingEngine aImagingEngine)
      Create a new painter which uses the specified imaging engine.
      Parameters:
      aImagingEngine - imaging engine to use.
  • Method Details

    • create

      public static ILcdGXYPainterProvider create(ILcdModel aModel, ALcdImagingEngine aImagingEngine)
      This method creates a painter provider that configures a GXY painter with the defaults for painting raster data. It can paint:
      • Models following the imaging API, where the domain object(s) either is an ALcdImage or has an ALcdImage.
      • Models following the raster API, where the domain objects can be either ILcdRaster, ILcdMultilevelRaster or ILcdEarthTileSet.
      It detects and styles the following types of raster data:
      • RGB(A) color data: styles as-is (color).
      • Elevation data: styled with a DTED color map.
      • Single-band measurement (weather) data: styled with a measurement color map.
      • Dual-band measurement (weather) data, such as wind and ocean currents: styled with arrow icons or wind barb icons.
      Parameters:
      aModel - the model for which to create a painter provider.
      aImagingEngine - the imaging engine to use. This may be null, in which case, a default imaging engine is used.
      Returns:
      a painter provider that configures a GXY painter with the defaults for painting raster data
    • getOperatorChain

      public ALcdImageOperatorChain getOperatorChain()
      Returns the current image operator chain.
      Returns:
      the operator chain
    • setOperatorChain

      public void setOperatorChain(ALcdImageOperatorChain aOperatorChain)
      Sets the operator chain to be applied to painted images.
      Parameters:
      aOperatorChain - the operator chain
    • setObject

      public void setObject(Object aObject)
      Parameters:
      aObject - the object to be painted
      See Also:
    • getObject

      public Object getObject()
      Description copied from interface: ILcdGXYPainter
      Returns the Object for which the representation is currently being handled by this painter.
      Returns:
      the Object for which the representation is currently being handled by this painter.
      See Also:
    • paint

      public void paint(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext)
      Description copied from interface: ILcdGXYPainter
      Displays the representation of the object in the given mode on the Graphics passed, taking into account the supplied context.

      The visual representation of an object depends on the context. Depending on the context (e.g. is the location covered by the view), an object may or may not have a representation. The context contains:

      • transformations which allow to compute the location in view space of points and bounds given in model, space
      • a pen which can connect points with a line or create arcs around a point,
      • the view for which the object's representation must be painted. This can be useful when the painted object depends on the scale of the view, or the presence of other layers in the view.
      • the current location(s) of the mouse or input device and the last location(s) the mouse or input device was pressed.

      The mode passed in this method indicates what part of the object must be painted, whether it should be painted as selected or not, and whether user interaction (via mouse movements) must be taken into account.

      When the mode passed contains either TRANSLATING, RESHAPING or CREATING, this method is also responsible for interpreting interaction on the representation of an object and modifying the representation of the object accordingly. The painter is not responsible for modifying the object itself, this is done by a corresponding ILcdGXYEditor . Implementations of ILcdGXYPainter and ILcdGXYEditor interfaces must be consistent for an object: the painter must display the result of the user interaction on the object, while the editor is responsible for modifying the object as a result of the user interaction. A good practice to ensure a consistent implementation is to implement both the ILcdGXYPainter and ILcdGXYEditor interfaces in a single class.

      When the mode passed includes SNAPS, the part of the representation which corresponds to the object returned as snap target by the method snapTarget must be painted in order to provide the user with a visual indication of the snap target.

      The Graphics passed in this method can be different from the Graphics returned by a view due to techniques such as double buffering (as applied in Swing). Basic drawing operations must always be performed on the Graphics passed as an argument in this method.

      Parameters:
      aGraphics - the Graphics on which the representation of the object is painted
      aMode - the mode the object is represented in (see class documentation).
      aGXYContext - the ILcdGXYContext the drawing depends on.
    • boundsSFCT

      public void boundsSFCT(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext, ILcd2DEditableBounds aBoundsSFCT) throws TLcdNoBoundsException
      Description copied from interface: ILcdGXYPainter
      Sets the supplied bounds (in view coordinates, pixels) so that it encompasses the representation of the object in the given mode taking into account the given context.

      If this method returns without exception the bounds argument must encompass the representation of the object. A point outside the bounds will not be contained within the painted object.

      The bounds returned in this method can be seen as the equivalent in the view space of the bounds in the model space for ILcdBounded objects.

      Parameters:
      aGraphics - the Graphics on which the representation of the object is painted
      aMode - the mode the object is represented in (see class documentation). For example, an object may be represented differently in SELECTED mode compared to DEFAULT mode. The returned bounds of the representation must take this different representation into account.
      aGXYContext - the context for which the representation of the object is painted. It contains amongst others the transformations from model to world and world to view.
      aBoundsSFCT - the bounds that must be adapted to encompass the representation of the object in the given mode and context. These bounds must not be taken into account when the method has thrown an exception.
      Throws:
      TLcdNoBoundsException - if no bounds can be determined for the representation of the object. This can happen when the object does not have a representation in the given context, for example when it is located in a part of the world which is not visible in the current view.
      See Also:
    • isTouched

      public boolean isTouched(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext)
      Description copied from interface: ILcdGXYPainter
      Checks if the representation of the object in the given mode is touched at the location as defined in the supplied context.

      The location that must be taken into account to check whether the representation is touched can be retrieved from the context passed with the methods ILcdGXYContext.getX() and ILcdGXYContext.getY(). If the check is part of an ongoing operation of user interaction, for example, when the mouse is being dragged, the location of the start of the operation can also be taken into account using the methods ILcdGXYContext.getDeltaX() and ILcdGXYContext.getDeltaY(). The context contains the transformations required to convert this location into the equivalent location in model space. Implementations of this interface usually follow either of the following patterns:

      • transform the location of the interaction back to model space and compare the coordinates with the object in model space.
      • transform the location to world space and compare with a world representation of the object. This forces the painter into caching a world representation of the object. Caching a view representation of an object is not very practical as it would have to change whenever the view's scale changes or when it is panned. A world representation of an object only changes when the view's XYWorldReference changes, which happens less frequently.

      As the mode influences the way an object is represented, it must also be taken into account when checking whether that representation is being touched. When the mode contains CREATING, RESHAPING or TRANSLATING which indicate that the object must be represented in a state for an ongoing operation, the location of the start of the operation may be taken into account as mentioned above. The painting result can take into account multiple locations, to respond to, for example, multi-touch input. When the mode contains SELECTED, the painter should also check if the non-selected representation is touched, since these are always painted on top of each other.

      The boundsSFCT is often used to speed up the performance of this method as a location outside these bounds can never touch the representation of the object.

      Note that this method does not give an indication of what part of the object is touched. It is up to the painter implementations to provide methods to make this distinction. The method does also not indicate what sensitivity must be applied when checking if an object is touched. It is up to the implementation to decide what should be the maximum distance between the location given in the context and the closest relevant point or area of the representation of the object.

      Parameters:
      aGraphics - the Graphics on which the representation of the object is painted
      aMode - the mode the object is represented in
      aGXYContext - contains the location of the interaction and the transformations to convert this location into model coordinates
      Returns:
      true if the representation of the object in the given mode is touched by the location as defined in the context passed, false otherwise
      See Also:
    • getStartResolutionFactor

      public double getStartResolutionFactor()
      See Also:
    • getStopResolutionFactor

      public double getStopResolutionFactor()
      See Also:
    • getLevelSwitchFactor

      public double getLevelSwitchFactor()
      See Also:
    • getLevelSwitchScales

      public double[] getLevelSwitchScales()
      See Also:
    • getStartScale

      public double getStartScale()
      Returns the start scale.
      Returns:
      the start scale currently used to determine whether or not images or outlines should be painted at a certain view scale.
      See Also:
    • getStopScale

      public double getStopScale()
      Returns the stop scale.
      Returns:
      the stop scale currently used to determine whether or not images should be painted at a certain view scale.
      See Also:
    • isForcePainting

      public boolean isForcePainting()
      See Also:
    • isPaintOutline

      public boolean isPaintOutline()
      See Also:
    • getOutlineStyle

      public ILcdGXYPainterStyle getOutlineStyle()
      Returns the style that is used to draw the bounds of images and/or tiles.
      Returns:
      a painter style or null
    • getOutlineColor

      public Color getOutlineColor()
      See Also:
    • isFillOutlineArea

      public boolean isFillOutlineArea()
      See Also:
    • getOutlineAreaFillStyle

      public ILcdGXYPainterStyle getOutlineAreaFillStyle()
      See Also:
    • getMaxNumberOfOutlineTiles

      public int getMaxNumberOfOutlineTiles()
      See Also:
    • setStartResolutionFactor

      public void setStartResolutionFactor(double aFactor)
      Sets the highest pixel density (number of image pixels per screen pixel) at which an image is painted. If the pixel density is too high, only the image outlines and tile outlines are painted (or a lower resolution level is chosen). This can avoid having to load a large image to fill a relatively small view.
    • setStopResolutionFactor

      public void setStopResolutionFactor(double aFactor)
      Sets the lowest pixel density (number of image pixels per screen pixel) at which an image is painted. If the pixel density is too low, nothing is painted. This can avoid painting overly pixelated images.
    • setLevelSwitchFactor

      public void setLevelSwitchFactor(double aLevelSwitchFactor)
      Sets the factor that affects the scale point at which a raster level is selected. The default value is 1.0: as soon as a single raster pixel would project to several screen pixels, a higher resolution level is used. This way, the highest practical raster quality is chosen. A value smaller than 1.0 delays this switching: a single raster pixel may project to multiple screen pixels. Such a value may cause pixelating effects, but it can reduce the burden of loading, decoding, and caching rasters.
    • setLevelSwitchScales

      public void setLevelSwitchScales(double[] aLevelSwitchScales)
      Sets the scales at which the painter will switch between image levels. The number of values must be equal to the number of image levels minus 1. They should be specified in ascending order, corresponding to image levels with increasing resolutions.

      If the scales are not set (default), the pixel density is used to automatically determine the level to be painted (also see setLevelSwitchFactor).

      Parameters:
      aLevelSwitchScales - the level switch scales
      See Also:
    • setForcePainting

      public void setForcePainting(boolean aForcePainting)
      Specifies whether the visible portion of the image should always be painted, irrespective of the startResolutionFactor and stopResolutionFactor.
      See Also:
    • setOpacity

      public void setOpacity(float aOpacity)
      Sets the opacity of the image. It is an alpha value between 0 and 1, with 0 being fully transparent, and 1 (the default) being fully opaque.
      Parameters:
      aOpacity - opacity value
    • getOpacity

      public float getOpacity()
      Returns the current opacity setting.
      Returns:
      the current opacity setting
      See Also:
    • setPaintOutline

      public void setPaintOutline(boolean aPaintOutline)
      Specifies whether the image outlines and tile outlines should be painted when the pixel density (number of image pixels per screen pixel) of the image to be painted is higher than the startResolutionFactor.
      See Also:
    • setOutlineStyle

      public void setOutlineStyle(ILcdGXYPainterStyle aOutlineStyle)
      Sets the style that is used when drawing the bounds of the image and/or tiles. If set to a non-null value the configure style will take precedence over the configured outline color if the style modifies the Graphics current color.
      Parameters:
      aOutlineStyle - the outline style to use
      See Also:
    • setOutlineColor

      public void setOutlineColor(Color aColor)
      Sets the line color used to paint the image outlines and tile outlines when the pixel density (number of image pixels per screen pixel) of the image to be painted is higher than the startResolutionFactor.
      See Also:
    • setFillOutlineArea

      public void setFillOutlineArea(boolean aFillOutlineArea)
      Specifies whether the image outlines and tile outlines should be filled when the pixel density (number of image pixels per screen pixel) of the image to be painted is higher than the startResolutionFactor.
      See Also:
    • setOutlineAreaFillStyle

      public void setOutlineAreaFillStyle(ILcdGXYPainterStyle aFillStyle)
      Sets the style that is used when filling the outline area of images and/or tiles. If the fill style is set to null and fill outline area is enabled the result visual result on screen is undefined.
      Parameters:
      aFillStyle - the fill style to use
      See Also:
    • setMaxNumberOfOutlineTiles

      public void setMaxNumberOfOutlineTiles(int aMaxNumberOfOutlineTiles)
      Sets the maximum number of outlines of individual tiles to paint when the pixel density (number of image pixels per screen pixel) of the image to be painted is higher than the startResolutionFactor. If the number of tiles is larger than this maximum, only the global outline of the image is painted.
      See Also:
    • setStartScale

      public void setStartScale(double aStartScale)
      As an alternative for the start resolution factor and stop resolution factor, this method and getStopScale() can be used for more intuitive control on when to paint an image and when to paint the outline. When the internal scale of the view (ILcdGXYView.getScale() is smaller than the start scale, the outline will be painted in stead of the image. The default value is 0. Warning: when the view scale is in between the start and stop scale, the start resolution factor and the stop resolution factor are still used as a second check. If you don't want interference from these two settings, set the start resolution factor to Double.POSITIVE_INFINITY and the stop resolution factor to 0.
      Parameters:
      aStartScale - The view scale at which one starts painting the image rather that the outline (when zooming in).
      See Also:
    • setStopScale

      public void setStopScale(double aStopScale)
      As an alternative for the start resolution factor and stop resolution factor, this method and getStartScale() can be used for more intuitive control on when to paint an image. When the internal scale of the view (ILcdGXYView.getScale() is larger than the stop scale, the image won't be painted. The default value is Double.POSITIVE_INFINITY.
      Parameters:
      aStopScale - The view scale at which one stops painting the image (when zooming in).
      See Also:
    • setAvoidOpaqueBorder

      public void setAvoidOpaqueBorder(boolean aAvoidOpaqueBorder)
      Specifies whether the painter should avoid drawing opaque borders around transformed images.

      The painter normally uses the default pixel of an image when painting the border around a transformed image. If the default pixel is transparent, the border is invisible. Otherwise, the border is opaque. This typically occurs if an image has an IndexColorModel without a transparent color index.

      Setting this property activates some additional processing to avoid the opaque border anyway. The processing overhead can run up to 50% when painting described images. Leaving the property unset is therefore preferable, for instance when the area around painted images is not relevant for the application. The default is false.

    • isAvoidOpaqueBorder

      public boolean isAvoidOpaqueBorder()
      See Also:
    • setOversamplingRate

      public void setOversamplingRate(int aOverSamplingRate)
      Sets the number of samples used per pixel when transforming a image. The default is 1. The total number of samples used per pixel equals (aOverSamplingRate * aOverSamplingRate). For instance, if the oversampling rate is set to 2, the painter will take 4 samples per pixel and average their values. This increases the image quality, especially if the image contains sharp edges, but it also increases the computational cost.

      This property is only relevant for images that have to be warped, that is, when the model reference of the image is different from the world reference of the view.

      Parameters:
      aOverSamplingRate - the number of samples used per pixel in one direction.
    • getOversamplingRate

      public int getOversamplingRate()
      Returns the sampling rate used when transforming the image. The returned value equals the number of samples used per pixel in one direction.
      See Also:
    • setWarpBlockSize

      public void setWarpBlockSize(int aWarpBlockSize)
      Sets the width and height of the block in which the image transformation is approximated using bilinear interpolation. Smaller values result in more accurate results, but also larger computation times. The default is 64. With a value of 1, every pixel is transformed without approximation.

      This property is only relevant for images that have to be warped, that is, when the model reference of the image is different from the world reference of the view.

      Parameters:
      aWarpBlockSize - the width and height, expressed in pixels.
    • getWarpBlockSize

      public int getWarpBlockSize()
      Returns the width and height of the block in which the image transformation is approximated using bilinear interpolation.
      See Also:
    • setBrightness

      public void setBrightness(float aBrightness)
      Sets the brightness that is applied to painted rasters. It is a value in [0, 2]. A value of 1 (the default) leaves the brightness unchanged. Values larger than 1 makes the colors brighter, while a value smaller than 1 makes the colors less bright.
      Parameters:
      aBrightness - the new brightness value
    • setContrast

      public void setContrast(float aContrast)
      Sets the contrast that is applied to painted rasters. It is a value in [0, 2]. A value of 1 (the default) leaves the contrast unchanged. A value larger than 1 enhances the contrast of dark colors by making them brighter, while a value smaller than 1 enhances the contrast of bright colors by making them darker.
      Parameters:
      aContrast - the new contrast value
    • getBrightness

      public float getBrightness()
      Returns the current brightness value.
      Returns:
      the current brightness value
      See Also:
    • getContrast

      public float getContrast()
      Returns the current contrast value.
      Returns:
      the current contrast value
      See Also:
    • isAsynchronousTileRequestAllowed

      public boolean isAsynchronousTileRequestAllowed()
      Returns whether the tiles can be requested asynchronously.

      Requesting tiles asynchronously typically improves responsiveness. However the data may temporarily painted at a lower resolution while requests for more detailed data are in progress. In practice this means that this feature should typically be disabled when a fully up-to-date view is required. For example when using an off-screen view to create a screenshot of the layer. If this feature is disabled then the repaint on tile available should typically also be disabled.

      Asynchronous tile requests are allowed by default.

      Returns:
      true if the tiles can be requested asynchronously
      See Also:
    • setAsynchronousTileRequestAllowed

      public void setAsynchronousTileRequestAllowed(boolean aAsynchronousTileRequestAllowed)
      Sets whether the tiles can be requested asynchronously.
      Parameters:
      aAsynchronousTileRequestAllowed - true if the tiles can be requested asynchronously
      See Also:
    • isRepaintViewWhenTileAvailable

      public boolean isRepaintViewWhenTileAvailable()
      Returns whether the view is repainted when a tile becomes available.

      This should typically only enabled when asynchronous tile requests are allowed.

      Returns:
      whether the view is repainted when a tile becomes available
      See Also:
    • setRepaintViewWhenTileAvailable

      public void setRepaintViewWhenTileAvailable(boolean aRepaintViewWhenTileAvailable)
      Sets whether the view is repainted when a tile becomes available.
      Parameters:
      aRepaintViewWhenTileAvailable - whether the view should repainted when a tile becomes available
      See Also:
    • clone

      public Object clone()
      Description copied from interface: ILcdCloneable

      Makes Object.clone() public.

      When for example extending from java.lang.Object, it can be implemented like this:
      
       public Object clone() {
         try {
           return super.clone();
         } catch ( CloneNotSupportedException e ) {
           // Cannot happen: extends from Object and implements Cloneable (see also Object.clone)
           throw new RuntimeException( e );
         }
       }
       
      Specified by:
      clone in interface ILcdCloneable
      Specified by:
      clone in interface ILcdGXYPainterProvider
      Overrides:
      clone in class ALcdGXYPainter
      Returns:
      a clone of this painter provider.
      See Also: