de.fhpotsdam.unfolding.utils
Class GeneralizationUtils

java.lang.Object
  extended by de.fhpotsdam.unfolding.utils.GeneralizationUtils

public class GeneralizationUtils
extends java.lang.Object

Provides utility functions to simplify points, paths, and polygons.


Constructor Summary
GeneralizationUtils()
           
 
Method Summary
protected static float[] computeMovingAverage(float[] values, int np)
          Calculates the np-point moving average for some values.
static java.util.List<processing.core.PVector> computeMovingAverage(java.util.List<processing.core.PVector> vertices, int np)
          Calculates the moving average of vertices.
protected static float getSquareDistance(processing.core.PVector p1, processing.core.PVector p2)
          Square distance between 2 points.
protected static float getSquareSegmentDistance(processing.core.PVector p, processing.core.PVector p1, processing.core.PVector p2)
          Square distance from a point to a segment.
static java.util.List<processing.core.PVector> simplify(java.util.List<processing.core.PVector> points, float tolerance, boolean highestQuality)
          Simplifies points by using Douglas-Peucker algorithm.
protected static java.util.List<processing.core.PVector> simplifyDouglasPeucker(java.util.List<processing.core.PVector> points, float sqTolerance)
          Simplification using optimized Douglas-Peucker algorithm with recursion elimination.
protected static java.util.List<processing.core.PVector> simplifyRadialDistance(java.util.List<processing.core.PVector> points, float sqTolerance)
          Distance-based simplification.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GeneralizationUtils

public GeneralizationUtils()
Method Detail

computeMovingAverage

public static java.util.List<processing.core.PVector> computeMovingAverage(java.util.List<processing.core.PVector> vertices,
                                                                           int np)
Calculates the moving average of vertices. Can be used to smoothen paths when the vertices are geo-locations.

Opposite to simplify(List, float, boolean) this keeps the same amount of vertices, so does not improve performance, but creates smoother paths. You might want to combine both methods.

Parameters:
vertices - The vertices to smoothen.
np - The number of points to average over.
Returns:
The smoothened vertices.

computeMovingAverage

protected static float[] computeMovingAverage(float[] values,
                                              int np)
Calculates the np-point moving average for some values.

Parameters:
np - number of points to average over.
Returns:
The smoothened values.

simplify

public static java.util.List<processing.core.PVector> simplify(java.util.List<processing.core.PVector> points,
                                                               float tolerance,
                                                               boolean highestQuality)
Simplifies points by using Douglas-Peucker algorithm. Can be used to reduce complexity. This is zoom-dependent when used for Locations due to the tolerance value.

Opposite to computeMovingAverage(List, int) this reduces the amount of vertices, and thus improves performance, but may result in still too complex paths. You might want to combine both methods.

Based on Simplify.js by Vladimir Agafonkin. Ported to Java and modified for Unfolding by Till Nagel.

Parameters:
points - A list of vertices.
tolerance - The amount of simplification (in the same metric as the points).
highestQuality - Whether to exclude distance-based preprocessing step which leads to highest quality simplification but runs ~10-20 times slower.
Returns:
A list of simplified vertices.

getSquareDistance

protected static float getSquareDistance(processing.core.PVector p1,
                                         processing.core.PVector p2)
Square distance between 2 points.


getSquareSegmentDistance

protected static float getSquareSegmentDistance(processing.core.PVector p,
                                                processing.core.PVector p1,
                                                processing.core.PVector p2)
Square distance from a point to a segment.


simplifyRadialDistance

protected static java.util.List<processing.core.PVector> simplifyRadialDistance(java.util.List<processing.core.PVector> points,
                                                                                float sqTolerance)
Distance-based simplification.

Parameters:
points - List of vertices.
sqTolerance - The square tolerance value.
Returns:
A list of simplified vertices.

simplifyDouglasPeucker

protected static java.util.List<processing.core.PVector> simplifyDouglasPeucker(java.util.List<processing.core.PVector> points,
                                                                                float sqTolerance)
Simplification using optimized Douglas-Peucker algorithm with recursion elimination.

Parameters:
points - List of vertices.
sqTolerance - The square tolerance value.
Returns:
A list of simplified vertices.