1 package tim.prune.function.compress;
3 import java.awt.Component;
4 import java.awt.event.ActionListener;
6 import tim.prune.data.DataPoint;
7 import tim.prune.data.Track;
10 * Algorithm for detecting singleton points to compress
12 public class SingletonAlgorithm extends SingleParameterAlgorithm
16 * @param inTrack track object
17 * @param inDetails track details object
18 * @param inListener listener to attach to activation control
20 public SingletonAlgorithm(Track inTrack, TrackDetails inDetails, ActionListener inListener)
22 super(inTrack, inDetails, inListener);
26 * Perform the compression and work out which points should be deleted
27 * @param inFlags deletion flags from previous algorithms
28 * @return number of points deleted
30 protected int compress(boolean[] inFlags)
32 double param = getParameter();
33 if (param <= 0.0) return 0;
34 // System.out.println("Singleton algorithm compressing : " + param + ", " + _trackDetails.getMeanRadians());
35 int numPoints = _track.getNumPoints();
37 double threshold = param * _trackDetails.getMeanRadians();
38 DataPoint currPoint = null, prevPoint = null;
39 // Loop over all points looking for points far away from neighbours
40 for (int i=0; i<numPoints; i++)
42 currPoint = _track.getPoint(i);
43 // Don't delete points which are already marked as deleted
46 // Don't delete any waypoints or photo points
47 // Only interested in start and end of segments
48 if (!currPoint.isWaypoint() && !currPoint.hasMedia()
49 && _trackDetails.isSegmentStart(i) && _trackDetails.isSegmentEnd(i))
51 // Measure distance from previous track point
52 if (DataPoint.calculateRadiansBetween(prevPoint, currPoint) > threshold)
54 // Now need to find next track point, and measure distances
55 DataPoint nextPoint = _track.getNextTrackPoint(i+1);
56 if (nextPoint != null && DataPoint.calculateRadiansBetween(currPoint, nextPoint) > threshold)
58 // Found a point to delete (hope that next point hasn't been deleted already)
64 // Remember last (not-deleted) track point
65 if (!currPoint.isWaypoint()) {prevPoint = currPoint;}
72 * @return specific gui components for dialog
74 protected Component getSpecificGuiComponents()
76 return getSpecificGuiComponents("dialog.compress.singletons.paramdesc", "2");
80 * @return title key for box
82 protected String getTitleTextKey()
84 return "dialog.compress.singletons.title";