NASA World Wind

gov.nasa.worldwind.render
Class Polygon

java.lang.Object
  extended by gov.nasa.worldwind.avlist.AVListImpl
      extended by gov.nasa.worldwind.WWObjectImpl
          extended by gov.nasa.worldwind.render.AbstractShape
              extended by gov.nasa.worldwind.render.Polygon
All Implemented Interfaces:
AVList, MessageListener, Exportable, ExtentHolder, Movable, GeographicExtent, Highlightable, OrderedRenderable, Renderable, Restorable, WWObject, PropertyChangeListener, EventListener
Direct Known Subclasses:
KMLGroundOverlayPolygonImpl, KMLPolygonImpl

public class Polygon
extends AbstractShape

/** A 3D polygon. The polygon may be complex with multiple internal but not intersecting contours.

Polygons are safe to share among World Windows. They should not be shared among layers in the same World Window.

In order to support simultaneous use of this shape with multiple globes (windows), this shape maintains a cache of data computed relative to each globe. During rendering, the data for the currently active globe, as indicated in the draw context, is made current. Subsequently called methods rely on the existence of this current data cache entry.


Nested Class Summary
protected static class Polygon.BoundaryInfo
          Holds information for each contour of the polygon.
protected static class Polygon.ShapeData
          This class holds globe-specific data for this shape.
 
Nested classes/interfaces inherited from class gov.nasa.worldwind.render.AbstractShape
AbstractShape.AbstractShapeData
 
Field Summary
protected  List<List<? extends Position>> boundaries
          The location of each vertex in this shape's boundaries.
protected static HashMap<Integer,IntBuffer> edgeIndexBuffers
          This static hash map holds the vertex indices that define the shape's visual outline.
protected  Object imageSource
          The image source for this shape's texture, if any.
protected  int numPositions
          The total number of positions in the entire polygon.
protected  Object previousIntersectionGlobeStateKey
          The globe state key for the globe used in the most recent intersection calculation.
protected  Polygon.ShapeData previousIntersectionShapeData
          The shape data used for the previous intersection calculation.
protected  Terrain previousIntersectionTerrain
          The terrain used in the most recent intersection calculations.
protected  Double rotation
          This shape's rotation, in degrees positive counterclockwise.
protected  WWTexture texture
          If an image source was specified, this is the WWTexture form.
protected  FloatBuffer textureCoordsBuffer
          This shape's texture coordinates.
protected static int VBO_THRESHOLD
          Indicates the number of vertices that must be present in order for VBOs to be used to render this shape.
 
Fields inherited from class gov.nasa.worldwind.render.AbstractShape
activeAttributes, altitudeMode, BEogsh, currentData, DEFAULT_ALTITUDE_MODE, DEFAULT_GEOMETRY_GENERATION_INTERVAL, DEFAULT_HIGHLIGHT_MATERIAL, DEFAULT_INTERIOR_MATERIAL, DEFAULT_OUTLINE_MATERIAL, DEFAULT_OUTLINE_PICK_WIDTH, defaultAttributes, delegateOwner, enableBatchPicking, enableBatchRendering, enableDepthOffset, highlightAttrs, highlighted, maxExpiryTime, minExpiryTime, normalAttrs, outlinePickWidth, outlineShapeRenderer, pickLayer, pickSupport, referencePosition, sector, shapeDataCache, viewDistanceExpiration, visible
 
Fields inherited from interface gov.nasa.worldwind.Exportable
FORMAT_NOT_SUPPORTED, FORMAT_PARTIALLY_SUPPORTED, FORMAT_SUPPORTED
 
Constructor Summary
Polygon()
          Construct a polygon with an empty outer boundary.
Polygon(Iterable<? extends Position> corners)
          Construct a polygon for a specified outer boundary.
Polygon(Position.PositionList corners)
          Construct a polygon for a specified list of outer-boundary positions.
 
Method Summary
 void addInnerBoundary(Iterable<? extends Position> corners)
          Add an inner boundary to this polygon.
protected  OGLStackHandler beginDrawing(DrawContext dc, int attrMask)
          Establish the OpenGL state needed to draw this shape.
 void clearIntersectionGeometry()
           
protected  FloatBuffer computeBoundaryNormals(Polygon.BoundaryInfo boundary, FloatBuffer nBuf)
          Compute normal vectors for a boundary's vertices.
protected  void computeBoundaryVertices(Terrain terrain, Polygon.BoundaryInfo boundary, Vec4 refPoint, Matrix rotationMatrix)
          Compute the vertices associated with a specified boundary.
protected  Extent computeExtent(Polygon.BoundaryInfo boundary, Vec4 refPoint)
          Computes the Cartesian extent of a polygon boundary.
protected  double computeEyeDistance(DrawContext dc, Polygon.ShapeData shapeData)
          Computes the minimum distance between this polygon and the eye point.
protected  Vec4 computePolygonNormal(DrawContext dc, Polygon.ShapeData shapeData)
           
protected  Vec4 computeReferencePoint(Terrain terrain, Matrix rotationMatrix)
           
protected  Matrix computeRotationMatrix(Globe globe)
           
protected  int countPositions()
          Counts the total number of positions in this shape, including all positions in all boundaries.
protected  AbstractShape.AbstractShapeData createCacheEntry(DrawContext dc)
          Creates and returns a new cache entry specific to the subclass.
protected  void createFullGeometry(DrawContext dc, Terrain terrain, Polygon.ShapeData shapeData, boolean skipOuterBoundary)
          Computes a shape's full geometry.
protected  void createGeometry(DrawContext dc, Polygon.ShapeData shapeData)
          Compute the cap geometry.
protected  Polygon.ShapeData createIntersectionGeometry(Terrain terrain)
           
protected  void createMinimalGeometry(DrawContext dc, Polygon.ShapeData shapeData)
          Compute enough geometry to determine this polygon's extent, reference point and eye distance.
protected  void createNormals(Polygon.ShapeData shapeData)
          Create this shape's vertex normals.
protected  void createTessllationGeometry(DrawContext dc, Polygon.ShapeData shapeData)
          Tessellates the polygon.
protected  void createVertices(Terrain terrain, Polygon.ShapeData shapeData, boolean skipOuterBoundary)
          Computes the Cartesian vertices for this shape.
protected  void doDrawInterior(DrawContext dc)
          Draws this shape's interior.
protected  void doDrawInteriorVA(DrawContext dc, Polygon.ShapeData shapeData)
           
protected  void doDrawInteriorVBO(DrawContext dc, int[] vboIds, Polygon.ShapeData shapeData)
           
protected  void doDrawOutline(DrawContext dc)
          Draws this shape's outline.
protected  void doDrawOutlineVA(DrawContext dc, Polygon.ShapeData shapeData)
           
protected  void doDrawOutlineVBO(DrawContext dc, int[] vboIds, Polygon.ShapeData shapeData)
           
protected  void doExportAsKML(XMLStreamWriter xmlWriter)
          Exports shape-specific fields.
protected  boolean doMakeOrderedRenderable(DrawContext dc)
          Produces the geometry and other state necessary to represent this shape as an ordered renderable.
protected  void exportBoundaryAsLinearRing(XMLStreamWriter xmlWriter, Iterable<? extends LatLon> boundary)
          Writes the boundary in KML as either a list of lat, lon, altitude tuples or lat, lon tuples, depending on the type originally specified.
protected  List<? extends Position> fillBoundary(Iterable<? extends Position> corners)
          Copies a boundary's positions to this shape's internal boundary list.
protected  void fillVBO(DrawContext dc)
          Fill this shape's vertex buffer objects.
protected  void generateInteriorIndices(Polygon.ShapeData shapeData)
           
 List<List<? extends Position>> getBoundaries()
          Returns this shape's boundaries.
protected  Polygon.ShapeData getCurrent()
          Returns the current shape data cache entry.
 Extent getExtent(Globe globe, double verticalExaggeration)
          Returns the objects enclosing volume as an Extent in model coordinates, given a specified Globe and vertical exaggeration (see SceneController.getVerticalExaggeration().
 Iterable<? extends LatLon> getOuterBoundary()
          Returns the list of positions defining this polygon's outer boundary.
 Position getReferencePosition()
          A position associated with the object that indicates its aggregate geographic position.
 Double getRotation()
          Indicates the amount of rotation applied to this polygon.
 Sector getSector()
          Returns the object's geographic extent.
protected  WWTexture getTexture()
          Get the texture applied to this polygon.
 float[] getTextureCoords()
          Returns the texture coordinates for this polygon.
 Object getTextureImageSource()
          Returns this polygon's texture image source.
protected  void initialize()
          Called during construction to establish any subclass-specific state such as different default values than those set by this class.
protected  void intersect(Line line, Polygon.ShapeData shapeData, List<Intersection> intersections)
           
 List<Intersection> intersect(Line line, Terrain terrain)
          Compute the intersections of a specified line with this polygon.
protected  boolean isOrderedRenderableValid(DrawContext dc)
          Determines whether this shape's ordered renderable state is valid and can be rendered.
protected  boolean isOuterBoundaryValid()
           
protected  boolean isSameAsPreviousTerrain(Terrain terrain)
           
 void moveTo(Position position)
          Move the shape over the globe's surface while maintaining its original azimuth, its orientation relative to North.
protected  boolean mustApplyTexture(DrawContext dc)
          Indicates whether texture should be applied to this shape.
protected  boolean mustRegenerateGeometry(DrawContext dc)
          Indicates whether this shape's renderable geometry must be recomputed, either as a result of an attribute or property change or the expiration of the geometry regeneration interval.
protected  List<? extends Position> outerBoundary()
          Returns a reference to the outer boundary of this polygon.
 void render(DrawContext dc)
          Causes this Renderable to render itself using the provided draw context.
protected  void reset()
          Void any computed data.
 void setOuterBoundary(Iterable<? extends Position> corners)
          Specifies the latitude, longitude and altitude of the outer boundary positions defining this polygon.
 void setRotation(Double rotation)
          Specifies the amount of rotation applied to this polygon.
 void setTextureImageSource(Object imageSource, float[] texCoords, int texCoordCount)
          Specifies the texture to apply to this polygon.
protected  boolean shouldUseVBOs(DrawContext dc)
          Indicates whether this shape should use OpenGL vertex buffer objects.
protected  void tessellatePolygon(Polygon.ShapeData shapeData, Vec4 normal)
          Tessellates the polygon from its vertices.
protected  void writeKMLBoundaries(XMLStreamWriter xmlWriter)
          Write the boundary of the polygon as KML.
 
Methods inherited from class gov.nasa.worldwind.render.AbstractShape
addOrderedRenderable, checkViewDistanceExpiration, clearCachedVbos, computeExtentFromPositions, computePoint, countTriangleVertices, createPickedObject, determineActiveAttributes, doDrawOrderedRenderable, doGetRestorableState, doRestoreState, drawBatched, drawInterior, drawOrderedRenderable, drawOutline, endDrawing, export, exportAsKML, getActiveAttributes, getAltitudeMode, getAttributes, getCurrentData, getDelegateOwner, getDistanceFromEye, getExtent, getGeometryRegenerationInterval, getHighlightAttributes, getOutlinePickWidth, getReferencePoint, getRestorableState, getVboIds, intersectsFrustum, isEnableBatchPicking, isEnableBatchRendering, isEnableDepthOffset, isExportFormatSupported, isHighlighted, isTerrainDependent, isViewDistanceExpiration, isVisible, makeOrderedRenderable, makeTexture, move, mustApplyLighting, mustApplyLighting, mustCreateNormals, mustCreateNormals, mustDrawInterior, mustDrawOutline, pick, prepareToDrawInterior, prepareToDrawOutline, restoreState, setAltitudeMode, setAttributes, setDelegateOwner, setEnableBatchPicking, setEnableBatchRendering, setEnableDepthOffset, setGeometryRegenerationInterval, setHighlightAttributes, setHighlighted, setOutlinePickWidth, setReferencePosition, setViewDistanceExpiration, setVisible
 
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.avlist.AVList
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getEntries, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
 

Field Detail

boundaries

protected List<List<? extends Position>> boundaries
The location of each vertex in this shape's boundaries. There is one list per boundary. There is always an entry for the outer boundary, but its list is empty if an outer boundary has not been specified.


edgeIndexBuffers

protected static HashMap<Integer,IntBuffer> edgeIndexBuffers
This static hash map holds the vertex indices that define the shape's visual outline. The contents depend only on the number of locations in the source polygon, so they can be reused by all shapes with the same location count.


imageSource

protected Object imageSource
The image source for this shape's texture, if any.


numPositions

protected int numPositions
The total number of positions in the entire polygon.


previousIntersectionGlobeStateKey

protected Object previousIntersectionGlobeStateKey
The globe state key for the globe used in the most recent intersection calculation.


previousIntersectionShapeData

protected Polygon.ShapeData previousIntersectionShapeData
The shape data used for the previous intersection calculation.


previousIntersectionTerrain

protected Terrain previousIntersectionTerrain
The terrain used in the most recent intersection calculations.


rotation

protected Double rotation
This shape's rotation, in degrees positive counterclockwise.


texture

protected WWTexture texture
If an image source was specified, this is the WWTexture form.


textureCoordsBuffer

protected FloatBuffer textureCoordsBuffer
This shape's texture coordinates.


VBO_THRESHOLD

protected static final int VBO_THRESHOLD
Indicates the number of vertices that must be present in order for VBOs to be used to render this shape.

Constructor Detail

Polygon

public Polygon()
Construct a polygon with an empty outer boundary.


Polygon

public Polygon(Iterable<? extends Position> corners)
Construct a polygon for a specified outer boundary.

Parameters:
corners - the list of locations defining the polygon.
Throws:
IllegalArgumentException - if the location list is null.

Polygon

public Polygon(Position.PositionList corners)
Construct a polygon for a specified list of outer-boundary positions.

Parameters:
corners - the list of positions -- latitude longitude and altitude -- defining the polygon. The current altitude mode determines whether the positions are considered relative to mean sea level (they are "absolute") or the ground elevation at the associated latitude and longitude.
Throws:
IllegalArgumentException - if the position list is null.
Method Detail

addInnerBoundary

public void addInnerBoundary(Iterable<? extends Position> corners)
Add an inner boundary to this polygon. A duplicate of the first position is appended to the list if the list's last position is not identical to the first.

Parameters:
corners - the new boundary positions. A copy of the list is created and retained, and a duplicate of the first position is added to the list if the first and last positions are not identical.
Throws:
IllegalArgumentException - if the location list is null or contains fewer than three locations.

beginDrawing

protected OGLStackHandler beginDrawing(DrawContext dc,
                                       int attrMask)
Description copied from class: AbstractShape
Establish the OpenGL state needed to draw this shape.

A AbstractShape.AbstractShapeData must be current when this method is called.

Overrides:
beginDrawing in class AbstractShape
Parameters:
dc - the current draw context.
attrMask - an attribute mask indicating state the caller will set. This base class implementation sets GL_CURRENT_BIT, GL_LINE_BIT, GL_HINT_BIT, GL_POLYGON_BIT, GL_COLOR_BUFFER_BIT, and GL_TRANSFORM_BIT.
Returns:
the stack handler used to set the OpenGL state. Callers should use this to set additional state, especially state indicated in the attribute mask argument.

clearIntersectionGeometry

public void clearIntersectionGeometry()

computeBoundaryNormals

protected FloatBuffer computeBoundaryNormals(Polygon.BoundaryInfo boundary,
                                             FloatBuffer nBuf)
Compute normal vectors for a boundary's vertices.

Parameters:
boundary - the boundary to compute normals for.
nBuf - the buffer in which to place the computed normals. Must have enough remaining space to hold the normals.
Returns:
the buffer specified as input, with its limit incremented by the number of vertices copied, and its position set to 0.

computeBoundaryVertices

protected void computeBoundaryVertices(Terrain terrain,
                                       Polygon.BoundaryInfo boundary,
                                       Vec4 refPoint,
                                       Matrix rotationMatrix)
Compute the vertices associated with a specified boundary.

Parameters:
terrain - the terrain to use when calculating vertices relative to the ground.
boundary - the boundary to compute vertices for.
refPoint - the reference point. Vertices are computed relative to this point, which is usually the shape's reference point.
rotationMatrix - the rotation matrix to apply to the vertices.

computeExtent

protected Extent computeExtent(Polygon.BoundaryInfo boundary,
                               Vec4 refPoint)
Computes the Cartesian extent of a polygon boundary.

Parameters:
boundary - The boundary to compute the extent for.
refPoint - the shape's reference point.
Returns:
the boundary's extent. Returns null if the boundary's vertices have not been computed.

computeEyeDistance

protected double computeEyeDistance(DrawContext dc,
                                    Polygon.ShapeData shapeData)
Computes the minimum distance between this polygon and the eye point.

A AbstractShape.AbstractShapeData must be current when this method is called.

Parameters:
dc - the draw context.
shapeData - the current shape data for this shape.
Returns:
the minimum distance from the shape to the eye point.

computePolygonNormal

protected Vec4 computePolygonNormal(DrawContext dc,
                                    Polygon.ShapeData shapeData)

computeReferencePoint

protected Vec4 computeReferencePoint(Terrain terrain,
                                     Matrix rotationMatrix)

computeRotationMatrix

protected Matrix computeRotationMatrix(Globe globe)

countPositions

protected int countPositions()
Counts the total number of positions in this shape, including all positions in all boundaries.

Returns:
the number of positions in this shape.

createCacheEntry

protected AbstractShape.AbstractShapeData createCacheEntry(DrawContext dc)
Description copied from class: AbstractShape
Creates and returns a new cache entry specific to the subclass.

Specified by:
createCacheEntry in class AbstractShape
Parameters:
dc - the current draw context.
Returns:
a data cache entry for the state in the specified draw context.

createFullGeometry

protected void createFullGeometry(DrawContext dc,
                                  Terrain terrain,
                                  Polygon.ShapeData shapeData,
                                  boolean skipOuterBoundary)
Computes a shape's full geometry.

Parameters:
dc - the current draw context.
terrain - the terrain to use when computing the geometry.
shapeData - the current shape data for this shape.
skipOuterBoundary - true if outer boundaries vertices do not need to be calculated, otherwise false.

createGeometry

protected void createGeometry(DrawContext dc,
                              Polygon.ShapeData shapeData)
Compute the cap geometry.

A AbstractShape.AbstractShapeData must be current when this method is called.

Parameters:
dc - the current draw context.
shapeData - boundary vertices are calculated during createMinimalGeometry(DrawContext, gov.nasa.worldwind.render.Polygon.ShapeData)).

createIntersectionGeometry

protected Polygon.ShapeData createIntersectionGeometry(Terrain terrain)

createMinimalGeometry

protected void createMinimalGeometry(DrawContext dc,
                                     Polygon.ShapeData shapeData)
Compute enough geometry to determine this polygon's extent, reference point and eye distance.

A AbstractShape.AbstractShapeData must be current when this method is called.

Parameters:
dc - the current draw context.
shapeData - the current shape data for this shape.

createNormals

protected void createNormals(Polygon.ShapeData shapeData)
Create this shape's vertex normals.

Parameters:
shapeData - the current shape data holding the vertex coordinates and in which the normal vectors are added. The normal vectors are appended to the vertex coordinates in the same buffer. The shape data's coordinate buffer must have sufficient capacity to hold the vertex normals.

createTessllationGeometry

protected void createTessllationGeometry(DrawContext dc,
                                         Polygon.ShapeData shapeData)
Tessellates the polygon.

This method catches OutOfMemoryError exceptions and if the draw context is not null passes the exception to the rendering exception listener (see WorldWindow.addRenderingExceptionListener(gov.nasa.worldwind.event.RenderingExceptionListener)).

Parameters:
dc - the draw context.
shapeData - the current shape data for this shape.

createVertices

protected void createVertices(Terrain terrain,
                              Polygon.ShapeData shapeData,
                              boolean skipOuterBoundary)
Computes the Cartesian vertices for this shape.

Parameters:
terrain - the terrain to use if the altitude mode is relative to the terrain.
shapeData - the current shape data for this shape.
skipOuterBoundary - if true, don't calculate the vertices for the outer boundary. This is used when the outer boundary vertices were computed as minimal geometry.

doDrawInterior

protected void doDrawInterior(DrawContext dc)
Description copied from class: AbstractShape
Draws this shape's interior. Called immediately after calling AbstractShape.prepareToDrawInterior(DrawContext, ShapeAttributes, ShapeAttributes), which establishes OpenGL state for lighting, blending, pick color and interior attributes. Subclasses should execute the drawing commands specific to the type of shape.

A AbstractShape.AbstractShapeData must be current when this method is called.

Specified by:
doDrawInterior in class AbstractShape
Parameters:
dc - the current draw context.

doDrawInteriorVA

protected void doDrawInteriorVA(DrawContext dc,
                                Polygon.ShapeData shapeData)

doDrawInteriorVBO

protected void doDrawInteriorVBO(DrawContext dc,
                                 int[] vboIds,
                                 Polygon.ShapeData shapeData)

doDrawOutline

protected void doDrawOutline(DrawContext dc)
Description copied from class: AbstractShape
Draws this shape's outline. Called immediately after calling AbstractShape.prepareToDrawOutline(DrawContext, ShapeAttributes, ShapeAttributes), which establishes OpenGL state for lighting, blending, pick color and line attributes. Subclasses should execute the drawing commands specific to the type of shape.

A AbstractShape.AbstractShapeData must be current when this method is called.

Specified by:
doDrawOutline in class AbstractShape
Parameters:
dc - the current draw context.

doDrawOutlineVA

protected void doDrawOutlineVA(DrawContext dc,
                               Polygon.ShapeData shapeData)

doDrawOutlineVBO

protected void doDrawOutlineVBO(DrawContext dc,
                                int[] vboIds,
                                Polygon.ShapeData shapeData)

doExportAsKML

protected void doExportAsKML(XMLStreamWriter xmlWriter)
                      throws IOException,
                             XMLStreamException
Exports shape-specific fields.

Specified by:
doExportAsKML in class AbstractShape
Parameters:
xmlWriter - the export writer to write to.
Throws:
IOException - if an IO error occurs while writing to the output destination.
XMLStreamException - if an exception occurs converting this shape's fields to XML.

doMakeOrderedRenderable

protected boolean doMakeOrderedRenderable(DrawContext dc)
Description copied from class: AbstractShape
Produces the geometry and other state necessary to represent this shape as an ordered renderable. Places this shape on the draw context's ordered renderable list for subsequent rendering. This method is called during AbstractShape.pick(DrawContext, java.awt.Point) and AbstractShape.render(DrawContext) when it's been determined that the shape is likely to be visible.

Specified by:
doMakeOrderedRenderable in class AbstractShape
Parameters:
dc - the current draw context.
Returns:
true if the ordered renderable state was successfully computed, otherwise false, in which case the current pick or render pass is terminated for this shape. Subclasses should return false if it is not possible to create the ordered renderable state.
See Also:
AbstractShape.pick(DrawContext, java.awt.Point), AbstractShape.render(DrawContext)

exportBoundaryAsLinearRing

protected void exportBoundaryAsLinearRing(XMLStreamWriter xmlWriter,
                                          Iterable<? extends LatLon> boundary)
                                   throws XMLStreamException
Writes the boundary in KML as either a list of lat, lon, altitude tuples or lat, lon tuples, depending on the type originally specified.

Parameters:
xmlWriter - the XML writer.
boundary - the boundary to write.
Throws:
XMLStreamException - if an error occurs during writing.

fillBoundary

protected List<? extends Position> fillBoundary(Iterable<? extends Position> corners)
Copies a boundary's positions to this shape's internal boundary list. Closes the boundary if it's not already closed.

Parameters:
corners - the boundary's positions.
Returns:
a list of the boundary positions.

fillVBO

protected void fillVBO(DrawContext dc)
Fill this shape's vertex buffer objects. If the vertex buffer object resource IDs don't yet exist, create them.

Specified by:
fillVBO in class AbstractShape
Parameters:
dc - the current draw context.

generateInteriorIndices

protected void generateInteriorIndices(Polygon.ShapeData shapeData)

getBoundaries

public List<List<? extends Position>> getBoundaries()
Returns this shape's boundaries.

Returns:
this shape's boundaries.

getCurrent

protected Polygon.ShapeData getCurrent()
Returns the current shape data cache entry.

Returns:
the current data cache entry.

getExtent

public Extent getExtent(Globe globe,
                        double verticalExaggeration)
Description copied from interface: ExtentHolder
Returns the objects enclosing volume as an Extent in model coordinates, given a specified Globe and vertical exaggeration (see SceneController.getVerticalExaggeration().

Specified by:
getExtent in interface ExtentHolder
Overrides:
getExtent in class AbstractShape
Parameters:
globe - the Globe the object is related to.
verticalExaggeration - the vertical exaggeration of the scene containing this object.
Returns:
the object's Extent in model coordinates.

getOuterBoundary

public Iterable<? extends LatLon> getOuterBoundary()
Returns the list of positions defining this polygon's outer boundary.

Returns:
this polygon's outer boundary positions. The list may be empty but will not be null.

getReferencePosition

public Position getReferencePosition()
Description copied from interface: Movable
A position associated with the object that indicates its aggregate geographic position. The chosen position varies among implementers of this interface. For objects defined by a list of positions, the reference position is typically the first position in the list. For symmetric objects the reference position is often the center of the object. In many cases the object's reference position may be explicitly specified by the application.

Returns:
the object's reference position, or null if no reference position is available.

getRotation

public Double getRotation()
Indicates the amount of rotation applied to this polygon.

Returns:
the rotation in degrees, or null if no rotation is specified.

getSector

public Sector getSector()
Description copied from interface: GeographicExtent
Returns the object's geographic extent.

Returns:
the object's geographic extent.

getTexture

protected WWTexture getTexture()
Get the texture applied to this polygon. The texture is loaded on a background thread. This method will return null until the texture has been loaded.

Returns:
the texture, or null if there is no texture or the texture is not yet available.

getTextureCoords

public float[] getTextureCoords()
Returns the texture coordinates for this polygon.

Returns:
the texture coordinates, or null if no texture coordinates have been specified.

getTextureImageSource

public Object getTextureImageSource()
Returns this polygon's texture image source.

Returns:
the texture image source, or null if no source has been specified.

initialize

protected void initialize()
Description copied from class: AbstractShape
Called during construction to establish any subclass-specific state such as different default values than those set by this class.

Specified by:
initialize in class AbstractShape

intersect

protected void intersect(Line line,
                         Polygon.ShapeData shapeData,
                         List<Intersection> intersections)
                  throws InterruptedException
Throws:
InterruptedException

intersect

public List<Intersection> intersect(Line line,
                                    Terrain terrain)
                             throws InterruptedException
Compute the intersections of a specified line with this polygon. If the polygon's altitude mode is other than WorldWind.ABSOLUTE, the polygon's geometry is created relative to the specified terrain rather than the terrain used during rendering, which may be at lower level of detail than required for accurate intersection determination.

Specified by:
intersect in class AbstractShape
Parameters:
line - the line to intersect.
terrain - the Terrain to use when computing the polygon's geometry.
Returns:
a list of intersections identifying where the line intersects the polygon, or null if the line does not intersect the polygon.
Throws:
InterruptedException - if the operation is interrupted.
See Also:
Terrain

isOrderedRenderableValid

protected boolean isOrderedRenderableValid(DrawContext dc)
Description copied from class: AbstractShape
Determines whether this shape's ordered renderable state is valid and can be rendered. Called by AbstractShape.makeOrderedRenderable(DrawContext)just prior to adding the shape to the ordered renderable list.

Specified by:
isOrderedRenderableValid in class AbstractShape
Parameters:
dc - the current draw context.
Returns:
true if this shape is ready to be rendered as an ordered renderable.

isOuterBoundaryValid

protected boolean isOuterBoundaryValid()

isSameAsPreviousTerrain

protected boolean isSameAsPreviousTerrain(Terrain terrain)

moveTo

public void moveTo(Position position)
Move the shape over the globe's surface while maintaining its original azimuth, its orientation relative to North.

Note that this method overwrites the boundary locations lists, and therefore no longer refer to the originally specified boundary lists.

Parameters:
position - the new position of the shape's reference position.

mustApplyTexture

protected boolean mustApplyTexture(DrawContext dc)
Description copied from class: AbstractShape
Indicates whether texture should be applied to this shape. Called during rendering to determine whether texture state should be established during preparation for interior drawing.

Note: This method always returns false during the pick pass.

Specified by:
mustApplyTexture in class AbstractShape
Parameters:
dc - the current draw context
Returns:
true if texture should be applied, otherwise false.

mustRegenerateGeometry

protected boolean mustRegenerateGeometry(DrawContext dc)
Description copied from class: AbstractShape
Indicates whether this shape's renderable geometry must be recomputed, either as a result of an attribute or property change or the expiration of the geometry regeneration interval.

A AbstractShape.AbstractShapeData must be current when this method is called.

Overrides:
mustRegenerateGeometry in class AbstractShape
Parameters:
dc - the current draw context.
Returns:
true if this shape's geometry must be regenerated, otherwise false.

outerBoundary

protected List<? extends Position> outerBoundary()
Returns a reference to the outer boundary of this polygon.

Returns:
this polygon's outer boundary. The list may be empty but will not be null.

render

public void render(DrawContext dc)
Description copied from interface: Renderable
Causes this Renderable to render itself using the provided draw context.

Specified by:
render in interface Renderable
Overrides:
render in class AbstractShape
Parameters:
dc - the DrawContext to be used
See Also:
DrawContext

reset

protected void reset()
Void any computed data. Called when a factor affecting the computed data is changed.

Overrides:
reset in class AbstractShape

setOuterBoundary

public void setOuterBoundary(Iterable<? extends Position> corners)
Specifies the latitude, longitude and altitude of the outer boundary positions defining this polygon.

Parameters:
corners - this polygon's positions. A copy of the list is made and retained, and a duplicate of the first position is appended to the copy if the first and last positions are not identical.
Throws:
IllegalArgumentException - if the location list is null or contains fewer than three locations.

setRotation

public void setRotation(Double rotation)
Specifies the amount of rotation applied to this polygon. Positive rotation is counter-clockwise.

Parameters:
rotation - the amount of rotation to apply, in degrees, or null to apply no rotation.

setTextureImageSource

public void setTextureImageSource(Object imageSource,
                                  float[] texCoords,
                                  int texCoordCount)
Specifies the texture to apply to this polygon.

Parameters:
imageSource - the texture image source. May be a String identifying a file path or URL, a File, or a URL.
texCoords - the (s, t) texture coordinates aligning the image to the polygon. There must be one texture coordinate pair, (s, t), for each polygon location in the polygon's outer boundary.
texCoordCount - the number of texture coordinates, (s, v) pairs, specified.
Throws:
IllegalArgumentException - if the image source is not null and either the texture coordinates are null or inconsistent with the specified texture-coordinate count, or there are fewer than three texture coordinate pairs.

shouldUseVBOs

protected boolean shouldUseVBOs(DrawContext dc)
Description copied from class: AbstractShape
Indicates whether this shape should use OpenGL vertex buffer objects.

Overrides:
shouldUseVBOs in class AbstractShape
Parameters:
dc - the current draw context.
Returns:
true if this shape should use vertex buffer objects, otherwise false.

tessellatePolygon

protected void tessellatePolygon(Polygon.ShapeData shapeData,
                                 Vec4 normal)
Tessellates the polygon from its vertices.

Parameters:
shapeData - the polygon boundaries.
normal - a unit normal vector for the plane containing the polygon vertices. Even though the the vertices might not be coplanar, only one representative normal is used for tessellation.

writeKMLBoundaries

protected void writeKMLBoundaries(XMLStreamWriter xmlWriter)
                           throws IOException,
                                  XMLStreamException
Write the boundary of the polygon as KML.

Parameters:
xmlWriter - XML writer to receive the output.
Throws:
IOException - If an exception occurs writing the XML stream.
XMLStreamException - If an exception occurs writing the XML stream.

NASA World Wind