Class PolygonOptimizer


  • public class PolygonOptimizer
    extends java.lang.Object
    Class for optimizing the polygons used in the GUI. All methods are static. They take a Polygon and return a (usually simplified) GPolygon

    Only high quality Polygons are optimized, low quality polygons (less than 20 points) get rerouted to generateHQPolygon(Border)

    Basic simplification steps:

    1. Skip every second point to remove jaggies (exception: neighbouring points are too far apart).
    2. Use frequency analysis to simplify the model. In this case frequency is the speed of change/the angle of change, in the model's outline. E.g a corner is high frequency and a straight line or slight curve is low frequency.
      • First detect edges/'high frequency' points using convolution with an edge detection kernel (-1, 2, -1), this kernel is based on edge detection kernels used in shaders. The result is low frequency points being close to [0,0] and high frequency points being far from 0,0. The distance to the origin is saved as the frequency. This low-frequency information is subsequently deleted by skipping the low-frequency points.
      • Leftover points are "blurred" with a weighted blur kernel. In this case a blur leads to the curves getting smoothed, leading to more appealing "simplified" looking shapes.
    3. As a last step, the points are iterated over and the distances are accumulated. Only when the distance is greater than a set threshold, does a point get added. This way, levels of detail can be created based on different distance threshold.
    Author:
    Juno Veenstra
    See Also:
    generateSimplifiedPolygon(Border, LevelOfDetail)
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static float[] calculateCenter​(Border polygon, float stepSize)
      Walks over every point at a constant distance, adds them together and calculates
      static sag.elements.shapes.GPolygon generateHQPolygon​(Border polygon)
      Generate a full quality GPolygon, these most likely run rather slow
      static sag.elements.shapes.GPolygon generateSimplifiedPolygon​(Border polygon, LevelOfDetail lod)
      Generate a simplified GPolygon, these should make the renderer run faster.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PolygonOptimizer

        public PolygonOptimizer()
    • Method Detail

      • generateSimplifiedPolygon

        public static sag.elements.shapes.GPolygon generateSimplifiedPolygon​(Border polygon,
                                                                             LevelOfDetail lod)
        Generate a simplified GPolygon, these should make the renderer run faster.

        The LOD sets the allowed distance between points. A higher distance means more points getting left out. When zoomed out, high levels can get used, when zooming in lower levels can get used

        Parameters:
        polygon - A PolygonWithIntersects from a Region
        lod - The degree to which the polygon gets simplified. Higher lod leads to more simplification
        Returns:
        simplified GPolygon
        See Also:
        PolygonOptimizer
      • generateHQPolygon

        public static sag.elements.shapes.GPolygon generateHQPolygon​(Border polygon)
        Generate a full quality GPolygon, these most likely run rather slow
        Parameters:
        polygon - a PolygonWithIntersects from a Region
        Returns:
        full quality GPolygon
      • calculateCenter

        public static float[] calculateCenter​(Border polygon,
                                              float stepSize)
        Walks over every point at a constant distance, adds them together and calculates
        Parameters:
        polygon - Polygon of which the center needs to be found
        stepSize - Distance between sampled points
        Returns:
        A float array of length 2, with the x coordinate at index 0 and the y coordinate at index y