File: WackyPointsMethod.java

package info (click to toggle)
gpsprune 26.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,824 kB
  • sloc: java: 52,154; sh: 25; makefile: 21; python: 15
file content (79 lines) | stat: -rw-r--r-- 2,503 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package tim.prune.function.compress.methods;

import tim.prune.data.DataPoint;
import tim.prune.data.MarkingData;
import tim.prune.data.NumberUtils;
import tim.prune.data.Track;
import tim.prune.function.compress.CompressionMethodType;
import tim.prune.function.compress.TrackDetails;

public class WackyPointsMethod extends CompressionMethod
{
	private final double _factor;

	public WackyPointsMethod(double factor) {
		_factor = factor;
	}

	public WackyPointsMethod(String inString) {
		_factor = NumberUtils.getDoubleOrZero(recogniseString(inString) ? inString.substring(4) : inString);
	}

	public CompressionMethodType getType() {
		return CompressionMethodType.WACKY_POINTS;
	}

	public String getParam() {
		return "" + Math.abs(_factor);
	}

	public int compress(Track inTrack, TrackDetails inDetails, MarkingData inMarkings)
	{
		if (_factor <= 0.0) {
			return 0;
		}
		int numPoints = inTrack.getNumPoints();
		int numDeleted = 0;
		double threshold = _factor * inDetails.getMeanRadians();
		DataPoint currPoint = null, prevPoint = null;
		// Loop over all points looking for points far away from neighbours
		for (int i=0; i<numPoints; i++)
		{
			if (inMarkings.isPointMarkedForDeletion(i)) {
				continue;
			}
			currPoint = inTrack.getPoint(i);
			// Don't delete any waypoints or photo points, or start/end of segments
			if (!currPoint.isWaypoint() && !currPoint.hasMedia()
				&& !inDetails.isSegmentStart(i) && !inDetails.isSegmentEnd(i))
			{
				// Measure distance from previous track point
				if (DataPoint.calculateRadiansBetween(prevPoint, currPoint) > threshold)
				{
					// Now need to find next track point, and measure distances
					DataPoint nextPoint = getNextTrackPoint(inTrack, i+1, inMarkings);
					if (nextPoint != null && DataPoint.calculateRadiansBetween(currPoint, nextPoint) > threshold
						&& DataPoint.calculateRadiansBetween(prevPoint, nextPoint) < threshold)
					{
						// Found a point to delete
						inMarkings.markPointForDeletion(i);
						numDeleted++;
					}
				}
			}
			// Remember last (not-deleted) track point
			if (!currPoint.isWaypoint() && !inMarkings.isPointMarkedForDeletion(i)) {
				prevPoint = currPoint;
			}
		}
		return numDeleted;
	}

	public String getSettingsString() {
		return getType().getKey() + _factor;
	}

	static boolean recogniseString(String inString) {
		return recogniseString(inString, CompressionMethodType.WACKY_POINTS);
	}
}