Package breitband.GUI.util
Class PolygonOptimizer
- java.lang.Object
-
- breitband.GUI.util.PolygonOptimizer
-
public class PolygonOptimizer extends java.lang.Object
Class for optimizing the polygons used in the GUI. All methods are static. They take aPolygon
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:
- Skip every second point to remove jaggies (exception: neighbouring points are too far apart).
-
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 from0,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.
-
First detect edges/'high frequency' points using convolution with an edge detection kernel
- 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)
-
-
Constructor Summary
Constructors Constructor Description PolygonOptimizer()
-
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 calculatesstatic sag.elements.shapes.GPolygon
generateHQPolygon(Border polygon)
Generate a full quality GPolygon, these most likely run rather slowstatic sag.elements.shapes.GPolygon
generateSimplifiedPolygon(Border polygon, LevelOfDetail lod)
Generate a simplified GPolygon, these should make the renderer run faster.
-
-
-
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 Regionlod
- 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 foundstepSize
- 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
-
-