/// <summary> /// Returns a KinectMotion of a single frame. /// </summary> /// <returns></returns> public KinectMotion takeSnapshot() { KinectMotion km = new KinectMotion(); km.addKeyframe(lastPlayer.copyPlayer()); return km; }
/// <summary> /// Reads from XML format outlined above. /// </summary> /// <param name="root"></param> /// <returns></returns> public static KinectMotion readFromXML(XElement root) { List<XElement> dataList = root.Descendants("Data").ToList<XElement>(); if(dataList == null) return null; XElement dataElement = dataList[0]; KinectMotion motion = new KinectMotion(int.Parse(dataElement.Attribute("Interval").Value), float.Parse(dataElement.Attribute("Length").Value), int.Parse(dataElement.Attribute("Keyframes").Value)); IEnumerable<XElement> frames = dataElement.Descendants("Frame"); Player newFrame; foreach (XElement frame in frames) { newFrame = new Player(); foreach (XElement joint in frame.Descendants("JointData")){ JointAngles jangles = KinectMotion.parseJoint(joint); XElement nameNode = joint.Descendants("Name").ToList<XElement>()[0]; switch (nameNode.Value){ case "Head": jangles.name = "Head"; newFrame.head = jangles; break; case "Neck": jangles.name = "Neck"; newFrame.neck = jangles; break; case "Spine": jangles.name = "Spine"; newFrame.spine = jangles; break; case "Left Shoulder": jangles.name = "Left Shoulder"; newFrame.lShoulder = jangles; break; case "Right Shoulder": jangles.name = "Right Shoulder"; newFrame.rShoulder = jangles; break; case "Left Elbow": jangles.name = "Left Elbow"; newFrame.lElbow = jangles; break; case "Right Elbow": jangles.name = "Right Elbow"; newFrame.rElbow = jangles; break; case "Right Hand": jangles.name = "Right Hand"; newFrame.rHand = jangles; break; case "Left Hand": jangles.name = "Left Hand"; newFrame.lHand = jangles; break; case "Right Hip": jangles.name = "Right Hip"; newFrame.rHip = jangles; break; case "Left Hip": jangles.name = "Left Hip"; newFrame.lHip = jangles; break; case "Center Hip": jangles.name = "Center Hip"; newFrame.cHip = jangles; break; case "Left Knee": jangles.name = "Left Knee"; newFrame.lKnee = jangles; break; case "Right Knee": jangles.name = "Right Knee"; newFrame.rKnee = jangles; break; case "Pelvis": jangles.name = "Pelvis"; newFrame.pelvis = jangles; break; case "Right Ankle": jangles.name = "Right Ankle"; newFrame.rAnkle = jangles; break; case "Left Ankle": jangles.name = "Left Ankle"; newFrame.lAnkle = jangles; break; } } //have to copy to keep list references? motion.addKeyframe(newFrame.copyPlayer()); } return motion; }