File: NearbyPointsMethod.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 (58 lines) | stat: -rw-r--r-- 1,730 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
package tim.prune.function.compress.methods;

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

public abstract class NearbyPointsMethod extends CompressionMethod
{
	public int compress(Track inTrack, TrackDetails inDetails, MarkingData inMarkings)
	{
		// Parse parameter
		final double radianThreshold = getRadianThreshold(inDetails);
		if (radianThreshold <= 0.0) {
			return 0;
		}

		// Loop over all points checking distances to previous point
		// TODO: Maybe this should also check distance to _next_ point as well!
		int numPoints = inTrack.getNumPoints();
		DataPoint prevPoint = null;
		int numDeleted = 0;
		for (int i=0; i<numPoints; i++)
		{
			// don't delete points already deleted
			if (inMarkings.isPointMarkedForDeletion(i)) {
				continue;
			}
			DataPoint currPoint = inTrack.getPoint(i);
			// Don't consider waypoints
			if (currPoint.isWaypoint()) {
				continue;
			}
			boolean deleted = false;
			// Don't delete any photo points or start/end of segments
			if (!currPoint.hasMedia()
				&& !isPointAtSegmentBoundary(i, inDetails, inMarkings)
				&& prevPoint != null)
			{
				// Check current point against prevPoint
				double radians = DataPoint.calculateRadiansBetween(prevPoint, currPoint);
				if (radians < radianThreshold)
				{
					inMarkings.markPointForDeletion(i);
					deleted = true;
					numDeleted++;
				}
			}
			if (!deleted) {
				prevPoint = currPoint;
			}
		}
		return numDeleted;
	}

	/** @return the radian threshold specified by the subclass */
	protected abstract double getRadianThreshold(TrackDetails inDetails);
}