public TimeSeriesCollection BuildKinematics(Dictionary <string, FilteredTrajectory> trajs, AngleOptions angleOptions, CalibrationHelper calibrationHelper) { if (trajs == null || trajs.Count != 3) { throw new InvalidProgramException(); } // Assume o, a, b keys for now. // We also use the "o" key as a reference, this implies that all three trajectories must have data at the same time points. // We must take care during tracking to keep the length of trajectories the same. TimeSeriesCollection tsc = new TimeSeriesCollection(trajs["o"].Length); tsc.AddTimes(trajs["o"].Times); tsc.InitializeKinematicComponents(new List <Kinematics>() { Kinematics.AngularPosition, Kinematics.AngularDisplacement, Kinematics.TotalAngularDisplacement, Kinematics.AngularVelocity, Kinematics.TangentialVelocity, Kinematics.AngularAcceleration, Kinematics.TangentialAcceleration, Kinematics.CentripetalAcceleration, Kinematics.ResultantLinearAcceleration }); // Keep series in the reference unit. radii = new float[tsc.Length]; positions = new float[tsc.Length]; velocities = new float[tsc.Length]; accelerations = new float[tsc.Length]; ComputeAngles(tsc, calibrationHelper, trajs, angleOptions); ComputeVelocity(tsc, calibrationHelper); ComputeAcceleration(tsc, calibrationHelper); return(tsc); }
private void ComputeAngles(TimeSeriesCollection tsc, CalibrationHelper calibrationHelper, Dictionary <string, FilteredTrajectory> trajs, AngleOptions angleOptions) { for (int i = 0; i < tsc.Length; i++) { PointF o = PointF.Empty; PointF a = PointF.Empty; PointF b = PointF.Empty; if (trajs["o"].CanFilter) { o = trajs["o"].Coordinates(i); a = trajs["a"].Coordinates(i); b = trajs["b"].Coordinates(i); } else { o = trajs["o"].RawCoordinates(i); a = trajs["a"].RawCoordinates(i); b = trajs["b"].RawCoordinates(i); } // Compute the actual angle value. The logic here should match the one in AngleHelper.Update(). // They work on different type of inputs so it's difficult to factorize the functions. if (angleOptions.Supplementary) { // Create a new point by point reflection of a around o. PointF c = new PointF(2 * o.X - a.X, 2 * o.Y - a.Y); a = b; b = c; } float angle = 0; if (angleOptions.CCW) { angle = GeometryHelper.GetAngle(o, a, b); } else { angle = GeometryHelper.GetAngle(o, b, a); } if (!angleOptions.Signed && angle < 0) { angle = (float)(TAU + angle); } positions[i] = angle; radii[i] = GeometryHelper.GetDistance(o, b); tsc[Kinematics.AngularPosition][i] = calibrationHelper.ConvertAngle(angle); if (i == 0) { tsc[Kinematics.AngularDisplacement][i] = 0; tsc[Kinematics.TotalAngularDisplacement][i] = 0; } else { float totalDisplacementAngle = angle - positions[0]; float displacementAngle = angle - positions[i - 1]; tsc[Kinematics.AngularDisplacement][i] = calibrationHelper.ConvertAngle(displacementAngle); tsc[Kinematics.TotalAngularDisplacement][i] = calibrationHelper.ConvertAngle(totalDisplacementAngle); } } }
private static void ImportCustomDrawingsData(Metadata metadata, List <TimeSeriesPlotData> timeSeriesData) { // Collect angular trajectories for all the angles in all the custom tools. foreach (DrawingGenericPosture drawing in metadata.GenericPostures()) { Dictionary <string, TrackablePoint> trackablePoints = metadata.TrackabilityManager.GetTrackablePoints(drawing); // First create trajectories for all the trackable points in the drawing. // This avoids duplicating the filtering operation for points shared by more than one angle. // Here the trajectories are indexed by the original alias in the custom tool, based on the index. Dictionary <string, FilteredTrajectory> trajs = new Dictionary <string, FilteredTrajectory>(); bool tracked = true; foreach (string key in trackablePoints.Keys) { Timeline <TrackFrame> timeline = trackablePoints[key].Timeline; if (timeline.Count == 0) { // The point is trackable but doesn't have any timeline data. // This happens if the user is not tracking that drawing, so we don't need to go further. tracked = false; break; } List <TimedPoint> samples = timeline.Enumerate().Select(p => new TimedPoint(p.Location.X, p.Location.Y, p.Time)).ToList(); FilteredTrajectory traj = new FilteredTrajectory(); traj.Initialize(samples, metadata.CalibrationHelper); trajs.Add(key, traj); } if (!tracked) { continue; } // Loop over all angles in this drawing and find the trackable aliases of the points making up the particular angle. // The final collection of trajectories for each angle should have indices named o, a, b. foreach (GenericPostureAngle gpa in drawing.GenericPostureAngles) { // From integer indices to tracking aliases. string keyO = gpa.Origin.ToString(); string keyA = gpa.Leg1.ToString(); string keyB = gpa.Leg2.ToString(); // All points in an angle must be trackable as there is currently no way to get the static point coordinate. if (!trajs.ContainsKey(keyO) || !trajs.ContainsKey(keyA) || !trajs.ContainsKey(keyB)) { continue; } // Remap to oab. Dictionary <string, FilteredTrajectory> angleTrajs = new Dictionary <string, FilteredTrajectory>(); angleTrajs.Add("o", trajs[keyO]); angleTrajs.Add("a", trajs[keyA]); angleTrajs.Add("b", trajs[keyB]); AngleOptions options = new AngleOptions(gpa.Signed, gpa.CCW, gpa.Supplementary); TimeSeriesCollection tsc = angularKinematics.BuildKinematics(angleTrajs, options, metadata.CalibrationHelper); string name = drawing.Name; if (!string.IsNullOrEmpty(gpa.Name)) { name = name + " - " + gpa.Name; } Color color = gpa.Color == Color.Transparent ? drawing.Color : gpa.Color; TimeSeriesPlotData data = new TimeSeriesPlotData(name, color, tsc); timeSeriesData.Add(data); } } }