コード例 #1
0
        private void addBtn_Click(object sender, RoutedEventArgs e)
        {
            // check if any of the checkbox is clicked
            List<JointType> checkedJoints = new List<JointType>();
            for (int i = 0; i < joint_checkbox_collection.Count; i++)
            {
                CheckBox cur_checkbox = joint_checkbox_collection[i] as CheckBox;
                if (cur_checkbox.IsChecked.Value)
                    checkedJoints.Add(checkbox_name_jointtype_mapping[cur_checkbox.Name]);
            }

            if (checkedJoints.Count == 0)
            {
                MessageBox.Show("No joint selected");
                return;
            }
            else if (checkedJoints.Count == 1)
            {
                MeasurementUnit unit = new MeasurementUnit();
                unit.ifSingleJoint = true;
                unit.singleJoint = checkedJoints[0];
                measureUnits.Add(unit);

                // display on list
                measureUnitList.Items.Add(unit.singleJoint.ToString());
            }
            else if (checkedJoints.Count == 2)
            {
                MeasurementUnit unit = new MeasurementUnit();
                unit.ifSingleJoint = false;
                unit.boneJoint1 = checkedJoints[0];
                unit.boneJoint2 = checkedJoints[1];

                // check if plane is selected
                if (XYRadioBtn.IsChecked.Value)
                    unit.plane = PlaneName.XYPlane;
                else if (YZRadioBtn.IsChecked.Value)
                    unit.plane = PlaneName.YZPlane;
                else if (XZRadioBtn.IsChecked.Value)
                    unit.plane = PlaneName.XZPlane;
                else
                {
                    MessageBox.Show("Select plane first");
                    return;
                }

                // add to units
                measureUnits.Add(unit);

                // add to display list
                measureUnitList.Items.Add(
                    unit.boneJoint1.ToString() + " " +
                    unit.boneJoint2.ToString() + " " +
                    unit.plane.ToString());
            }
            else
                MessageBox.Show("Invalid selection. Only one or two joints are supported.");
        }
コード例 #2
0
        // compute angle in measure unit
        private void ComputeJointAngle(Skeleton ske, MeasurementUnit unit, ref JointStatus status)
        {
            if (ske == null)
            {
                return;
            }

            if (unit.ifSingleJoint)
            {
                // compute bone-bone angle centered in single joint
                if (jointNeighbors.ContainsKey(unit.singleJoint) &&
                    jointNeighbors[unit.singleJoint].Count == 2)
                {
                    SkeletonPoint cur_joint_pos       = ske.Joints[unit.singleJoint].Position;
                    JointType     neighbor_jointtype1 = jointNeighbors[unit.singleJoint][0];
                    JointType     neighbor_jointtype2 = jointNeighbors[unit.singleJoint][1];
                    SkeletonPoint neighbor_joint_pos1 = ske.Joints[neighbor_jointtype1].Position;
                    SkeletonPoint neighbor_joint_pos2 = ske.Joints[neighbor_jointtype2].Position;

                    // compute bone-bone angle
                    Point3D vec1 = new Point3D(neighbor_joint_pos1.X - cur_joint_pos.X,
                                               neighbor_joint_pos1.Y - cur_joint_pos.Y,
                                               neighbor_joint_pos1.Z - cur_joint_pos.Z);
                    Point3D vec2 = new Point3D(neighbor_joint_pos2.X - cur_joint_pos.X,
                                               neighbor_joint_pos2.Y - cur_joint_pos.Y,
                                               neighbor_joint_pos2.Z - cur_joint_pos.Z);

                    status.angle = Tools.ComputeAngle(vec1, vec2);
                }
            }
            else
            {
                // compute bone angle
                SkeletonPoint cur_joint_pos       = ske.Joints[unit.boneJoint1].Position;
                SkeletonPoint neighbor_joint_pos1 = ske.Joints[unit.boneJoint2].Position;

                if (!status.planeAngles.ContainsKey(unit.boneJoint2))
                {
                    Dictionary <PlaneName, double> plane_temp = new Dictionary <PlaneName, double>();
                    plane_temp.Add(PlaneName.XYPlane, 0);
                    plane_temp.Add(PlaneName.YZPlane, 0);
                    plane_temp.Add(PlaneName.XZPlane, 0);
                    status.planeAngles.Add(unit.boneJoint2, plane_temp);
                }

                Point3D vec1 = new Point3D(neighbor_joint_pos1.X - cur_joint_pos.X,
                                           neighbor_joint_pos1.Y - cur_joint_pos.Y,
                                           neighbor_joint_pos1.Z - cur_joint_pos.Z);

                Point3D xyplane1 = new Point3D(vec1.X, vec1.Y, 0);  // projection of vec1 to xy plane
                status.planeAngles[unit.boneJoint2][PlaneName.XYPlane] = Tools.ComputeAngle(vec1, xyplane1);
                Point3D yzplane1 = new Point3D(0, vec1.Y, vec1.Z);
                status.planeAngles[unit.boneJoint2][PlaneName.YZPlane] = Tools.ComputeAngle(vec1, yzplane1);
                Point3D xzplane1 = new Point3D(vec1.X, 0, vec1.Z);
                status.planeAngles[unit.boneJoint2][PlaneName.XZPlane] = Tools.ComputeAngle(vec1, xzplane1);
            }
        }
コード例 #3
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            unit = new MeasurementUnit();

            // set name type mapping
            jointtype_mapping = new Dictionary<string, JointType>();
            jointtype_mapping.Add(Head.Name, JointType.Head);
            jointtype_mapping.Add(ShoulderCenter.Name, JointType.ShoulderCenter);
            jointtype_mapping.Add(ShoulderLeft.Name, JointType.ShoulderLeft);
            jointtype_mapping.Add(ShoulderRight.Name, JointType.ShoulderRight);
            jointtype_mapping.Add(HandLeft.Name, JointType.HandLeft);
            jointtype_mapping.Add(HandRight.Name, JointType.HandRight);
            jointtype_mapping.Add(WristLeft.Name, JointType.WristLeft);
            jointtype_mapping.Add(WristRight.Name, JointType.WristRight);
            jointtype_mapping.Add(ElbowLeft.Name, JointType.ElbowLeft);
            jointtype_mapping.Add(ElbowRight.Name, JointType.ElbowRight);
            jointtype_mapping.Add(Spine.Name, JointType.Spine);
            jointtype_mapping.Add(HipCenter.Name, JointType.HipCenter);
            jointtype_mapping.Add(HipLeft.Name, JointType.HipLeft);
            jointtype_mapping.Add(HipRight.Name, JointType.HipRight);
            jointtype_mapping.Add(KneeLeft.Name, JointType.KneeLeft);
            jointtype_mapping.Add(KneeRight.Name, JointType.KneeRight);
            jointtype_mapping.Add(AnkleLeft.Name, JointType.AnkleLeft);
            jointtype_mapping.Add(AnkleRight.Name, JointType.AnkleRight);
            jointtype_mapping.Add(FootLeft.Name, JointType.FootLeft);
            jointtype_mapping.Add(FootRight.Name, JointType.FootRight);

            planeButtons.Add(XY);
            planeButtons.Add(YZ);
            planeButtons.Add(XZ);
        }
コード例 #4
0
ファイル: MotionAssessor.cs プロジェクト: flyfj/KinectStudio
        // compute angle in measure unit
        private void ComputeJointAngle(Skeleton ske, MeasurementUnit unit, ref JointStatus status)
        {
            if (ske == null)
                return;

            if (unit.ifSingleJoint)
            {
                // compute bone-bone angle centered in single joint
                if (jointNeighbors.ContainsKey(unit.singleJoint) &&
                    jointNeighbors[unit.singleJoint].Count == 2)
                {
                    SkeletonPoint cur_joint_pos = ske.Joints[unit.singleJoint].Position;
                    JointType neighbor_jointtype1 = jointNeighbors[unit.singleJoint][0];
                    JointType neighbor_jointtype2 = jointNeighbors[unit.singleJoint][1];
                    SkeletonPoint neighbor_joint_pos1 = ske.Joints[neighbor_jointtype1].Position;
                    SkeletonPoint neighbor_joint_pos2 = ske.Joints[neighbor_jointtype2].Position;

                    // compute bone-bone angle
                    Point3D vec1 = new Point3D(neighbor_joint_pos1.X - cur_joint_pos.X,
                            neighbor_joint_pos1.Y - cur_joint_pos.Y,
                            neighbor_joint_pos1.Z - cur_joint_pos.Z);
                    Point3D vec2 = new Point3D(neighbor_joint_pos2.X - cur_joint_pos.X,
                                neighbor_joint_pos2.Y - cur_joint_pos.Y,
                                neighbor_joint_pos2.Z - cur_joint_pos.Z);

                    status.angle = Tools.ComputeAngle(vec1, vec2);
                }
            }
            else
            {
                // compute bone angle
                SkeletonPoint cur_joint_pos = ske.Joints[unit.boneJoint1].Position;
                SkeletonPoint neighbor_joint_pos1 = ske.Joints[unit.boneJoint2].Position;

                if (!status.planeAngles.ContainsKey(unit.boneJoint2))
                {
                    Dictionary<PlaneName, double> plane_temp = new Dictionary<PlaneName, double>();
                    plane_temp.Add(PlaneName.XYPlane, 0);
                    plane_temp.Add(PlaneName.YZPlane, 0);
                    plane_temp.Add(PlaneName.XZPlane, 0);
                    status.planeAngles.Add(unit.boneJoint2, plane_temp);
                }

                Point3D vec1 = new Point3D(neighbor_joint_pos1.X - cur_joint_pos.X,
                        neighbor_joint_pos1.Y - cur_joint_pos.Y,
                        neighbor_joint_pos1.Z - cur_joint_pos.Z);

                Point3D xyplane1 = new Point3D(vec1.X, vec1.Y, 0);  // projection of vec1 to xy plane
                status.planeAngles[unit.boneJoint2][PlaneName.XYPlane] = Tools.ComputeAngle(vec1, xyplane1);
                Point3D yzplane1 = new Point3D(0, vec1.Y, vec1.Z);
                status.planeAngles[unit.boneJoint2][PlaneName.YZPlane] = Tools.ComputeAngle(vec1, yzplane1);
                Point3D xzplane1 = new Point3D(vec1.X, 0, vec1.Z);
                status.planeAngles[unit.boneJoint2][PlaneName.XZPlane] = Tools.ComputeAngle(vec1, xzplane1);
            }
        }