Class AbstractSurfaceObject
- java.lang.Object
-
- gov.nasa.worldwind.avlist.AVListImpl
-
- gov.nasa.worldwind.WWObjectImpl
-
- gov.nasa.worldwind.render.AbstractSurfaceObject
-
- All Implemented Interfaces:
AVList
,MessageListener
,OrderedRenderable
,PreRenderable
,Renderable
,SurfaceObject
,SurfaceRenderable
,WWObject
,java.beans.PropertyChangeListener
,java.util.EventListener
- Direct Known Subclasses:
AbstractSurfaceRenderable
,AbstractSurfaceShape
,AnalyticSurface.AnalyticSurfaceObject
,SurfaceText
public abstract class AbstractSurfaceObject extends WWObjectImpl implements SurfaceObject
Abstract implementation of SurfaceObject that participates in theSceneController
's bulk rendering of SurfaceObjects. The SceneControllers bulk renders all SurfaceObjects added to theDrawContext
's ordered surface renderable queue during the preRendering pass. While building the composite representation the SceneController invokesrender(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:
- 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. - Override
pickOrderedRenderable(DrawContext, PickSupport)
; draw the custom pick representation. - 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. - Override
drawOrderedRenderable(DrawContext)
; draw the custom representation. Unlike AbstractSurfaceObject subclasses should assume the modelview and projection matrices are consistent with the currentView
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description 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
Fields Modifier and Type Field Description protected java.lang.Object
delegateOwner
protected boolean
drawBoundingSectors
protected boolean
enableBatchPicking
protected java.util.Map<java.lang.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 long
uniqueId
protected boolean
visible
-
Constructor Summary
Constructors Constructor Description AbstractSurfaceObject()
Creates a new AbstractSurfaceObject, assigning it a unique ID and initializing its last modified time to the current system time.AbstractSurfaceObject(AbstractSurfaceObject source)
Creates a shallow copy of the specified source shape.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
buildPickRepresentation(DrawContext dc)
Builds this AbstractSurfaceObject's pickable representation.protected void
clearCaches()
Clears this SurfaceObject's internal extent cache.protected Extent
computeExtent(Globe globe, double verticalExaggeration, java.util.List<Sector> sectors)
Computes an extent bounding the the specified sectors on the specified Globe's surface.protected Extent
computeExtent(DrawContext dc)
Computes the surface object's extent.protected PickedObject
createPickedObject(DrawContext dc, java.awt.Color pickColor)
Create aPickedObject
for this surface object.protected SurfaceObjectTileBuilder
createPickTileBuilder()
Returns aSurfaceObjectTileBuilder
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.java.lang.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 anExtent
in model coordinates, given a specifiedDrawContext
.java.lang.Object
getStateKey(DrawContext dc)
Returns an object that uniquely identifies this renderable's state for 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 anOrderedRenderable
and adds it to the DrawContext's ordered surface renderable list.protected void
makeOrderedRenderable(DrawContext dc)
Prepares the SurfaceObject as anOrderedRenderable
and adds it to the DrawContext's ordered surface renderable list.protected static long
nextUniqueId()
Returns the next unique integer associated with an AbstractSurfaceObject.protected void
onShapeChanged()
void
pick(DrawContext dc, java.awt.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 thisRenderable
to render itself using the provided draw context.void
setDelegateOwner(java.lang.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, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
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
-
Methods inherited from interface gov.nasa.worldwind.render.SurfaceRenderable
getSectors
-
-
-
-
Field Detail
-
visible
protected boolean visible
-
uniqueId
protected final long uniqueId
-
lastModifiedTime
protected long lastModifiedTime
-
delegateOwner
protected java.lang.Object delegateOwner
-
enableBatchPicking
protected boolean enableBatchPicking
-
drawBoundingSectors
protected boolean drawBoundingSectors
-
extentCache
protected java.util.Map<java.lang.Object,AbstractSurfaceObject.CacheEntry> extentCache
-
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.
-
nextUniqueId
protected static long nextUniqueId
-
-
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.
-
AbstractSurfaceObject
public AbstractSurfaceObject(AbstractSurfaceObject source)
Creates a shallow copy of the specified source shape.- Parameters:
source
- the shape to copy.
-
-
Method Detail
-
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.
-
isVisible
public boolean isVisible()
Indicates whether the surface object should be drawn during rendering.- Specified by:
isVisible
in interfaceSurfaceObject
- Returns:
- true if the object is to be drawn, otherwise false.
-
setVisible
public void setVisible(boolean visible)
Specifies whether the surface object should be drawn during rendering.- Specified by:
setVisible
in interfaceSurfaceObject
- Parameters:
visible
- true if the object is to be drawn, otherwise false.
-
getStateKey
public java.lang.Object getStateKey(DrawContext dc)
Returns an object that uniquely identifies this renderable's state for the specified draw context.Callers can perform an equality test on two state keys using
Object.equals(Object)
in order to determine whether or not a renderable has changed. The returned object is guaranteed to be globally unique with respect to other SurfaceRenderable state keys; an equality test with a state key from another renderable always returns false.- Specified by:
getStateKey
in interfaceSurfaceRenderable
- Parameters:
dc
- the draw context for which to determine this renderable's current state.- Returns:
- an object representing this renderable's current state.
-
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 interfaceOrderedRenderable
- Specified by:
getDistanceFromEye
in interfaceSurfaceObject
- Returns:
- zero, to indicate that the object's distance from the eye is unknown.
-
getDelegateOwner
public java.lang.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 interfaceSurfaceObject
- Returns:
- the object used as the pickable object returned during picking, or null to indicate the the surface object is returned during picking.
-
setDelegateOwner
public void setDelegateOwner(java.lang.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 interfaceSurfaceObject
- Parameters:
owner
- the object to use as the pickable object returned during picking, or null to return the surface object.
-
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)
-
setDrawBoundingSectors
public void setDrawBoundingSectors(boolean draw)
Specifies if the SurfaceObject should draw its bounding sector. Iftrue
, the SurfaceObject draws an outline of its bounding sector in green on top of its shape. The default value isfalse
.- Parameters:
draw
-true
to draw the shape's outline;false
otherwise.
-
isEnableBatchPicking
public boolean isEnableBatchPicking()
Indicates whether batch picking is enabled.- Specified by:
isEnableBatchPicking
in interfaceSurfaceObject
- Returns:
true
to enable batch picking;false
otherwise.- See Also:
SurfaceObject.setEnableBatchPicking(boolean)
-
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.- Specified by:
setEnableBatchPicking
in interfaceSurfaceObject
- Parameters:
enable
-true
to enable batch picking;false
otherwise.
-
getExtent
public Extent getExtent(DrawContext dc)
Returns the surface object's enclosing volume as anExtent
in model coordinates, given a specifiedDrawContext
.- Specified by:
getExtent
in interfaceSurfaceObject
- Parameters:
dc
- the current draw context.- Returns:
- the surface object's Extent in model coordinates.
-
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 interfacePreRenderable
- Specified by:
preRender
in interfaceSurfaceObject
- Parameters:
dc
- the current draw context.
-
pick
public void pick(DrawContext dc, java.awt.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 interfaceOrderedRenderable
- Specified by:
pick
in interfaceSurfaceObject
- Parameters:
dc
- the current draw context.pickPoint
- the pick point.
-
render
public void render(DrawContext dc)
Causes thisRenderable
to render itself using the provided draw context.- Specified by:
render
in interfaceRenderable
- Parameters:
dc
- theDrawContext
to be used- See Also:
DrawContext
-
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.
-
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.
-
clearCaches
protected void clearCaches()
Clears this SurfaceObject's internal extent cache.
-
onShapeChanged
protected void onShapeChanged()
-
computeExtent
protected Extent computeExtent(DrawContext dc)
Computes the surface object's extent. Uses the sector list returned bySurfaceRenderable.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, java.util.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 callingSector.computeBoundingBox(gov.nasa.worldwind.globes.Globe, double, gov.nasa.worldwind.geom.Sector)
. If the list contains more than one sector this returns aBox
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.
-
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.
-
makeOrderedPreRenderable
protected void makeOrderedPreRenderable(DrawContext dc)
Prepares the SurfaceObject as anOrderedRenderable
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 itsrender(DrawContext)
method in ordered rendering mode.- Parameters:
dc
- the DrawContext to add to.
-
makeOrderedRenderable
protected void makeOrderedRenderable(DrawContext dc)
Prepares the SurfaceObject as anOrderedRenderable
and adds it to the DrawContext's ordered surface renderable list. We ignore this call during rendering mode to suppress calls torender(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'spick(DrawContext, java.awt.Point)
method.- Parameters:
dc
- the DrawContext to add 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.
-
createPickedObject
protected PickedObject createPickedObject(DrawContext dc, java.awt.Color pickColor)
Create aPickedObject
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.
-
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.
-
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 aSurfaceTileDrawContext
from the DrawContext's AVList by querying the keyAVKey.SURFACE_TILE_DRAW_CONTEXT
. If the DrawContext has a SurfaceTileDrawContext attached under that key, this callsdrawGeographic(DrawContext, gov.nasa.worldwind.util.SurfaceTileDrawContext)
with the SurfaceTileDrawContext. Otherwise this logs a warning and returns.- Parameters:
dc
- the current 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.
-
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.
-
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.
-
createPickTileBuilder
protected SurfaceObjectTileBuilder createPickTileBuilder()
Returns aSurfaceObjectTileBuilder
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:
SurfaceRenderable.getSectors(DrawContext)
-
-