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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
package tim.prune.function.compress;
import tim.prune.data.DataPoint;
import tim.prune.data.Track;
/**
* Class to hold details about a track
* which might be useful for compression
*/
public class TrackDetails
{
/** Track object */
private Track _track = null;
/** Range span */
private double _trackSpan = -1.0;
/** Markers for start of segment */
private boolean[] _segmentStarts = null;
/** Markers for end of segment */
private boolean[] _segmentEnds = null;
/** Mean distance between track points in radians */
private double _meanRadians = 0.0;
/**
* Constructor
* @param inTrack track object
*/
public TrackDetails(Track inTrack)
{
_track = inTrack;
}
/**
* Recalculate all details
*/
public void initialise()
{
// calculate track span
double xRange = _track.getXRange().getRange();
double yRange = _track.getYRange().getRange();
_trackSpan = (xRange > yRange ? xRange : yRange);
// Calculate segment starts / ends
int numPoints = _track.getNumPoints();
_segmentStarts = new boolean[numPoints];
_segmentEnds = new boolean[numPoints];
int prevTrackPointIndex = -1;
int numDistances = 0; double totalRadians = 0.0;
// Loop over points
for (int i=0; i<numPoints; i++)
{
DataPoint point = _track.getPoint(i);
if (!point.isWaypoint())
{
// track point, check for segment flag
if (point.getSegmentStart())
{
// set start of segment and end of previous
_segmentStarts[i] = true;
if (prevTrackPointIndex >= 0) {
_segmentEnds[prevTrackPointIndex] = true;
}
}
else {
// Add up distances between points within the same track segment
if (prevTrackPointIndex >= 0) {
numDistances++;
totalRadians += DataPoint.calculateRadiansBetween(_track.getPoint(prevTrackPointIndex), point);
}
}
prevTrackPointIndex = i;
}
}
// last segment
_segmentEnds[prevTrackPointIndex] = true;
// Mean radians between points
_meanRadians = totalRadians / numDistances;
}
/**
* @return the track span
*/
public double getTrackSpan()
{
if (_trackSpan < 0.0) {initialise();}
return _trackSpan;
}
/**
* @param inPointIndex index of point to check
* @return true if specified point is start of segment
*/
public boolean isSegmentStart(int inPointIndex)
{
if (_segmentStarts == null ||
_segmentStarts.length != _track.getNumPoints()) {initialise();}
return _segmentStarts[inPointIndex];
}
/**
* @param inPointIndex index of point to check
* @return true if specified point is end of segment
*/
public boolean isSegmentEnd(int inPointIndex)
{
if (_segmentEnds == null ||
_segmentEnds.length != _track.getNumPoints()) {initialise();}
return _segmentEnds[inPointIndex];
}
/**
* @return mean radians between adjacent track points
*/
public double getMeanRadians()
{
if (_meanRadians == 0.0) {initialise();}
return _meanRadians;
}
}
|