private void ComputeDisplacementAngle(TrajectoryKinematics kinematics, CalibrationHelper calibrationHelper) { double total = 0; kinematics.DisplacementAngle[0] = 0; kinematics.TotalDisplacementAngle[0] = total; for (int i = 1; i < kinematics.Length; i++) { double displacement = GetDisplacementAngle(kinematics, i, i - 1); total += displacement; kinematics.DisplacementAngle[i] = calibrationHelper.ConvertAngle((float)displacement); kinematics.TotalDisplacementAngle[i] = calibrationHelper.ConvertAngle((float)total); } }
public void WriteXml(XmlWriter w, SerializationFilter filter) { if (ShouldSerializeCore(filter)) { w.WriteElementString("PointO", XmlHelper.WritePointF(points["o"])); w.WriteElementString("PointA", XmlHelper.WritePointF(points["a"])); w.WriteElementString("PointB", XmlHelper.WritePointF(points["b"])); w.WriteElementString("Signed", XmlHelper.WriteBoolean(signedAngle)); w.WriteElementString("CCW", XmlHelper.WriteBoolean(counterClockwise)); w.WriteElementString("Supplementary", XmlHelper.WriteBoolean(supplementaryAngle)); } if (ShouldSerializeStyle(filter)) { w.WriteStartElement("DrawingStyle"); style.WriteXml(w); w.WriteEndElement(); } if (ShouldSerializeFading(filter)) { w.WriteStartElement("InfosFading"); infosFading.WriteXml(w); w.WriteEndElement(); } if (ShouldSerializeAll(filter)) { // Spreadsheet support. w.WriteStartElement("Measure"); float angle = CalibrationHelper.ConvertAngle(angleHelper.CalibratedAngle); w.WriteAttributeString("UserAngle", angle.ToString()); w.WriteEndElement(); } }
public void DrawText(Graphics canvas, double opacity, SolidBrush brushFill, PointF o, IImageToViewportTransformer transformer, CalibrationHelper calibrationHelper, StyleHelper styleHelper) { float value = calibrationHelper.ConvertAngle(CalibratedAngle); string label = ""; if (tenth || calibrationHelper.AngleUnit == AngleUnit.Radian) { label = string.Format("{0:0.0} {1}", value, calibrationHelper.GetAngleAbbreviation()); } else { label = string.Format("{0} {1}", (int)Math.Round(value), calibrationHelper.GetAngleAbbreviation()); } if (!string.IsNullOrEmpty(symbol)) { label = string.Format("{0} = {1}", symbol, label); } SolidBrush fontBrush = styleHelper.GetForegroundBrush((int)(opacity * 255)); Font tempFont = styleHelper.GetFont(1.0F); SizeF labelSize = canvas.MeasureString(label, tempFont); Font tempFontTransformed = styleHelper.GetFont(Math.Max((float)transformer.Scale, 1.0F)); SizeF labelSizeTransformed = canvas.MeasureString(label, tempFontTransformed); // Background PointF textPosition = GetTextPosition(textDistance, labelSize); textPosition = textPosition.Scale((float)transformer.Scale); PointF backgroundOrigin = o.Translate(textPosition.X, textPosition.Y); RectangleF backRectangle = new RectangleF(backgroundOrigin, labelSizeTransformed); RoundedRectangle.Draw(canvas, backRectangle, brushFill, tempFontTransformed.Height / 4, false, false, null); // Text canvas.DrawString(label, tempFontTransformed, fontBrush, backgroundOrigin); tempFont.Dispose(); tempFontTransformed.Dispose(); fontBrush.Dispose(); }
private void DrawAngles(Pen penEdge, Color basePenEdgeColor, SolidBrush brushFill, Color baseBrushFillColor, int alpha, int alphaBackground, double opacity, Graphics canvas, IImageToViewportTransformer transformer, List <Point> points) { UpdateAngles(); penEdge.Width = 2; penEdge.DashStyle = DashStyle.Solid; for (int i = 0; i < angles.Count; i++) { if (!IsActive(genericPosture.Angles[i].OptionGroup)) { continue; } AngleHelper angleHelper = angles[i]; Rectangle box = transformer.Transform(angleHelper.SweepAngle.BoundingBox); Color color = genericPosture.Angles[i].Color; try { penEdge.Color = color == Color.Transparent ? basePenEdgeColor : Color.FromArgb(alpha, color); brushFill.Color = color == Color.Transparent ? baseBrushFillColor : Color.FromArgb(alphaBackground, color); canvas.FillPie(brushFill, box, angleHelper.SweepAngle.Start, angleHelper.SweepAngle.Sweep); canvas.DrawArc(penEdge, box, angleHelper.SweepAngle.Start, angleHelper.SweepAngle.Sweep); } catch (Exception e) { log.DebugFormat(e.ToString()); } Point origin = transformer.Transform(angleHelper.SweepAngle.Origin); if (!PreferencesManager.PlayerPreferences.EnableCustomToolsDebugMode) { angleHelper.DrawText(canvas, opacity, brushFill, origin, transformer, CalibrationHelper, styleHelper); } else { GenericPostureAngle gpa = genericPosture.Angles[i]; float value = CalibrationHelper.ConvertAngle(angleHelper.CalibratedAngle); string debugLabel = string.Format("A{0} [P{1}, P{2}, P{3}]\n", i, gpa.Leg1, gpa.Origin, gpa.Leg2); if (!string.IsNullOrEmpty(gpa.Name)) { debugLabel += string.Format("Name:{0}\n", gpa.Name); } debugLabel += string.Format("Signed:{0}\n", gpa.Signed); debugLabel += string.Format("CCW:{0}\n", gpa.CCW); debugLabel += string.Format("Supplementary:{0}\n", gpa.Supplementary); debugLabel += string.Format("Value: {0:0.0} {1}", value, CalibrationHelper.GetAngleAbbreviation()); SizeF debugLabelSize = canvas.MeasureString(debugLabel, debugFont); int debugLabelDistance = (int)debugOffset.X * 8; PointF debugLabelPositionRelative = angleHelper.GetTextPosition(debugLabelDistance, debugLabelSize); debugLabelPositionRelative = debugLabelPositionRelative.Scale((float)transformer.Scale); PointF debugLabelPosition = new PointF(origin.X + debugLabelPositionRelative.X, origin.Y + debugLabelPositionRelative.Y); RectangleF backRectangle = new RectangleF(debugLabelPosition, debugLabelSize); int roundingRadius = (int)(debugFont.Height * 0.25f); RoundedRectangle.Draw(canvas, backRectangle, debugBrush, roundingRadius, false, false, null); canvas.DrawString(debugLabel, debugFont, Brushes.White, backRectangle.Location); } } brushFill.Color = baseBrushFillColor; penEdge.Width = 1; penEdge.Color = basePenEdgeColor; }
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); } } }