Class Polygon

    • Field Detail

      • edgeIndexBuffers

        protected static java.util.HashMap<java.lang.Integer,​java.nio.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.
      • 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.
      • boundaries

        protected java.util.List<java.util.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.
      • numPositions

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

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

        protected java.lang.Double rotation
        This shape's rotation, in degrees positive counterclockwise.
      • textureCoordsBuffer

        protected java.nio.FloatBuffer textureCoordsBuffer
        This shape's texture coordinates.
      • previousIntersectionTerrain

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

        protected java.lang.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.
    • Constructor Detail

      • Polygon

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

        public Polygon​(java.lang.Iterable<? extends Position> corners)
        Construct a polygon for a specified outer boundary.
        Parameters:
        corners - the list of locations defining the polygon.
        Throws:
        java.lang.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:
        java.lang.IllegalArgumentException - if the position list is null.
    • Method Detail

      • getCurrent

        protected Polygon.ShapeData getCurrent()
        Returns the current shape data cache entry.
        Returns:
        the current data cache entry.
      • 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
      • reset

        protected void reset()
        Void any computed data. Called when a factor affecting the computed data is changed.
        Overrides:
        reset in class AbstractShape
      • 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.
      • getOuterBoundary

        public java.lang.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.
      • outerBoundary

        public java.util.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.
      • isOuterBoundaryValid

        protected boolean isOuterBoundaryValid()
      • setOuterBoundary

        public void setOuterBoundary​(java.lang.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:
        java.lang.IllegalArgumentException - if the location list is null or contains fewer than three locations.
      • fillBoundary

        protected java.util.List<? extends Position> fillBoundary​(java.lang.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.
      • addInnerBoundary

        public void addInnerBoundary​(java.lang.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:
        java.lang.IllegalArgumentException - if the location list is null or contains fewer than three locations.
      • getBoundaries

        public java.util.List<java.util.List<? extends Position>> getBoundaries()
        Returns this shape's boundaries.
        Returns:
        this shape's boundaries.
      • getTextureImageSource

        public java.lang.Object getTextureImageSource()
        Returns this polygon's texture image source.
        Returns:
        the texture image source, or null if no source has been specified.
      • 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.
      • setTextureImageSource

        public void setTextureImageSource​(java.lang.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:
        java.lang.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.
      • 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 java.lang.Double getRotation()
        Indicates the amount of rotation applied to this polygon.
        Returns:
        the rotation in degrees, or null if no rotation is specified.
      • setRotation

        public void setRotation​(java.lang.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.
      • setSurfacePolygonBoundaries

        protected void setSurfacePolygonBoundaries​(SurfaceShape shape)
      • setSurfacePolygonTexImageSource

        protected void setSurfacePolygonTexImageSource​(SurfaceShape shape)
      • 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.
      • 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.
      • getSector

        public Sector getSector()
        Description copied from interface: GeographicExtent
        Returns the object's geographic extent.
        Returns:
        the object's geographic extent.
      • 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.
      • 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.
      • 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.
      • 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.
      • computeRotationMatrix

        protected Matrix computeRotationMatrix​(Globe globe)
      • 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.
      • 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.
      • computeReferencePoint

        protected Vec4 computeReferencePoint​(Terrain terrain,
                                             Matrix rotationMatrix)
      • 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.
      • 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.
      • 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.
      • 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.
      • 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.
      • computeBoundaryNormals

        protected java.nio.FloatBuffer computeBoundaryNormals​(Polygon.BoundaryInfo boundary,
                                                              java.nio.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.
      • 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.
      • generateInteriorIndices

        protected void generateInteriorIndices​(Polygon.ShapeData shapeData)
      • isSameAsPreviousTerrain

        protected boolean isSameAsPreviousTerrain​(Terrain terrain)
      • clearIntersectionGeometry

        public void clearIntersectionGeometry()
      • intersect

        public java.util.List<Intersection> intersect​(Line line,
                                                      Terrain terrain)
                                               throws java.lang.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:
        java.lang.InterruptedException - if the operation is interrupted.
        See Also:
        Terrain
      • intersect

        protected void intersect​(Line line,
                                 Polygon.ShapeData shapeData,
                                 java.util.List<Intersection> intersections)
                          throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • 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.
        Throws:
        java.lang.IllegalArgumentException - if the position is null.
      • moveTo

        public void moveTo​(Globe globe,
                           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.

        Specified by:
        moveTo in interface Movable2
        Overrides:
        moveTo in class AbstractShape
        Parameters:
        globe - the globe on which to move this shape.
        position - the new position of the shape's reference position.
        Throws:
        java.lang.IllegalArgumentException - if the globe or position is null.
      • doExportAsKML

        protected void doExportAsKML​(javax.xml.stream.XMLStreamWriter xmlWriter)
                              throws java.io.IOException,
                                     javax.xml.stream.XMLStreamException
        Exports shape-specific fields.
        Specified by:
        doExportAsKML in class AbstractShape
        Parameters:
        xmlWriter - the export writer to write to.
        Throws:
        java.io.IOException - if an IO error occurs while writing to the output destination.
        javax.xml.stream.XMLStreamException - if an exception occurs converting this shape's fields to XML.
      • writeKMLBoundaries

        protected void writeKMLBoundaries​(javax.xml.stream.XMLStreamWriter xmlWriter)
                                   throws java.io.IOException,
                                          javax.xml.stream.XMLStreamException
        Write the boundary of the polygon as KML.
        Parameters:
        xmlWriter - XML writer to receive the output.
        Throws:
        java.io.IOException - If an exception occurs writing the XML stream.
        javax.xml.stream.XMLStreamException - If an exception occurs writing the XML stream.
      • exportBoundaryAsLinearRing

        protected void exportBoundaryAsLinearRing​(javax.xml.stream.XMLStreamWriter xmlWriter,
                                                  java.lang.Iterable<? extends LatLon> boundary)
                                           throws javax.xml.stream.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:
        javax.xml.stream.XMLStreamException - if an error occurs during writing.