public void Nested_ToStringTest() { OscBundle target = UnitTestHelper.DoubleNestedBundle(); string expected = UnitTestHelper.DoubleNestedBundleString; string actual; actual = target.ToString(); Assert.AreEqual(expected, actual); }
/// <summary> /// Handles the body frame data arriving from the sensor /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> private void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e) { bool dataReceived = false; using (BodyFrame bodyFrame = e.FrameReference.AcquireFrame()) { if (bodyFrame != null) { if (this.bodies == null) { this.bodies = new Body[bodyFrame.BodyCount]; } // The first time GetAndRefreshBodyData is called, Kinect will allocate each Body in the array. // As long as those body objects are not disposed and not set to null in the array, // those body objects will be re-used. bodyFrame.GetAndRefreshBodyData(this.bodies); dataReceived = true; } } if (dataReceived) { using (DrawingContext dc = this.drawingGroup.Open()) { // Draw a transparent background to set the render size dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, this.displayWidth, this.displayHeight)); int penIndex = 0; foreach (Body body in this.bodies) { Pen drawPen = this.bodyColors[penIndex++]; if (body.IsTracked) { this.DrawClippedEdges(body, dc); IReadOnlyDictionary <JointType, Joint> joints = body.Joints; // log joints StringBuilder builder = new StringBuilder(); // it's ugly and verbose, but it's clear and in guaranteed order builder.Append(joints[JointType.AnkleLeft].Position.X + " " + joints[JointType.AnkleLeft].Position.Y + " " + joints[JointType.AnkleLeft].Position.Z + " "); builder.Append(joints[JointType.AnkleRight].Position.X + " " + joints[JointType.AnkleRight].Position.Y + " " + joints[JointType.AnkleRight].Position.Z + " "); builder.Append(joints[JointType.ElbowLeft].Position.X + " " + joints[JointType.ElbowLeft].Position.Y + " " + joints[JointType.ElbowLeft].Position.Z + " "); builder.Append(joints[JointType.ElbowRight].Position.X + " " + joints[JointType.ElbowRight].Position.Y + " " + joints[JointType.ElbowRight].Position.Z + " "); builder.Append(joints[JointType.FootLeft].Position.X + " " + joints[JointType.FootLeft].Position.Y + " " + joints[JointType.FootLeft].Position.Z + " "); builder.Append(joints[JointType.FootRight].Position.X + " " + joints[JointType.FootRight].Position.Y + " " + joints[JointType.FootRight].Position.Z + " "); builder.Append(joints[JointType.HandLeft].Position.X + " " + joints[JointType.HandLeft].Position.Y + " " + joints[JointType.HandLeft].Position.Z + " "); builder.Append(joints[JointType.HandRight].Position.X + " " + joints[JointType.HandRight].Position.Y + " " + joints[JointType.HandRight].Position.Z + " "); builder.Append(joints[JointType.HandTipLeft].Position.X + " " + joints[JointType.HandTipLeft].Position.Y + " " + joints[JointType.HandTipLeft].Position.Z + " "); builder.Append(joints[JointType.HandTipRight].Position.X + " " + joints[JointType.HandTipRight].Position.Y + " " + joints[JointType.HandTipRight].Position.Z + " "); builder.Append(joints[JointType.Head].Position.X + " " + joints[JointType.Head].Position.Y + " " + joints[JointType.Head].Position.Z + " "); builder.Append(joints[JointType.HipLeft].Position.X + " " + joints[JointType.HipLeft].Position.Y + " " + joints[JointType.HipLeft].Position.Z + " "); builder.Append(joints[JointType.HipRight].Position.X + " " + joints[JointType.HipRight].Position.Y + " " + joints[JointType.HipRight].Position.Z + " "); builder.Append(joints[JointType.KneeLeft].Position.X + " " + joints[JointType.KneeLeft].Position.Y + " " + joints[JointType.KneeLeft].Position.Z + " "); builder.Append(joints[JointType.KneeRight].Position.X + " " + joints[JointType.KneeRight].Position.Y + " " + joints[JointType.KneeRight].Position.Z + " "); builder.Append(joints[JointType.Neck].Position.X + " " + joints[JointType.Neck].Position.Y + " " + joints[JointType.Neck].Position.Z + " "); builder.Append(joints[JointType.ShoulderLeft].Position.X + " " + joints[JointType.ShoulderLeft].Position.Y + " " + joints[JointType.ShoulderLeft].Position.Z + " "); builder.Append(joints[JointType.ShoulderRight].Position.X + " " + joints[JointType.ShoulderRight].Position.Y + " " + joints[JointType.ShoulderRight].Position.Z + " "); builder.Append(joints[JointType.SpineBase].Position.X + " " + joints[JointType.SpineBase].Position.Y + " " + joints[JointType.SpineBase].Position.Z + " "); builder.Append(joints[JointType.SpineMid].Position.X + " " + joints[JointType.SpineMid].Position.Y + " " + joints[JointType.SpineMid].Position.Z + " "); builder.Append(joints[JointType.SpineShoulder].Position.X + " " + joints[JointType.SpineShoulder].Position.Y + " " + joints[JointType.SpineShoulder].Position.Z + " "); builder.Append(joints[JointType.ThumbLeft].Position.X + " " + joints[JointType.ThumbLeft].Position.Y + " " + joints[JointType.ThumbLeft].Position.Z + " "); builder.Append(joints[JointType.ThumbRight].Position.X + " " + joints[JointType.ThumbRight].Position.Y + " " + joints[JointType.ThumbRight].Position.Z + " "); builder.Append(joints[JointType.WristLeft].Position.X + " " + joints[JointType.WristLeft].Position.Y + " " + joints[JointType.WristLeft].Position.Z + " "); builder.Append(joints[JointType.WristRight].Position.X + " " + joints[JointType.WristRight].Position.Y + " " + joints[JointType.WristRight].Position.Z + " "); string jointStr = builder.ToString(); log.Info(jointStr); // convert the joint points to depth (display) space Dictionary <JointType, Point> jointPoints = new Dictionary <JointType, Point>(); foreach (JointType jointType in joints.Keys) { // sometimes the depth(Z) of an inferred joint may show as negative // clamp down to 0.1f to prevent coordinatemapper from returning (-Infinity, -Infinity) CameraSpacePoint position = joints[jointType].Position; if (position.Z < 0) { position.Z = InferredZPositionClamp; } DepthSpacePoint depthSpacePoint = this.coordinateMapper.MapCameraPointToDepthSpace(position); jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y); } this.DrawBody(joints, jointPoints, dc, drawPen); this.DrawHand(body.HandLeftState, jointPoints[JointType.HandLeft], dc); this.DrawHand(body.HandRightState, jointPoints[JointType.HandRight], dc); //by KO // setting data set : the name of the element + x + y + z //FOR MUSIC var HandRight = new SharpOSC.OscMessage(" /HandRight", " ", joints[JointType.HandRight].Position.X.ToString(), " ", joints[JointType.HandRight].Position.Y.ToString(), " ", joints[JointType.HandRight].Position.Z.ToString()); var HandTipLeft = new SharpOSC.OscMessage(" /HandTipLeft", " ", joints[JointType.HandTipLeft].Position.X.ToString(), " ", joints[JointType.HandTipLeft].Position.Y.ToString(), " ", joints[JointType.HandTipLeft].Position.Z.ToString()); var AnkleLeft = new SharpOSC.OscMessage(" /AnkleLeft", " ", joints[JointType.AnkleLeft].Position.X.ToString(), " ", joints[JointType.AnkleLeft].Position.Y.ToString(), " ", joints[JointType.AnkleLeft].Position.Z.ToString()); var AnkleRight = new SharpOSC.OscMessage(" /AnkleRight", " ", joints[JointType.AnkleRight].Position.X.ToString(), " ", joints[JointType.AnkleRight].Position.Y.ToString(), " ", joints[JointType.AnkleRight].Position.Z.ToString()); //PureData //var HandRight = new SharpOSC.OscMessage("/HandRight/position", joints[JointType.HandRight].Position.X, joints[JointType.HandRight].Position.Y, joints[JointType.HandRight].Position.Z); //var HandTipLeft = new SharpOSC.OscMessage("/HandTipLeft/position", joints[JointType.HandTipLeft].Position.X, joints[JointType.HandTipLeft].Position.Y, joints[JointType.HandTipLeft].Position.Z); //var AnkleLeft = new SharpOSC.OscMessage("/AnkleLeft", " ", joints[JointType.AnkleLeft].Position.X.ToString(), " ", joints[JointType.AnkleLeft].Position.Y.ToString(), " ", joints[JointType.AnkleLeft].Position.Z.ToString()); //var AnkleRight = new SharpOSC.OscMessage("/AnkleRight", " ", joints[JointType.AnkleRight].Position.X.ToString(), " ", joints[JointType.AnkleRight].Position.Y.ToString(), " ", joints[JointType.AnkleRight].Position.Z.ToString()); var ElbowLeft = new SharpOSC.OscMessage(" /ElbowLeft", " ", joints[JointType.ElbowLeft].Position.X.ToString(), " ", joints[JointType.ElbowLeft].Position.Y.ToString(), " ", joints[JointType.ElbowLeft].Position.Z.ToString()); var ElbowRight = new SharpOSC.OscMessage(" /ElbowRight", " ", joints[JointType.ElbowRight].Position.X.ToString(), " ", joints[JointType.ElbowRight].Position.Y.ToString(), " ", joints[JointType.ElbowRight].Position.Z.ToString()); var FootLeft = new SharpOSC.OscMessage(" /FootLeft", joints[JointType.FootLeft].Position.X.ToString(), joints[JointType.FootLeft].Position.Y.ToString(), joints[JointType.FootLeft].Position.Z.ToString()); var FootRight = new SharpOSC.OscMessage(" /FootRight", joints[JointType.FootRight].Position.X.ToString(), joints[JointType.FootRight].Position.Y.ToString(), joints[JointType.FootRight].Position.Z.ToString()); var HandLeft = new SharpOSC.OscMessage(" /HandLeft", " ", joints[JointType.HandLeft].Position.X.ToString(), " ", joints[JointType.HandLeft].Position.Y.ToString(), " ", joints[JointType.HandLeft].Position.Z.ToString()); var HandTipRight = new SharpOSC.OscMessage(" /HandTipRight", joints[JointType.HandTipRight].Position.X.ToString(), joints[JointType.HandTipRight].Position.Y.ToString(), joints[JointType.AnkleLeft].Position.Z.ToString()); var Head = new SharpOSC.OscMessage(" /Head", joints[JointType.Head].Position.X.ToString(), joints[JointType.Head].Position.Y.ToString(), joints[JointType.Head].Position.Z.ToString()); var HipLeft = new SharpOSC.OscMessage(" /HipLeft", joints[JointType.HipLeft].Position.X.ToString(), joints[JointType.HipLeft].Position.Y.ToString(), joints[JointType.HipLeft].Position.Z.ToString()); var HipRight = new SharpOSC.OscMessage(" /HipRight", joints[JointType.HipRight].Position.X.ToString(), joints[JointType.HipRight].Position.Y.ToString(), joints[JointType.HipRight].Position.Z.ToString()); var KneeLeft = new SharpOSC.OscMessage(" /KneeLeft", joints[JointType.KneeLeft].Position.X.ToString(), joints[JointType.KneeLeft].Position.Y.ToString(), joints[JointType.KneeLeft].Position.Z.ToString()); var KneeRight = new SharpOSC.OscMessage(" /KneeRight", joints[JointType.KneeRight].Position.X.ToString(), joints[JointType.KneeRight].Position.Y.ToString(), joints[JointType.KneeRight].Position.Z.ToString()); var Neck = new SharpOSC.OscMessage(" /Neck", joints[JointType.Neck].Position.X.ToString(), joints[JointType.Neck].Position.Y.ToString(), joints[JointType.Neck].Position.Z.ToString()); var ShoulderLeft = new SharpOSC.OscMessage(" /ShoulderLeft", joints[JointType.ShoulderLeft].Position.X.ToString(), joints[JointType.ShoulderLeft].Position.Y.ToString(), joints[JointType.ShoulderLeft].Position.Z.ToString()); var ShoulderRight = new SharpOSC.OscMessage(" /ShoulderRight", joints[JointType.ShoulderRight].Position.X.ToString(), joints[JointType.ShoulderRight].Position.Y.ToString(), joints[JointType.ShoulderRight].Position.Z.ToString()); var SpineBase = new SharpOSC.OscMessage(" /SpineBase", joints[JointType.SpineBase].Position.X.ToString(), joints[JointType.SpineBase].Position.Y.ToString(), joints[JointType.SpineBase].Position.Z.ToString()); var SpineMid = new SharpOSC.OscMessage(" /SpineMid", joints[JointType.SpineMid].Position.X.ToString(), joints[JointType.SpineMid].Position.Y.ToString(), joints[JointType.SpineMid].Position.Z.ToString()); var SpineShoulder = new SharpOSC.OscMessage(" /SpineShoulder", joints[JointType.SpineShoulder].Position.X.ToString(), joints[JointType.SpineShoulder].Position.Y.ToString(), joints[JointType.SpineShoulder].Position.Z.ToString()); var ThumbLeft = new SharpOSC.OscMessage(" /ThumbLeft", joints[JointType.ThumbLeft].Position.X.ToString(), joints[JointType.ThumbLeft].Position.Y.ToString(), joints[JointType.ThumbLeft].Position.Z.ToString()); var ThumbRight = new SharpOSC.OscMessage(" /ThumbRight", joints[JointType.ThumbRight].Position.X.ToString(), joints[JointType.ThumbRight].Position.Y.ToString(), joints[JointType.ThumbRight].Position.Z.ToString()); var WristLeft = new SharpOSC.OscMessage(" /WristLeft", joints[JointType.WristLeft].Position.X.ToString(), joints[JointType.WristLeft].Position.Y.ToString(), joints[JointType.WristLeft].Position.Z.ToString()); var WristRight = new SharpOSC.OscMessage(" /WristRight", joints[JointType.WristRight].Position.X.ToString(), joints[JointType.WristRight].Position.Y.ToString(), joints[JointType.WristRight].Position.Z.ToString()); // OSC message for area // var Area = new SharpOSC.OscMessage("/area", testV.ToString()); // Sending UDP OscBundle oscBundle = new OscBundle(0, HandRight, HandLeft, AnkleRight, AnkleLeft);//FOR MUSIC //OscBundle oscBundle = new OscBundle(0, HandRight);//FOR PureData //OscBundle oscBundle = new OscBundle(0, HandLeft, HandRight, HandTipLeft, HandTipRight); /*FootLeft, FootRight, HandLeft, HandRight, HandTipLeft, * HandTipRight, Head, HipLeft, HipRight, KneeLeft, KneeRight, Neck, ShoulderLeft, ShoulderRight, SpineBase, * SpineMid, SpineShoulder, ThumbLeft, ThumbRight, WristLeft, WristRight); */ Console.WriteLine("TEST SENDING:"); Console.WriteLine(oscBundle.ToString()); //Send Method (message) udpSender.Send(oscBundle); } } // prevent drawing outside of our render area this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, this.displayWidth, this.displayHeight)); } } }