private void UpdatePlot() { // Create plot values from selected options. TimeSeriesPlotData xSeries = cbSourceX.SelectedItem as TimeSeriesPlotData; TimeSeriesPlotData ySeries = cbSourceY.SelectedItem as TimeSeriesPlotData; if (xSeries == null || ySeries == null || xSeries == ySeries) { return; } TimeSeriesPlotSpecification spec = cmbDataSource.SelectedItem as TimeSeriesPlotSpecification; if (spec == null) { return; } PlotModel model = CreatePlot(xSeries, ySeries, spec.Component, spec.Abbreviation, spec.Label); plotView.Model = model; tbTitle.Text = model.Title; tbXAxis.Text = model.Axes[0].Title; tbYAxis.Text = model.Axes[1].Title; }
private void ImportOtherDrawingsData(Metadata metadata) { LinearKinematics linearKinematics = new LinearKinematics(); // Trackable drawing's individual points. foreach (ITrackable trackable in metadata.TrackableDrawings()) { Dictionary <string, TrackablePoint> trackablePoints = metadata.TrackabilityManager.GetTrackablePoints(trackable); if (trackablePoints == null) { continue; } foreach (var pair in trackablePoints) { TrackablePoint tp = pair.Value; Timeline <TrackFrame> timeline = pair.Value.Timeline; if (timeline.Count == 0) { continue; } 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); TimeSeriesCollection tsc = linearKinematics.BuildKinematics(traj, metadata.CalibrationHelper); string name = trackable.Name; Color color = trackable.Color; // Custom drawings may have dedicated names for their handles. DrawingGenericPosture dgp = trackable as DrawingGenericPosture; if (dgp == null) { name = name + " - " + pair.Key; } else { foreach (var handle in dgp.GenericPostureHandles) { if (handle.Reference.ToString() != pair.Key) { continue; } name = name + " - " + (string.IsNullOrEmpty(handle.Name) ? pair.Key : handle.Name); color = handle.Color == Color.Transparent ? trackable.Color : handle.Color; break; } } TimeSeriesPlotData data = new TimeSeriesPlotData(name, color, tsc); timeSeriesData.Add(data); filteredTrajectories.Add(data, traj); } } }
private void ImportTrackData(Metadata metadata) { foreach (DrawingTrack track in metadata.Tracks()) { TimeSeriesPlotData data = new TimeSeriesPlotData(track.Name, track.MainColor, track.TimeSeriesCollection); timeSeriesData.Add(data); filteredTrajectories.Add(data, track.FilteredTrajectory); } }
private static void ImportAngleDrawingsData(Metadata metadata, List <TimeSeriesPlotData> timeSeriesData) { // Create three filtered trajectories named o, a, b directly based on the trackable points. foreach (DrawingAngle drawingAngle in metadata.Angles()) { Dictionary <string, FilteredTrajectory> trajs = new Dictionary <string, FilteredTrajectory>(); Dictionary <string, TrackablePoint> trackablePoints = metadata.TrackabilityManager.GetTrackablePoints(drawingAngle); bool tracked = true; foreach (string key in trackablePoints.Keys) { Timeline <TrackFrame> timeline = trackablePoints[key].Timeline; if (timeline.Count == 0) { 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; } TimeSeriesCollection tsc = angularKinematics.BuildKinematics(trajs, drawingAngle.AngleOptions, metadata.CalibrationHelper); TimeSeriesPlotData data = new TimeSeriesPlotData(drawingAngle.Name, drawingAngle.Color, tsc); timeSeriesData.Add(data); } }
private PlotModel CreatePlot(TimeSeriesPlotData xSeries, TimeSeriesPlotData ySeries, Kinematics component, string abbreviation, string title) { if (xSeries == null || ySeries == null || xSeries == ySeries) { return(null); } PlotModel model = new PlotModel(); model.PlotType = PlotType.XY; model.Title = string.Format("{0} v {1} - {2}", xSeries.Label, ySeries.Label, title); LinearAxis xAxis = new LinearAxis(); xAxis.Position = AxisPosition.Bottom; xAxis.MajorGridlineStyle = LineStyle.Solid; xAxis.MinorGridlineStyle = LineStyle.Dot; xAxis.MinimumPadding = 0.05; xAxis.MaximumPadding = 0.1; xAxis.Title = string.Format("{0} {1} ({2})", xSeries.Label, title, abbreviation); model.Axes.Add(xAxis); LinearAxis yAxis = new LinearAxis(); yAxis.Position = AxisPosition.Left; yAxis.MajorGridlineStyle = LineStyle.Solid; yAxis.MinorGridlineStyle = LineStyle.Dot; yAxis.MinimumPadding = 0.05; yAxis.MaximumPadding = 0.1; yAxis.Title = string.Format("{0} {1} ({2})", ySeries.Label, title, abbreviation); model.Axes.Add(yAxis); LineSeries series = new LineSeries(); //series.Title = //series.Color = OxyColor.; series.MarkerType = MarkerType.Circle; series.Smooth = true; double[] xPoints = xSeries.TimeSeriesCollection[component]; double[] yPoints = ySeries.TimeSeriesCollection[component]; long[] xTimes = xSeries.TimeSeriesCollection.Times; long[] yTimes = ySeries.TimeSeriesCollection.Times; // The plot is only defined in the range of common time coordinates. int xIndex = 0; int yIndex = 0; while (xIndex < xTimes.Length && yIndex < yTimes.Length) { long xTime = xTimes[xIndex]; long yTime = yTimes[yIndex]; if (xTime < yTime) { xIndex++; continue; } else if (yTime < xTime) { yIndex++; continue; } else { series.Points.Add(new DataPoint(xPoints[xIndex], yPoints[yIndex])); xIndex++; yIndex++; } } model.Series.Add(series); return(model); }
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); } } }