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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
package tim.prune.correlate;
import tim.prune.data.DataPoint;
import tim.prune.data.Photo;
/**
* Class to hold a pair of points
* used to hold the result of correlation of a photo
*/
public class PointPair
{
private Photo _photo = null;
private DataPoint _pointBefore = null;
private DataPoint _pointAfter = null;
private long _secondsBefore = 1L;
private long _secondsAfter = -1L;
/**
* Constructor
* @param inPhoto Photo object
*/
public PointPair(Photo inPhoto)
{
_photo = inPhoto;
}
/**
* Add a point to the pair
* @param inPoint data point
* @param inSeconds number of seconds time difference, positive means point later
*/
public void addPoint(DataPoint inPoint, long inSeconds)
{
// Check if point is closest point before
if (inSeconds <= 0)
{
// point stamp is before photo stamp
if (inSeconds > _secondsBefore || _secondsBefore > 0L)
{
// point stamp is nearer to photo
_pointBefore = inPoint;
_secondsBefore = inSeconds;
}
}
// Check if point is closest point after
if (inSeconds >= 0)
{
// point stamp is after photo stamp
if (inSeconds < _secondsAfter || _secondsAfter < 0L)
{
// point stamp is nearer to photo
_pointAfter = inPoint;
_secondsAfter = inSeconds;
}
}
}
/**
* @return Photo object
*/
public Photo getPhoto()
{
return _photo;
}
/**
* @return the closest point before the photo
*/
public DataPoint getPointBefore()
{
return _pointBefore;
}
/**
* @return number of seconds between photo and subsequent point
*/
public long getSecondsBefore()
{
return _secondsBefore;
}
/**
* @return the closest point after the photo
*/
public DataPoint getPointAfter()
{
return _pointAfter;
}
/**
* @return number of seconds between previous point and photo
*/
public long getSecondsAfter()
{
return _secondsAfter;
}
/**
* @return true if both points found
*/
public boolean isValid()
{
return getPointBefore() != null && getPointAfter() != null;
}
/**
* @return the fraction of the distance along the interpolated line
*/
public double getFraction()
{
if (_secondsAfter == 0L) return 0.0;
return (-_secondsBefore * 1.0 / (-_secondsBefore + _secondsAfter));
}
/**
* @return the number of seconds to the nearest point
*/
public long getMinSeconds()
{
return Math.min(_secondsAfter, -_secondsBefore);
}
/**
* @return angle from photo to nearest point in radians
*/
public double getMinRadians()
{
double totalRadians = DataPoint.calculateRadiansBetween(_pointBefore, _pointAfter);
double frac = getFraction();
return totalRadians * Math.min(frac, 1-frac);
}
}
|