| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | namespace ReFlex.Core.Common.Components |
| | | 4 | | { |
| | | 5 | | /// <summary> |
| | | 6 | | /// Motion in raster coordinates per second (Z is normalized depth); acceleration is units/s². |
| | | 7 | | /// Both forecasts target PredictionTimestampSeconds. FrameId identifies the latest processed |
| | | 8 | | /// observation; LastMeasuredFrameId identifies the contact's last real measurement. Lost contacts |
| | | 9 | | /// retain that measurement and its smoothed position. Diagnostics are never fed |
| | | 10 | | /// back as measurements. Derivatives are evaluated at the last measurement time. |
| | | 11 | | /// </summary> |
| | | 12 | | public class InteractionVelocity |
| | | 13 | | { |
| | 528 | 14 | | public int TouchId { get; set; } |
| | 270 | 15 | | public int FrameId { get; set; } |
| | 262 | 16 | | public int LastMeasuredFrameId { get; set; } |
| | 264 | 17 | | public double TimestampSeconds { get; set; } |
| | 262 | 18 | | public double LastMeasuredTimestampSeconds { get; set; } |
| | 274 | 19 | | public double PredictionTimestampSeconds { get; set; } |
| | 262 | 20 | | public double PredictionHorizonSeconds { get; set; } |
| | 266 | 21 | | public float Confidence { get; set; } |
| | 282 | 22 | | public int SampleCount { get; set; } |
| | 534 | 23 | | public bool IsPredicted { get; set; } |
| | 466 | 24 | | public bool IsPublished { get; set; } |
| | 1434 | 25 | | public string SuppressionReason { get; set; } = ""; |
| | 262 | 26 | | public bool UseSecondDerivation { get; set; } |
| | 208 | 27 | | public int Width { get; set; } |
| | 208 | 28 | | public int Height { get; set; } |
| | 2450 | 29 | | public Point3 MeasuredPosition { get; set; } = new Point3(); |
| | 1484 | 30 | | public Point3 SmoothedPosition { get; set; } = new Point3(); |
| | 1494 | 31 | | public Point3 MatchingPosition { get; set; } = new Point3(); |
| | 2474 | 32 | | public Point3 FirstDerivation { get; set; } = new Point3(); |
| | 2460 | 33 | | public Point3 SecondDerivation { get; set; } = new Point3(); |
| | 4630 | 34 | | public Point3 PredictedPositionBasic { get; set; } = new Point3(); |
| | 2496 | 35 | | public Point3 PredictedPositionAdvanced { get; set; } = new Point3(); |
| | | 36 | | |
| | 3666 | 37 | | public InteractionVelocity() { } |
| | | 38 | | |
| | 0 | 39 | | public InteractionVelocity(int touchId, Point3 position, Point3 firstDerivation = null, |
| | 0 | 40 | | Point3 secondDerivation = null, float secondDerivationMagnitude = .5f) |
| | 0 | 41 | | { |
| | 0 | 42 | | TouchId = touchId; |
| | 0 | 43 | | Update(position, firstDerivation ?? new Point3(), secondDerivation ?? new Point3(), secondDerivationMagnitud |
| | 0 | 44 | | } |
| | | 45 | | |
| | | 46 | | /// <summary>h is seconds. p(t+h) = p(t) + v(t) h + magnitude a(t) h²; .5 gives constant acceleration.</summary> |
| | | 47 | | public void Update(Point3 position, Point3 firstDerivation, Point3 secondDerivation, |
| | | 48 | | float secondDerivationMagnitude = .5f, float horizon = 1) |
| | 1222 | 49 | | { |
| | 1222 | 50 | | if (!float.IsFinite(horizon) || horizon < 0) |
| | 0 | 51 | | throw new ArgumentOutOfRangeException(nameof(horizon)); |
| | 1222 | 52 | | if (!float.IsFinite(secondDerivationMagnitude) || secondDerivationMagnitude < 0) |
| | 0 | 53 | | throw new ArgumentOutOfRangeException(nameof(secondDerivationMagnitude)); |
| | 1222 | 54 | | MeasuredPosition = (Point3)position.Copy(); |
| | 1222 | 55 | | FirstDerivation = (Point3)firstDerivation.Copy(); |
| | 1222 | 56 | | SecondDerivation = (Point3)secondDerivation.Copy(); |
| | 1222 | 57 | | PredictedPositionBasic = position + firstDerivation * horizon; |
| | 1222 | 58 | | PredictedPositionAdvanced = PredictedPositionBasic + secondDerivation * (secondDerivationMagnitude * horizon |
| | 1222 | 59 | | } |
| | | 60 | | } |
| | | 61 | | } |