Class VisibilityAlgorithm


  • public class VisibilityAlgorithm
    extends Object
    This class compute an IsoVist from a coordinate and a set of originalSegments This code is adapted from Byron Knoll byron-at-byronknoll.com javascript library: https://github.com/byronknoll/visibility-polygon-js First, sort all vertices according to their angle to the observer. Now iterate (angle sweep) through the sorted vertices. For each vertex imagine a ray projecting outwards from the observer towards that vertex compute the closest "active" line segment in order to construct the visibility polygon. The closest active line segment must be computed in O(log n) time (for each vertex). A special type of heap accomplish this: The heap keeps track of all active line segments (arranged by distance to the observer). The closest line segment is at the root of the heap. Since line segments don't intersect (a constraint in the problem definition), the heap remains consistent. This property is essential - if the distance ordering between two line segments could change depending on the angle, then a heap would no longer work. So, we can find the closest segment in O(1) time and insert new segments in O(log n) time. The reason the heap I used is "special" is because it also allows removing line segments (when they are no longer active) in O(log n) time. Inactive line segments can't just be ignored and left in the heap. they need to be removed to maintain a consistent distance ordering. In a standard heap, removing an arbitrary element takes O(n) time (since it takes linear time just to find the element). Heap contains an additional map structure from element value to heap index, so elements can be found in O(1) time. Once an element is found, we swap in the last element in the tree and propagate it either up or down (which takes O(log n) time) to maintain heap correctness.
    Author:
    Nicolas Fortin, Ifsttar UMRAE
    • Constructor Detail

      • VisibilityAlgorithm

        public VisibilityAlgorithm​(double maxDistance)
        Parameters:
        maxDistance - maximum distance constraint for visibility polygon, from view point
    • Method Detail

      • fixSegments

        public void fixSegments()
      • setNumPoints

        public void setNumPoints​(int numPoints)
        Parameters:
        numPoints - Number of points of the bounding circle polygon. Default 100
      • addSegment

        public void addSegment​(org.locationtech.jts.geom.Coordinate p0,
                               org.locationtech.jts.geom.Coordinate p1)
        Add occlusion segment in isovist
        Parameters:
        p0 - segment origin
        p1 - segment destination
      • getIsoVist

        public org.locationtech.jts.geom.Polygon getIsoVist​(org.locationtech.jts.geom.Coordinate position,
                                                            boolean addEnvelope)
        Compute isovist polygon
        Parameters:
        position - View coordinate
        addEnvelope - If true add circle bounding box. This function does not work properly if the view point is not enclosed by segments
        Returns:
        Visibility polygon
      • getEpsilon

        public double getEpsilon()
      • setEpsilon

        public void setEpsilon​(double epsilon)
      • addLineString

        public void addLineString​(org.locationtech.jts.geom.LineString lineString)
      • addGeometry

        public void addGeometry​(org.locationtech.jts.geom.Geometry geometry)
        Explode geometry and add occlusion segments in isovist
        Parameters:
        geometry - Geometry collection, LineString or Polygon instance