/// <summary> /// Converts a JointDictionary with 3D data to the corresponding one /// with 2D data. Note that the Z-Coordinate is left unchanged, though /// it has no meaning in the resulting 2D space and can be seen as 0. /// </summary> public JointDictionary Convert3Dto2D(JointDictionary source, DepthGenerator generator) { if (!source.Is3DData) return new JointDictionary(source); else { JointDictionary ret = new JointDictionary(false); foreach (SkeletonJoint joint in source.Keys) { SkeletonJointPosition pos = new SkeletonJointPosition(); pos.Confidence = source[joint].Confidence; pos.Position = generator.ConvertRealWorldToProjective(source[joint].Position); ret.Add(joint, pos); } return ret; } }
/// <summary> /// Loads all 3D joint positions for a specific user. /// </summary> /// <exception cref="ArgumentException">Thrown if the target dictionary /// does not contain 3d data.</exception> protected void GetJoints3D(SkeletonCapability source, int user, JointDictionary target) { if (!target.Is3DData) throw new ArgumentException("Trying to load 3d data to a non 3D JointDictionary."); for (int i = 0; i < JointDictionary.JointTranslationList.Count; i++) { GetJoint3D(source, user, JointDictionary.JointTranslationList[i].joint_type, target); } }
/// <summary> /// Loads the 3D data for a specific skeleton joint. /// </summary> private void GetJoint3D(SkeletonCapability source, int user, SkeletonJoint joint, JointDictionary target) { SkeletonJointPosition pos; if (joint == SkeletonJoint.Waist) { // Calculate the joint position as arithmetic mean of right // and left hip joints, as it is not possible to poll it // directly. pos = new SkeletonJointPosition(); SkeletonJointPosition posLeft = source.GetSkeletonJointPosition(user, SkeletonJoint.LeftHip); SkeletonJointPosition posRight = source.GetSkeletonJointPosition(user, SkeletonJoint.RightHip); if (posLeft.Position.Z == 0 || posRight.Position.Z == 0) { pos.Confidence = 0; pos.Position = new Point3D( (posLeft.Position.X + posRight.Position.X) / 2, (posLeft.Position.Y + posRight.Position.Y) / 2, 0); } else { pos.Confidence = Math.Min(posLeft.Confidence, posRight.Confidence); pos.Position = new Point3D( (posLeft.Position.X + posRight.Position.X) / 2, (posLeft.Position.Y + posRight.Position.Y) / 2, (posLeft.Position.Z + posRight.Position.Z) / 2); } } else { pos = source.GetSkeletonJointPosition(user, joint); if (pos.Position.Z == 0) { pos.Confidence = 0; } } target[joint] = pos; }
/// <summary> /// Converts a JointDictionary with 3D data to the corresponding one /// with 2D data. Note that the Z-Coordinate is left unchanged, though /// it has no meaning in the resulting 2D space and can be seen as 0. /// </summary> public JointDictionary Convert3Dto2D(JointDictionary source) { return base.Convert3Dto2D(source, depthGenerator); }