com.bbn.openmap.omGraphics
Class OMScalingRaster

java.lang.Object
  extended by com.bbn.openmap.omGraphics.geom.BasicGeometry
      extended by com.bbn.openmap.omGraphics.OMGraphicAdapter
          extended by com.bbn.openmap.omGraphics.OMRasterObject
              extended by com.bbn.openmap.omGraphics.OMRaster
                  extended by com.bbn.openmap.omGraphics.OMScalingRaster
All Implemented Interfaces:
OMGeometry, OMGraphic, OMGraphicConstants, java.awt.image.ImageObserver, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
ImageTile, OMScalingIcon

public class OMScalingRaster
extends OMRaster
implements java.io.Serializable

This is an extension to OMRaster that automatically scales itelf to match the current projection. It is only lat/lon based, and takes the coordinates of the upper left and lower right corners of the image. It does straight scaling - it does not force the image projection to match the map projection! So, your mileage may vary - you have to understand the projection of the image, and know how it fits the projection type of the map. Of course, at larger scales, it might not matter so much. This class was inspired by, and created from parts of the ImageLayer submission from Adrian Lumsden@sss, on 25-Jan-2002. Used the scaling and trimming code from that submission. That code was also developed with assistance from Steve McDonald at SiliconSpaceships.com.

See Also:
OMRaster, OMRasterObject, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.bbn.openmap.omGraphics.OMRasterObject
OMRasterObject.TrimScaleFilter
 
Field Summary
protected  java.awt.Rectangle clipRect
          The rectangle in screen coordinates that the scaled image projects to after clipping.
protected  java.util.ArrayList<float[]> corners
           
protected  Projection lastProjection
          This lastProjection is used to keep track of the last projection used to warp or scale the image, an used during the rendering process to check if we should rework the image to be displayed.
protected  double lat2
          The latitude of the lower right corner for the image, in decimal degrees.
protected  double lon2
          The longitude of the lower right corner for the image, in decimal degrees.
protected  int scaleTransformType
          Transform type for AffineTransformOp to use to scale images.
protected  java.awt.image.AffineTransformOp scalingXFormOp
          AffineTransformOp applied to the bitmap at render time.
 
Fields inherited from class com.bbn.openmap.omGraphics.OMRaster
colors, transparent
 
Fields inherited from class com.bbn.openmap.omGraphics.OMRasterObject
bitmap, bits, colorModel, COLORMODEL_DIRECT, COLORMODEL_IMAGEICON, COLORMODEL_INDEXED, DEBUG, FAST_SCALING, filteredHeight, filteredWidth, height, imageFilter, lat, logger, lon, needToReposition, pixels, point1, point2, renderRotationAngle, rotationAngle, SMOOTH_SCALING, width, x, y
 
Fields inherited from class com.bbn.openmap.omGraphics.OMGraphicAdapter
declutterType, displayPaint, edgeMatchesFill, fillPaint, hasLabel, linePaint, matted, mattingPaint, renderType, selected, selectPaint, showEditablePalette, stroke, textureMask
 
Fields inherited from class com.bbn.openmap.omGraphics.geom.BasicGeometry
attributes, lineType, needToRegenerate, shape, visible
 
Fields inherited from interface com.bbn.openmap.omGraphics.OMGraphicConstants
ADD_GRAPHIC_MASK, APP_OBJECT, BASIC_STROKE, CHANGE_APPEARANCE, clear, DECIMAL_DEGREES, DECLUTTERTYPE_LINE, DECLUTTERTYPE_MOVE, DECLUTTERTYPE_NONE, DECLUTTERTYPE_SPACE, DEFAULT_ROTATIONANGLE, DELETE_GRAPHIC_MASK, DESELECT_GRAPHIC_MASK, DESELECTALL_GRAPHIC_MASK, GRAPHICTYPE_ARC, GRAPHICTYPE_BITMAP, GRAPHICTYPE_CIRCLE, GRAPHICTYPE_ELLIPSE, GRAPHICTYPE_GRAPHIC, GRAPHICTYPE_GRID, GRAPHICTYPE_LINE, GRAPHICTYPE_POINT, GRAPHICTYPE_POLY, GRAPHICTYPE_RASTER, GRAPHICTYPE_RECTANGLE, GRAPHICTYPE_TEXT, INDEX, INFOLINE, LABEL, LINETYPE_GREATCIRCLE, LINETYPE_RHUMB, LINETYPE_STRAIGHT, LINETYPE_UNKNOWN, LOWER_GRAPHIC_MASK, LOWER_TO_BOTTOM_GRAPHIC_MASK, NO_ROTATE, OMGRAPHIC_ELT, OMGRAPHIC_TYPE_ATTR, RADIANS, RAISE_GRAPHIC_MASK, RAISE_TO_TOP_GRAPHIC_MASK, REMOVABLE, RENDERTYPE_LATLON, RENDERTYPE_OFFSET, RENDERTYPE_UNKNOWN, RENDERTYPE_XY, SELECT_GRAPHIC_MASK, SORT_GRAPHICS_MASK, TOOLTIP, UPDATE_GRAPHIC_MASK, UPDATED
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
OMScalingRaster()
          Construct a blank OMRaster, to be filled in with set calls.
OMScalingRaster(double ullat, double ullon, double lrlat, double lrlon, java.awt.Image ii)
          Create an OMRaster, Lat/Lon placement with an Image.
OMScalingRaster(double ullat, double ullon, double lrlat, double lrlon, javax.swing.ImageIcon ii)
          Create an OMRaster, Lat/Lon placement with an ImageIcon.
OMScalingRaster(double ullat, double ullon, double lrlat, double lrlon, int w, int h, byte[] bytes, java.awt.Color[] colorTable, int trans)
          Lat/Lon placement with a indexed colormodel, which is using a colortable and a byte array to construct the int[] pixels.
OMScalingRaster(double ullat, double ullon, double lrlat, double lrlon, int w, int h, int[] pix)
          Creates an OMRaster images, Lat/Lon placement with a direct colormodel image.
 
Method Summary
 boolean generate(Projection proj)
          Prepare the graphics for rendering.
 java.awt.Rectangle getClippedRectangle()
          Return the rectangle in screen co-ordinates that the scaled image has been clipped to.
 ImageWarp getImageWarp(GeoCoordTransformation transform)
          Creates an ImageWarp object from the contents of the OMScalingRaster.
 double getLRLat()
          Get the southern latitude.
 double getLRLon()
          Get the eastern longitude.
 int getScaleTransformType()
           
 double getULLat()
          Get the upper latitude.
 double getULLon()
          Get the western longitude.
 boolean isOnMap(Projection proj)
          Test to see if projected image is on map.
protected  boolean position(Projection proj)
          Since the image doesn't necessarily need to be regenerated when it is merely moved, raster objects have this function, called from generate() and when a placement attribute is changed.
 void render(java.awt.Graphics graphics)
          Render the raster on the java.awt.Graphics.
protected  void renderImage(java.awt.Graphics g, java.awt.Image image, java.awt.Point loc)
          Render the image at the given pixel location.
 void restore(OMGeometry source)
          Takes the generic OMGraphic settings from another OMGraphic and pushes them to this one.
protected  void rotate(java.awt.Graphics2D g)
          Since the OMScalingRaster changes height and width depending on scale, we need to rotate the image over that point and factor in the scaled height and width of the image.
protected  void scaleTo(Projection thisProj)
          Take the current projection and the sourceImage, and make the image that gets displayed fit the projection.
 void setLRLat(double value)
          Change the southern latitude attribute.
 void setLRLon(double value)
          Change the eastern longitude attribute.
 void setScaleTransformType(int scaleTransformType)
          Set the AffineTransformOp used for scaling images.
 void setShape()
          Set the rectangle, based on the location and size of the image after scaling.
 void setULLat(double value)
          Change the upper latitude attribute.
 void setULLon(double value)
          Change the western longitude attribute.
protected  boolean updateImageForProjection(Projection proj)
          Called from within generate.
 
Methods inherited from class com.bbn.openmap.omGraphics.OMRaster
computePixels, evaluateRotationAngle, getBitmapFromInternalData, getByte, getColors, getPixel, getTransparent, setBits, setByte, setColors, setColors, setImageIcon, setPixel, setTransparent
 
Methods inherited from class com.bbn.openmap.omGraphics.OMRasterObject
adjustShapeForRotation, filterImage, getBits, getColorModel, getFilteredHeight, getFilteredWidth, getHeight, getImage, getImageFilter, getLat, getLon, getMapLocation, getNeedToReposition, getPixels, getRotationAngle, getWidth, getX, getY, hasLineTypeChoice, imageUpdate, regenerate, scaleTo, setColorModel, setHeight, setImage, setImageFilter, setLat, setLon, setNeedToReposition, setPixels, setRotationAngle, setWidth, setX, setY, shouldRenderFill
 
Methods inherited from class com.bbn.openmap.omGraphics.OMGraphicAdapter
clone, deselect, distance, getDeclutterType, getDisplayColor, getDisplayPaint, getEdgeMatchesFill, getFillColor, getFillPaint, getHasLabel, getLineColor, getLinePaint, getMattingPaint, getRenderType, getSelectColor, getSelectPaint, getShowEditablePalette, getStroke, getTextureMask, initLabelingDuringGenerate, isClear, isMatted, isSelected, normalizeDistanceForLineWidth, readStroke, readTextureMask, renderLabel, renderShape, select, setDeclutterType, setEdgeMatchesFill, setFillColor, setFillPaint, setGraphicsColor, setGraphicsForEdge, setGraphicsForFill, setHasLabel, setLabelLocation, setLabelLocation, setLabelLocation, setLabelLocation, setLabelLocation, setLabelLocation, setLabelLocation, setLabelLocation, setLineColor, setLinePaint, setMatted, setMattingPaint, setRenderType, setSelectColor, setSelected, setSelectPaint, setShowEditablePalette, setStroke, setTextureMask, shouldRenderEdge, writeStroke, writeTextureMask
 
Methods inherited from class com.bbn.openmap.omGraphics.geom.BasicGeometry
_distance, appendShapeEdge, appendShapeEdge, appendShapeEdge, appendShapeEdge, clearAttributes, contains, createAttributeMap, createBoxShape, createShape, createShape, describeShapeDetail, describeShapeDetail, distanceToEdge, distanceToEdge, draw, draw, fill, fill, getAppObject, getAttribute, getAttributes, getDescription, getLineType, getNeedToRegenerate, getShape, isRenderable, isRenderable, isVisible, putAttribute, removeAttribute, setAppObject, setAttributes, setLineType, setNeedToRegenerate, setShape, setVisible
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.bbn.openmap.omGraphics.OMGraphic
clone, deselect, getDeclutterType, getDisplayColor, getDisplayPaint, getFillColor, getFillPaint, getLineColor, getLinePaint, getMattingPaint, getRenderType, getSelectColor, getSelectPaint, getShowEditablePalette, getStroke, getTextureMask, isMatted, isSelected, normalizeDistanceForLineWidth, renderLabel, select, setDeclutterType, setFillPaint, setGraphicsColor, setGraphicsForEdge, setGraphicsForFill, setLabelLocation, setLabelLocation, setLabelLocation, setLinePaint, setMatted, setMattingPaint, setRenderType, setSelected, setSelectPaint, setShowEditablePalette, setStroke, setTextureMask, shouldRenderEdge
 
Methods inherited from interface com.bbn.openmap.omGraphics.OMGeometry
clearAttributes, contains, distance, distanceToEdge, draw, draw, fill, fill, getAppObject, getAttribute, getAttributes, getDescription, getLineType, getNeedToRegenerate, getShape, isRenderable, isRenderable, isVisible, putAttribute, removeAttribute, setAppObject, setAttributes, setLineType, setNeedToRegenerate, setShape, setVisible
 

Field Detail

lat2

protected double lat2
The latitude of the lower right corner for the image, in decimal degrees.


lon2

protected double lon2
The longitude of the lower right corner for the image, in decimal degrees.


scalingXFormOp

protected java.awt.image.AffineTransformOp scalingXFormOp
AffineTransformOp applied to the bitmap at render time.


clipRect

protected transient java.awt.Rectangle clipRect
The rectangle in screen coordinates that the scaled image projects to after clipping.


corners

protected transient java.util.ArrayList<float[]> corners

scaleTransformType

protected int scaleTransformType
Transform type for AffineTransformOp to use to scale images.


lastProjection

protected Projection lastProjection
This lastProjection is used to keep track of the last projection used to warp or scale the image, an used during the rendering process to check if we should rework the image to be displayed.

Constructor Detail

OMScalingRaster

public OMScalingRaster()
Construct a blank OMRaster, to be filled in with set calls.


OMScalingRaster

public OMScalingRaster(double ullat,
                       double ullon,
                       double lrlat,
                       double lrlon,
                       int w,
                       int h,
                       int[] pix)
Creates an OMRaster images, Lat/Lon placement with a direct colormodel image.

Parameters:
ullat - latitude of the top of the image.
ullon - longitude of the left side of the image.
lrlat - latitude of the bottom of the image.
lrlon - longitude of the right side of the image.
w - width of the image, in pixels.
h - height of the image, in pixels.
pix - color values for the pixels.

OMScalingRaster

public OMScalingRaster(double ullat,
                       double ullon,
                       double lrlat,
                       double lrlon,
                       javax.swing.ImageIcon ii)
Create an OMRaster, Lat/Lon placement with an ImageIcon.

Parameters:
ullat - latitude of the top of the image.
ullon - longitude of the left side of the image.
lrlat - latitude of the bottom of the image.
lrlon - longitude of the right side of the image.
ii - ImageIcon used for the image.

OMScalingRaster

public OMScalingRaster(double ullat,
                       double ullon,
                       double lrlat,
                       double lrlon,
                       java.awt.Image ii)
Create an OMRaster, Lat/Lon placement with an Image.

Parameters:
ullat - latitude of the top of the image.
ullon - longitude of the left side of the image.
lrlat - latitude of the bottom of the image.
lrlon - longitude of the right side of the image.
ii - Image used for the image.

OMScalingRaster

public OMScalingRaster(double ullat,
                       double ullon,
                       double lrlat,
                       double lrlon,
                       int w,
                       int h,
                       byte[] bytes,
                       java.awt.Color[] colorTable,
                       int trans)
Lat/Lon placement with a indexed colormodel, which is using a colortable and a byte array to construct the int[] pixels.

Parameters:
ullat - latitude of the top of the image.
ullon - longitude of the left side of the image.
lrlat - latitude of the bottom of the image.
lrlon - longitude of the right side of the image.
w - width of the image, in pixels.
h - height of the image, in pixels.
bytes - colortable index values for the pixels.
colorTable - color array corresponding to bytes
trans - transparency of image.
Method Detail

position

protected boolean position(Projection proj)
Since the image doesn't necessarily need to be regenerated when it is merely moved, raster objects have this function, called from generate() and when a placement attribute is changed.

Overrides:
position in class OMRasterObject
Parameters:
proj - projection of window.
Returns:
true if enough information is in the object for proper placement.

generate

public boolean generate(Projection proj)
Prepare the graphics for rendering. For all image types, it positions the image relative to the projection. For direct and indexed colormodel images, it creates the ImageIcon used for drawing to the window (internal to object). For indexed colormodel images, it also calls computePixels, to resolve the colortable and the bytes to create the image pixels.

Specified by:
generate in interface OMGeometry
Overrides:
generate in class OMRaster
Parameters:
proj - Projection used to position the image on the window.
Returns:
true if the image is ready to paint.
See Also:
OMGraphicAdapter.regenerate(com.bbn.openmap.proj.Projection)

updateImageForProjection

protected boolean updateImageForProjection(Projection proj)
Called from within generate. Some render buffering calls generate to make sure the latest projection is called on an OMGraphic before it's put into a buffer. We're keeping track of the last projection used to generate the warped image, and if it's the same, don't bother regenerating, use the raster we have. This method is a question: do we need to update the image because of a projection change?

Parameters:
proj - current projection.
Returns:
false if the projection shouldn't cause anything to change for the image.

rotate

protected void rotate(java.awt.Graphics2D g)
Since the OMScalingRaster changes height and width depending on scale, we need to rotate the image over that point and factor in the scaled height and width of the image. Called from within OMRasterObject.render().

Overrides:
rotate in class OMRasterObject
Parameters:
g - Graphics2D object to rotate and translate.

scaleTo

protected void scaleTo(Projection thisProj)
Take the current projection and the sourceImage, and make the image that gets displayed fit the projection. If the source image isn't over the map, then this OMGraphic is set to be invisible. If part of the image is on the map, only that part is used. The OMRaster bitmap variable is set with an image that is created from the source image, and the point1 variable is set to the point where the image should be placed. For instance, if the source image upper left corner is off the map to the NorthWest, then the OMRaster bitmap is set to a image, clipped from the source, that is entirely on the map. The OMRaster point1 is set to 0, 0, since that is where the clipped image should be placed.

Parameters:
thisProj - the projection that the image should be scaled to.

render

public void render(java.awt.Graphics graphics)
Render the raster on the java.awt.Graphics. Overrides the raster method because it checks to see if the raster is in a small-world situation, where the image must wrap around the world.

Specified by:
render in interface OMGeometry
Overrides:
render in class OMRasterObject
Parameters:
graphics - java.awt.Graphics to draw the image on.

renderImage

protected void renderImage(java.awt.Graphics g,
                           java.awt.Image image,
                           java.awt.Point loc)
Render the image at the given pixel location. This method should be overridden for special Image handling.

Overrides:
renderImage in class OMRasterObject
Parameters:
g - the Graphics object to render the image into. Assumes this is a derivative of the Graphics passed into the OMGraphic, and can be modified without worrying about passing settings on to other OMGraphics.
image - the image to render.
loc - the pixel location of the image.

getClippedRectangle

public java.awt.Rectangle getClippedRectangle()
Return the rectangle in screen co-ordinates that the scaled image has been clipped to. This may return a null rectangle (i.e. the image is out of the window). Otherwise the returned rectangle should always at least partially lie within the bounds of the window.


setULLat

public void setULLat(double value)
Change the upper latitude attribute.

Parameters:
value - latitude in decimal degrees.

getULLat

public double getULLat()
Get the upper latitude.

Returns:
the latitude in decimal degrees.

setULLon

public void setULLon(double value)
Change the western longitude attribute.

Parameters:
value - the longitude in decimal degrees.

getULLon

public double getULLon()
Get the western longitude.

Returns:
longitude in decimal degrees.

setLRLat

public void setLRLat(double value)
Change the southern latitude attribute.

Parameters:
value - latitude in decimal degrees.

getLRLat

public double getLRLat()
Get the southern latitude.

Returns:
the latitude in decimal degrees.

setLRLon

public void setLRLon(double value)
Change the eastern longitude attribute.

Parameters:
value - the longitude in decimal degrees.

getLRLon

public double getLRLon()
Get the eastern longitude.

Returns:
longitude in decimal degrees.

setShape

public void setShape()
Set the rectangle, based on the location and size of the image after scaling.

Overrides:
setShape in class OMRasterObject

isOnMap

public boolean isOnMap(Projection proj)
Test to see if projected image is on map.

Parameters:
proj - current projection
Returns:
true of projected image location intersects map area.

getScaleTransformType

public int getScaleTransformType()

setScaleTransformType

public void setScaleTransformType(int scaleTransformType)
Set the AffineTransformOp used for scaling images. Default is AffineTransformOp.TYPE_BILINEAR. Can also be AffineTransformOp.TYPE_BICUBIC or AffineTransformOp.TYPE_NEAREST_NEIGHBOR.

Parameters:
scaleTransformType -

getImageWarp

public ImageWarp getImageWarp(GeoCoordTransformation transform)
Creates an ImageWarp object from the contents of the OMScalingRaster. This can be used in an OMWarpingImage to be used for display in projections that don't match the raster's projection.

Parameters:
transform - the OMScalingImage assumes that the coordinates/pixel transformation of the image is equal arc. If it's not, the correct transformation should be provided for this query. The OMScalingRaster doesn't really know what it is, it just plots the corner coordinates and scales the image accordingly.
Returns:
ImageWarp an ImageWarp if all the required information was provided, null if not.

restore

public void restore(OMGeometry source)
Description copied from class: OMGraphicAdapter
Takes the generic OMGraphic settings from another OMGraphic and pushes them to this one.

Specified by:
restore in interface OMGeometry
Overrides:
restore in class OMRaster


Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details