NASA World Wind

gov.nasa.worldwind.render
Class AbstractSurfaceObject

java.lang.Object
  extended by gov.nasa.worldwind.avlist.AVListImpl
      extended by gov.nasa.worldwind.WWObjectImpl
          extended by gov.nasa.worldwind.render.AbstractSurfaceObject
All Implemented Interfaces:
AVList, MessageListener, OrderedRenderable, PreRenderable, Renderable, SurfaceObject, WWObject, PropertyChangeListener, EventListener
Direct Known Subclasses:
AbstractSurfaceRenderable, AbstractSurfaceShape, AnalyticSurface.AnalyticSurfaceObject, SurfaceText

public abstract class AbstractSurfaceObject
extends WWObjectImpl
implements SurfaceObject

Abstract implementation of SurfaceObject that participates in the SceneController's bulk rendering of SurfaceObjects. The SceneControllers bulk renders all SurfaceObjects added to the DrawContext's ordered surface renderable queue during the preRendering pass. While building the composite representation the SceneController invokes render(DrawContext) in ordered rendering mode. To avoid overloading the purpose of the render method, AbstractSurfaceObject does not add itself to the DrawContext's ordered surface renderable queue during rendering.

Subclasses that do not wish to participate in this composite representation can override this behavior as follows:

  1. Override makeOrderedPreRenderable(DrawContext); do not add this object to the draw context's ordered renderable queue. Perform any preRender processing necessary for the subclass to pick and render itself.
  2. Override pickOrderedRenderable(DrawContext, PickSupport); draw the custom pick representation.
  3. Override makeOrderedRenderable(DrawContext); add this object to the draw context's ordered renderable queue. AbstractSurfaceObject does not add itself to this queue during rendering. render() is called from the SceneController while building the composite representation because AbstractSurfaceObject adds itself to the ordered surface renderable queue during preRendering.
  4. Override drawOrderedRenderable(DrawContext); draw the custom representation. Unlike AbstractSurfaceObject subclasses should assume the modelview and projection matrices are consistent with the current View.


Nested Class Summary
protected static class AbstractSurfaceObject.CacheEntry
          Represents a globe dependent cache entry.
protected static class AbstractSurfaceObject.SurfaceObjectStateKey
          Represents a surface object's current state.
 
Field Summary
protected  Object delegateOwner
           
protected  boolean drawBoundingSectors
           
protected  boolean enableBatchPicking
           
protected  Map<Object,AbstractSurfaceObject.CacheEntry> extentCache
           
protected  long lastModifiedTime
           
protected static long nextUniqueId
           
protected  Layer pickLayer
           
protected  PickSupport pickSupport
           
protected  SurfaceObjectTileBuilder pickTileBuilder
          Support class used to build surface tiles used to draw the pick representation.
protected  Collection<SurfaceTile> pickTiles
          The pick representation.
protected  long uniqueId
           
protected  boolean visible
           
 
Constructor Summary
AbstractSurfaceObject()
          Creates a new AbstractSurfaceObject, assigning it a unique ID and initializing its last modified time to the current system time.
 
Method Summary
protected  void buildPickRepresentation(DrawContext dc)
          Builds this AbstractSurfaceObject's pickable representation.
protected  void clearCaches()
          Clears this SurfaceObject's internal extent cache.
protected  Extent computeExtent(DrawContext dc)
          Computes the surface object's extent.
protected  Extent computeExtent(Globe globe, double verticalExaggeration, List<Sector> sectors)
          Computes an extent bounding the the specified sectors on the specified Globe's surface.
protected  PickedObject createPickedObject(DrawContext dc, Color pickColor)
          Create a PickedObject for this surface object.
protected  SurfaceObjectTileBuilder createPickTileBuilder()
          Returns a SurfaceObjectTileBuilder appropriate for building and drawing the surface object's pickable representation.
protected  void drawBoundingSectors(DrawContext dc, SurfaceTileDrawContext sdc)
          Causes this SurfaceObject to render its bounding sectors to the specified region in geographic coordinates.
protected abstract  void drawGeographic(DrawContext dc, SurfaceTileDrawContext sdc)
          Causes the SurfaceObject to render itself to the specified region in geographic coordinates.
protected  void drawOrderedRenderable(DrawContext dc)
          Causes the SurfaceObject to render itself.
protected  void drawPickRepresentation(DrawContext dc)
          Causes this SurfaceObject to draw a representation of itself suitable for use during picking.
 Object getDelegateOwner()
          Returns the delegate owner of the surface object.
 double getDistanceFromEye()
          Returns zero to indicate that the surface object's distance from the eye is unknown.
 Extent getExtent(DrawContext dc)
          Returns the surface object's enclosing volume as an Extent in model coordinates, given a specified DrawContext.
 Object getStateKey(DrawContext dc)
          Returns an object that uniquely identifies the surface object's state on the specified draw context.
protected  long getUniqueId()
          Returns an integer number uniquely identifying the surface object.
protected  boolean intersectsFrustum(DrawContext dc)
          Test if this SurfaceObject intersects the specified draw context's frustum.
protected  boolean intersectsPickFrustum(DrawContext dc)
          Test if this SurfaceObject intersects the specified draw context's pick frustums.
protected  boolean intersectsVisibleSector(DrawContext dc)
          Test if this SurfaceObject intersects the specified draw context's visible sector.
 boolean isDrawBoundingSectors()
          Indicates whether the SurfaceObject draws its bounding sector.
 boolean isEnableBatchPicking()
          Indicates whether batch picking is enabled.
 boolean isVisible()
          Indicates whether the surface object should be drawn during rendering.
protected  void makeOrderedPreRenderable(DrawContext dc)
          Prepares the SurfaceObject as an OrderedRenderable and adds it to the DrawContext's ordered surface renderable list.
protected  void makeOrderedRenderable(DrawContext dc)
          Prepares the SurfaceObject as an OrderedRenderable and adds it to the DrawContext's ordered surface renderable list.
protected static long nextUniqueId()
          Returns the next unique integer associated with an AbstractSurfaceObject.
 void pick(DrawContext dc, Point pickPoint)
          Causes the surface object to draw a pickable representation of itself on the surface terrain, using the provided draw context.
protected  void pickBatched(DrawContext dc, PickSupport pickSupport)
          Causes adjacent SurfaceObjects in the DrawContext's ordered surface renderable list to draw themselves in in a unique pick color, and adds themselves as pickable objects to the specified pickSupport.
protected  void pickOrderedRenderable(DrawContext dc, PickSupport pickSupport)
          Causes the SurfaceObject to draw itself in a unique pick color, and add itself as a pickable object to the specified pickSupport.
 void preRender(DrawContext dc)
          Causes the surface object to prepare a representation of itself which can be drawn on the surface terrain, using the provided draw context.
 void render(DrawContext dc)
          Causes the surface object to render a representation of itself on the surface terrain, using the provided draw context.
 void setDelegateOwner(Object owner)
          Specifies the delegate owner of the surface object.
 void setDrawBoundingSectors(boolean draw)
          Specifies if the SurfaceObject should draw its bounding sector.
 void setEnableBatchPicking(boolean enable)
          Specifies whether adjacent SurfaceObjects in the DrawContext's ordered surface renderable list may be rendered together during picking if they are contained in the same layer.
 void setVisible(boolean visible)
          Specifies whether the surface object should be drawn during rendering.
protected  void updateModifiedTime()
          Sets the SurfaceObject's modified time to the current system time.
 
Methods inherited from class gov.nasa.worldwind.WWObjectImpl
onMessage, propertyChange
 
Methods inherited from class gov.nasa.worldwind.avlist.AVListImpl
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getBooleanValue, getBooleanValue, getChangeSupport, getDoubleValue, getDoubleValue, getEntries, getIntegerValue, getIntegerValue, getLongValue, getLongValue, getRestorableStateForAVPair, getStringValue, getStringValue, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.nasa.worldwind.render.SurfaceObject
getSectors
 
Methods inherited from interface gov.nasa.worldwind.avlist.AVList
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getEntries, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
 

Field Detail

delegateOwner

protected Object delegateOwner

drawBoundingSectors

protected boolean drawBoundingSectors

enableBatchPicking

protected boolean enableBatchPicking

extentCache

protected Map<Object,AbstractSurfaceObject.CacheEntry> extentCache

lastModifiedTime

protected long lastModifiedTime

nextUniqueId

protected static long nextUniqueId

pickLayer

protected Layer pickLayer

pickSupport

protected PickSupport pickSupport

pickTileBuilder

protected SurfaceObjectTileBuilder pickTileBuilder
Support class used to build surface tiles used to draw the pick representation.


pickTiles

protected Collection<SurfaceTile> pickTiles
The pick representation. Populated each frame by the pickTileBuilder.


uniqueId

protected final long uniqueId

visible

protected boolean visible
Constructor Detail

AbstractSurfaceObject

public AbstractSurfaceObject()
Creates a new AbstractSurfaceObject, assigning it a unique ID and initializing its last modified time to the current system time.

Method Detail

buildPickRepresentation

protected void buildPickRepresentation(DrawContext dc)
Builds this AbstractSurfaceObject's pickable representation. This method is called during the preRender phase, and is therefore free to modify the framebuffer contents to create the pickable representation.

Parameters:
dc - the draw context to build a representation for.

clearCaches

protected void clearCaches()
Clears this SurfaceObject's internal extent cache.


computeExtent

protected Extent computeExtent(DrawContext dc)
Computes the surface object's extent. Uses the sector list returned by SurfaceObject.getSectors(DrawContext) to compute the extent bounding this object's sectors on the draw context's surface. This returns null if the surface object has no sectors.

Parameters:
dc - the draw context the extent relates to.
Returns:
the surface object's extent. Returns null if the surface object has no sectors.

computeExtent

protected Extent computeExtent(Globe globe,
                               double verticalExaggeration,
                               List<Sector> sectors)
Computes an extent bounding the the specified sectors on the specified Globe's surface. If the list contains a single sector this returns a box created by calling Sector.computeBoundingBox(gov.nasa.worldwind.globes.Globe, double, gov.nasa.worldwind.geom.Sector). If the list contains more than one sector this returns a Box containing the corners of the boxes bounding each sector. This returns null if the sector list is empty.

Parameters:
globe - the globe the extent relates to.
verticalExaggeration - the globe's vertical surface exaggeration.
sectors - the sectors to bound.
Returns:
an extent for the specified sectors on the specified Globe.

createPickedObject

protected PickedObject createPickedObject(DrawContext dc,
                                          Color pickColor)
Create a PickedObject for this surface object. The PickedObject created by this method will be added to the pick list to represent the current surface object.

Parameters:
dc - Active draw context.
pickColor - Unique color for this PickedObject.
Returns:
A new picked object.

createPickTileBuilder

protected SurfaceObjectTileBuilder createPickTileBuilder()
Returns a SurfaceObjectTileBuilder appropriate for building and drawing the surface object's pickable representation. The returned SurfaceObjectTileBuilder's is configured to create textures with the GL_ALPHA8 format, and to use GL_NEAREST filtering. This reduces a surface object's pick texture resources by a factor of 4, and ensures that linear texture filtering and mip-mapping is disabled while drawing the pick tiles.

Returns:
a SurfaceObjectTileBuilder used for building and drawing the surface object's pickable representation.

drawBoundingSectors

protected void drawBoundingSectors(DrawContext dc,
                                   SurfaceTileDrawContext sdc)
Causes this SurfaceObject to render its bounding sectors to the specified region in geographic coordinates. The specified viewport denotes the geographic region and its corresponding screen viewport.

The bounding sectors are rendered as a 1 pixel wide green outline.

Parameters:
dc - the current DrawContext.
sdc - the context containing a geographic region and screen viewport corresponding to a surface tile.
See Also:
SurfaceObject.getSectors(DrawContext)

drawGeographic

protected abstract void drawGeographic(DrawContext dc,
                                       SurfaceTileDrawContext sdc)
Causes the SurfaceObject to render itself to the specified region in geographic coordinates. The specified viewport denotes the geographic region and its corresponding screen viewport.

Parameters:
dc - the current draw context.
sdc - the context containing a geographic region and screen viewport corresponding to a surface tile.

drawOrderedRenderable

protected void drawOrderedRenderable(DrawContext dc)
Causes the SurfaceObject to render itself. SurfaceObjects are drawn in geographic coordinates into offscreen surface tiles. This attempts to get a SurfaceTileDrawContext from the DrawContext's AVList by querying the key AVKey.SURFACE_TILE_DRAW_CONTEXT. If the DrawContext has a SurfaceTileDrawContext attached under that key, this calls drawGeographic(DrawContext, gov.nasa.worldwind.util.SurfaceTileDrawContext) with the SurfaceTileDrawContext. Otherwise this logs a warning and returns.

Parameters:
dc - the current DrawContext.

drawPickRepresentation

protected void drawPickRepresentation(DrawContext dc)
Causes this SurfaceObject to draw a representation of itself suitable for use during picking.

Parameters:
dc - the current DrawContext.

getDelegateOwner

public Object getDelegateOwner()
Returns the delegate owner of the surface object. If non-null, the returned object replaces the surface object as the pickable object returned during picking. If null, the surface object itself is the pickable object returned during picking.

Specified by:
getDelegateOwner in interface SurfaceObject
Returns:
the object used as the pickable object returned during picking, or null to indicate the the surface object is returned during picking.

getDistanceFromEye

public double getDistanceFromEye()
Returns zero to indicate that the surface object's distance from the eye is unknown. SurfaceObjects are processed on the DrawContext's ordered surface renderable queue. Ordered surface renderables do not utilize the renderable's distance from the eye to determine draw order.

Specified by:
getDistanceFromEye in interface OrderedRenderable
Specified by:
getDistanceFromEye in interface SurfaceObject
Returns:
zero, to indicate that the object's distance from the eye is unknown.

getExtent

public Extent getExtent(DrawContext dc)
Returns the surface object's enclosing volume as an Extent in model coordinates, given a specified DrawContext.

Specified by:
getExtent in interface SurfaceObject
Parameters:
dc - the current draw context.
Returns:
the surface object's Extent in model coordinates.

getStateKey

public Object getStateKey(DrawContext dc)
Returns an object that uniquely identifies the surface object's state on the specified draw context. This object is guaranteed to be globally unique; an equality test with a state key from another always returns false.

Specified by:
getStateKey in interface SurfaceObject
Parameters:
dc - the draw context the state key relates to.
Returns:
an object representing surface object's current state.

getUniqueId

protected long getUniqueId()
Returns an integer number uniquely identifying the surface object. This number is unique relative to other instances of SurfaceObject, but is not necessarily globally unique.

Returns:
the surface object's unique identifier.

intersectsFrustum

protected boolean intersectsFrustum(DrawContext dc)
Test if this SurfaceObject intersects the specified draw context's frustum. During picking mode, this tests intersection against all of the draw context's pick frustums. During rendering mode, this tests intersection against the draw context's viewing frustum.

Parameters:
dc - the draw context the SurfaceObject is related to.
Returns:
true if this SurfaceObject intersects the draw context's frustum; false otherwise.

intersectsPickFrustum

protected boolean intersectsPickFrustum(DrawContext dc)
Test if this SurfaceObject intersects the specified draw context's pick frustums.

Parameters:
dc - the draw context the SurfaceObject is related to.
Returns:
true if this SurfaceObject intersects any of the draw context's pick frustums; false otherwise.

intersectsVisibleSector

protected boolean intersectsVisibleSector(DrawContext dc)
Test if this SurfaceObject intersects the specified draw context's visible sector. This returns false if the draw context's visible sector is null.

Parameters:
dc - draw context the SurfaceObject is related to.
Returns:
true if this SurfaceObject intersects the draw context's visible sector; false otherwise.

isDrawBoundingSectors

public boolean isDrawBoundingSectors()
Indicates whether the SurfaceObject draws its bounding sector.

Returns:
true if the shape draws its outline; false otherwise.
See Also:
setDrawBoundingSectors(boolean)

isEnableBatchPicking

public boolean isEnableBatchPicking()
Indicates whether batch picking is enabled.

Returns:
true to enable batch picking; false otherwise.
See Also:
setEnableBatchPicking(boolean)

isVisible

public boolean isVisible()
Indicates whether the surface object should be drawn during rendering.

Specified by:
isVisible in interface SurfaceObject
Returns:
true if the object is to be drawn, otherwise false.

makeOrderedPreRenderable

protected void makeOrderedPreRenderable(DrawContext dc)
Prepares the SurfaceObject as an OrderedRenderable and adds it to the DrawContext's ordered surface renderable list. Additionally, this prepares the SurfaceObject's pickable representation if the SurfaceObject's containing layer is enabled for picking and the SurfaceObject intersects one of the DrawContext's picking frustums.

During ordered preRendering, the SceneController builds a composite representation of this SurfaceObject and any other SurfaceObject on the DrawContext's ordered surface renderable list. The SceneController causes each SurfaceObject's to draw itself into the composite representation by calling its render(DrawContext) method in ordered rendering mode.

Parameters:
dc - the DrawContext to add to.

makeOrderedRenderable

protected void makeOrderedRenderable(DrawContext dc)
Prepares the SurfaceObject as an OrderedRenderable and adds it to the DrawContext's ordered surface renderable list. We ignore this call during rendering mode to suppress calls to render(DrawContext) during ordered rendering mode. The SceneController already invokes render during ordered picking mode to build a composite representation of the SurfaceObjects.

During ordered picking, the SceneController invokes the SurfaceObject's pick(DrawContext, java.awt.Point) method.

Parameters:
dc - the DrawContext to add to.

nextUniqueId

protected static long nextUniqueId()
Returns the next unique integer associated with an AbstractSurfaceObject. This method is synchronized to ensure that two threads calling simultaneously receive different values. Since this method is called from AbstractSurfaceObject's constructor, this is critical to ensure that AbstractSurfaceObject can be safely constructed on separate threads.

Returns:
the next unique integer.

pick

public void pick(DrawContext dc,
                 Point pickPoint)
Causes the surface object to draw a pickable representation of itself on the surface terrain, using the provided draw context.

Specified by:
pick in interface OrderedRenderable
Specified by:
pick in interface SurfaceObject
Parameters:
dc - the current draw context.
pickPoint - the pick point.

pickBatched

protected void pickBatched(DrawContext dc,
                           PickSupport pickSupport)
Causes adjacent SurfaceObjects in the DrawContext's ordered surface renderable list to draw themselves in in a unique pick color, and adds themselves as pickable objects to the specified pickSupport. Adjacent SurfaceObjects are removed from the DrawContext's list and processed until one is encountered that has a different containing layer or is not enabled for batch picking.

Parameters:
dc - the current DrawContext.
pickSupport - the PickSupport to add the SurfaceObject to.

pickOrderedRenderable

protected void pickOrderedRenderable(DrawContext dc,
                                     PickSupport pickSupport)
Causes the SurfaceObject to draw itself in a unique pick color, and add itself as a pickable object to the specified pickSupport.

Parameters:
dc - the current DrawContext.
pickSupport - the PickSupport to add the SurfaceObject to.

preRender

public void preRender(DrawContext dc)
Causes the surface object to prepare a representation of itself which can be drawn on the surface terrain, using the provided draw context.

Specified by:
preRender in interface PreRenderable
Specified by:
preRender in interface SurfaceObject
Parameters:
dc - the current draw context.

render

public void render(DrawContext dc)
Causes the surface object to render a representation of itself on the surface terrain, using the provided draw context.

Specified by:
render in interface Renderable
Specified by:
render in interface SurfaceObject
Parameters:
dc - the current draw context.
See Also:
DrawContext

setDelegateOwner

public void setDelegateOwner(Object owner)
Specifies the delegate owner of the surface object. If non-null, the delegate owner replaces the surface object as the pickable object returned during picking. If null, the surface object itself is the pickable object returned during picking.

Specified by:
setDelegateOwner in interface SurfaceObject
Parameters:
owner - the object to use as the pickable object returned during picking, or null to return the surface object.

setDrawBoundingSectors

public void setDrawBoundingSectors(boolean draw)
Specifies if the SurfaceObject should draw its bounding sector. If true, the SurfaceObject draws an outline of its bounding sector in green on top of its shape. The default value is false.

Parameters:
draw - true to draw the shape's outline; false otherwise.

setEnableBatchPicking

public void setEnableBatchPicking(boolean enable)
Specifies whether adjacent SurfaceObjects in the DrawContext's ordered surface renderable list may be rendered together during picking if they are contained in the same layer. This increases performance and there is seldom a reason to disable it.

Parameters:
enable - true to enable batch picking; false otherwise.

setVisible

public void setVisible(boolean visible)
Specifies whether the surface object should be drawn during rendering.

Specified by:
setVisible in interface SurfaceObject
Parameters:
visible - true if the object is to be drawn, otherwise false.

updateModifiedTime

protected void updateModifiedTime()
Sets the SurfaceObject's modified time to the current system time. This causes cached representations of this SurfaceObject to be refreshed.


NASA World Wind