1 package tim.prune.function.compress;
3 import tim.prune.data.DataPoint;
4 import tim.prune.data.Track;
7 * Class to hold details about a track
8 * which might be useful for compression
10 public class TrackDetails
13 private Track _track = null;
15 private double _trackSpan = -1.0;
16 /** Markers for start of segment */
17 private boolean[] _segmentStarts = null;
18 /** Markers for end of segment */
19 private boolean[] _segmentEnds = null;
20 /** Mean distance between track points in radians */
21 private double _meanRadians = 0.0;
26 * @param inTrack track object
28 public TrackDetails(Track inTrack)
34 * Recalculate all details
36 public void initialise()
38 // calculate track span
39 double xRange = _track.getXRange().getRange();
40 double yRange = _track.getYRange().getRange();
41 _trackSpan = (xRange > yRange ? xRange : yRange);
43 // Calculate segment starts / ends
44 int numPoints = _track.getNumPoints();
45 _segmentStarts = new boolean[numPoints];
46 _segmentEnds = new boolean[numPoints];
47 int prevTrackPointIndex = -1;
48 int numDistances = 0; double totalRadians = 0.0;
50 for (int i=0; i<numPoints; i++)
52 DataPoint point = _track.getPoint(i);
53 if (!point.isWaypoint())
55 // track point, check for segment flag
56 if (point.getSegmentStart())
58 // set start of segment and end of previous
59 _segmentStarts[i] = true;
60 if (prevTrackPointIndex >= 0) {
61 _segmentEnds[prevTrackPointIndex] = true;
65 // Add up distances between points within the same track segment
66 if (prevTrackPointIndex >= 0) {
68 totalRadians += DataPoint.calculateRadiansBetween(_track.getPoint(prevTrackPointIndex), point);
71 prevTrackPointIndex = i;
75 _segmentEnds[prevTrackPointIndex] = true;
76 // Mean radians between points
77 _meanRadians = totalRadians / numDistances;
82 * @return the track span
84 public double getTrackSpan()
86 if (_trackSpan < 0.0) {initialise();}
91 * @param inPointIndex index of point to check
92 * @return true if specified point is start of segment
94 public boolean isSegmentStart(int inPointIndex)
96 if (_segmentStarts == null ||
97 _segmentStarts.length != _track.getNumPoints()) {initialise();}
98 return _segmentStarts[inPointIndex];
102 * @param inPointIndex index of point to check
103 * @return true if specified point is end of segment
105 public boolean isSegmentEnd(int inPointIndex)
107 if (_segmentEnds == null ||
108 _segmentEnds.length != _track.getNumPoints()) {initialise();}
109 return _segmentEnds[inPointIndex];
113 * @return mean radians between adjacent track points
115 public double getMeanRadians()
117 if (_meanRadians == 0.0) {initialise();}