private void uncheckJointBox(FubiUtils.SkeletonJoint joint)
        {
            var box = (CheckBox)FindName(UseHand ? FubiUtils.getHandJointName((FubiUtils.SkeletonHandJoint)joint)  : FubiUtils.getJointName(joint));

            if (box != null)
            {
                box.Background = Brushes.White;
                box.IsChecked  = false;
            }
        }
        public XMLGenRecognizerOptionsWindow(XMLGenerator.RecognizerType type)
        {
            HideInsteadOfClosing = true;
            InitializeComponent();

            measuringUnit.Items.Add("millimeter");             // No actual body measurement
            measuringUnit.SelectedIndex = 0;
            foreach (FubiUtils.BodyMeasurement measure in Enum.GetValues(typeof(FubiUtils.BodyMeasurement)))
            {
                if (measure != FubiUtils.BodyMeasurement.NUM_MEASUREMENTS)
                {
                    measuringUnit.Items.Add(FubiUtils.getBodyMeasureName(measure));
                }
            }

            foreach (var measureName in Enum.GetNames(typeof(FubiUtils.DistanceMeasure)))
            {
                distanceMeasure.Items.Add(measureName);
            }
            distanceMeasure.SelectedIndex = (int)FubiUtils.DistanceMeasure.Euclidean;


            foreach (var typeName in XMLGenerator.ToleranceTypeString)
            {
                toleranceXType.Items.Add(typeName);
                toleranceYType.Items.Add(typeName);
                toleranceZType.Items.Add(typeName);
                toleranceDistType.Items.Add(typeName);
                toleranceSpeedType.Items.Add(typeName);
                toleranceFingerCountType.Items.Add(typeName);
            }
            toleranceXType.SelectedIndex           = (int)XMLGenerator.ToleranceType.PlusMinus;
            toleranceYType.SelectedIndex           = (int)XMLGenerator.ToleranceType.PlusMinus;
            toleranceZType.SelectedIndex           = (int)XMLGenerator.ToleranceType.PlusMinus;
            toleranceDistType.SelectedIndex        = (int)XMLGenerator.ToleranceType.PlusMinus;
            toleranceSpeedType.SelectedIndex       = (int)XMLGenerator.ToleranceType.PlusMinus;
            toleranceFingerCountType.SelectedIndex = (int)XMLGenerator.ToleranceType.PlusMinus;

            Type = type;
        }
 public void getOptions(ref XMLGenerator.RecognizerOptions options)
 {
     options.SelectedJoints     = SelectedJoints;
     options.ToleranceX         = toleranceX.Value;
     options.ToleranceY         = toleranceY.Value;
     options.ToleranceZ         = toleranceZ.Value;
     options.ToleranceDist      = toleranceDist.Value;
     options.ToleranceSpeed     = speed.Value;
     options.ToleranceXType     = toleranceXType.SelectedItem.ToString();
     options.ToleranceYType     = toleranceYType.SelectedItem.ToString();
     options.ToleranceZType     = toleranceZType.SelectedItem.ToString();
     options.ToleranceDistType  = toleranceDistType.SelectedItem.ToString();
     options.ToleranceSpeedType = toleranceSpeedType.SelectedItem.ToString();
     options.MaxAngleDifference = maxAngle.Value;
     options.ToleranceCountType = toleranceFingerCountType.SelectedItem.ToString();
     options.ToleranceCount     = (uint)fingerCount.Value;
     options.MedianWindowSize   = (uint)medianWindow.Value;
     options.Local           = localTrans.IsChecked == true;
     options.Filtered        = filtered.IsChecked == true;
     options.MeasuringUnit   = FubiUtils.getBodyMeasureID(measuringUnit.SelectedValue.ToString());
     options.MaxDistance     = maxDistance.Value;
     options.DistanceMeasure = (FubiUtils.DistanceMeasure)Enum.Parse(typeof(FubiUtils.DistanceMeasure), distanceMeasure.SelectedItem.ToString());
     options.IgnoreAxes      = 0;
     if (xActive.IsChecked == false)
     {
         options.IgnoreAxes |= (uint)FubiUtils.CoordinateAxis.X;
     }
     if (yActive.IsChecked == false)
     {
         options.IgnoreAxes |= (uint)FubiUtils.CoordinateAxis.Y;
     }
     if (zActive.IsChecked == false)
     {
         options.IgnoreAxes |= (uint)FubiUtils.CoordinateAxis.Z;
     }
     options.UseOrientations = useOrientations.IsChecked == true;
     options.AspectInvariant = aspectInvariant.IsChecked == true;
 }
        protected override void generateXML()
        {
            if (Options.Local)
            {
                appendStringAttribute(RecognizerNode, "useLocalPositions", "true");
            }
            if (Options.Filtered)
            {
                appendStringAttribute(RecognizerNode, "useFilteredData", "true");
            }
            if (Options.MeasuringUnit != FubiUtils.BodyMeasurement.NUM_MEASUREMENTS)
            {
                appendStringAttribute(RecognizerNode, "measuringUnit", FubiUtils.getBodyMeasureName(Options.MeasuringUnit));
            }

            var jointNode = Doc.CreateElement(UseHand ? "HandJoints" : "Joints", NamespaceUri);

            appendStringAttribute(jointNode, "main", getJointName(Options.SelectedJoints[0].Main));
            if (Options.SelectedJoints[0].Relative != FubiUtils.SkeletonJoint.NUM_JOINTS)
            {
                appendStringAttribute(jointNode, "relative", getJointName(Options.SelectedJoints[0].Relative));
            }
            RecognizerNode.AppendChild(jointNode);

            Vector3D direction = AvgValue;
            double   length    = AvgValue.Length;

            if (length > Double.Epsilon)
            {
                direction.Normalize();
            }
            else // No valid direction recorded, so we arbitrarily chose up direction
            {
                direction = new Vector3D(0, 1, 0);
            }
            var directionNode = Doc.CreateElement("Direction", NamespaceUri);

            appendNumericAttribute(directionNode, "x", direction.X, 3);
            appendNumericAttribute(directionNode, "y", direction.Y, 3);
            appendNumericAttribute(directionNode, "z", direction.Z, 3);
            if (Options.MaxAngleDifference >= 0)
            {
                appendNumericAttribute(directionNode, "maxAngleDifference", Options.MaxAngleDifference, 3);
            }
            RecognizerNode.AppendChild(directionNode);

            if (Options.ToleranceDist >= 0)
            {
                if (Options.MeasuringUnit != FubiUtils.BodyMeasurement.NUM_MEASUREMENTS)
                {
                    if (m_measureDist > 0)
                    {
                        AvgValue.X /= m_measureDist;
                        AvgValue.Y /= m_measureDist;
                        AvgValue.Z /= m_measureDist;
                        length      = AvgValue.Length;
                    }
                }
                var lengthNode = Doc.CreateElement("Length", NamespaceUri);
                if (length - Options.ToleranceDist > 0 && Options.ToleranceDistType != XMLGenerator.ToleranceTypeString[(int)XMLGenerator.ToleranceType.Lesser])
                {
                    appendNumericAttribute(lengthNode, "min", length - Options.ToleranceDist, 3);
                }
                if (Options.ToleranceDistType != XMLGenerator.ToleranceTypeString[(int)XMLGenerator.ToleranceType.Greater])
                {
                    appendNumericAttribute(lengthNode, "max", length + Options.ToleranceDist, 3);
                }
                if (lengthNode.HasAttributes)
                {
                    RecognizerNode.AppendChild(lengthNode);
                }
            }
            if (Options.ToleranceSpeed >= 0)
            {
                var speedNode = Doc.CreateElement("Speed", NamespaceUri);
                if (m_speed - Options.ToleranceSpeed > 0 && Options.ToleranceSpeedType != XMLGenerator.ToleranceTypeString[(int)XMLGenerator.ToleranceType.Lesser])
                {
                    appendNumericAttribute(speedNode, "min", m_speed - Options.ToleranceSpeed, 3);
                }
                if (Options.ToleranceSpeedType != XMLGenerator.ToleranceTypeString[(int)XMLGenerator.ToleranceType.Greater])
                {
                    appendNumericAttribute(speedNode, "max", m_speed + Options.ToleranceSpeed, 3);
                }
                if (speedNode.HasAttributes)
                {
                    RecognizerNode.AppendChild(speedNode);
                }
            }
        }
 protected string getJointName(FubiUtils.SkeletonJoint jointID)
 {
     return(UseHand ? FubiUtils.getHandJointName((FubiUtils.SkeletonHandJoint)jointID) : FubiUtils.getJointName(jointID));
 }
Exemplo n.º 6
0
        protected override void generateXML()
        {
            if (Options.Filtered)
            {
                appendStringAttribute(RecognizerNode, "useFilteredData", "true");
            }

            XmlElement maxNode, minNode;

            if (Type == XMLGenerator.RecognizerType.JointRelation)
            {
                if (Options.MeasuringUnit != FubiUtils.BodyMeasurement.NUM_MEASUREMENTS)
                {
                    appendStringAttribute(RecognizerNode, "measuringUnit", FubiUtils.getBodyMeasureName(Options.MeasuringUnit));
                }
                if (Options.Local)
                {
                    appendStringAttribute(RecognizerNode, "useLocalPositions", "true");
                }
                var jointNode = Doc.CreateElement(UseHand ? "HandJoints" : "Joints", NamespaceUri);
                appendStringAttribute(jointNode, "main", getJointName(Options.SelectedJoints[0].Main));
                if (Options.SelectedJoints[0].Relative != FubiUtils.SkeletonJoint.NUM_JOINTS)
                {
                    appendStringAttribute(jointNode, "relative", getJointName(Options.SelectedJoints[0].Relative));
                }
                RecognizerNode.AppendChild(jointNode);
                maxNode = Doc.CreateElement("MaxValues", NamespaceUri);
                minNode = Doc.CreateElement("MinValues", NamespaceUri);
            }
            else
            {
                if (!Options.Local)
                {
                    appendStringAttribute(RecognizerNode, "useLocalOrientations", "false");
                }
                var jointNode = Doc.CreateElement(UseHand ? "HandJoint" : "Joint", NamespaceUri);
                appendStringAttribute(jointNode, "name", getJointName(Options.SelectedJoints[0].Main));
                RecognizerNode.AppendChild(jointNode);

                if (Options.MaxAngleDifference >= 0)
                {
                    var orientationNode = Doc.CreateElement("Orientation", NamespaceUri);
                    appendNumericAttribute(orientationNode, "x", AvgValue.X);
                    appendNumericAttribute(orientationNode, "y", AvgValue.Y);
                    appendNumericAttribute(orientationNode, "z", AvgValue.Z);
                    appendNumericAttribute(orientationNode, "maxAngleDifference", Options.MaxAngleDifference);
                    RecognizerNode.AppendChild(orientationNode);
                    return;
                }
                maxNode = Doc.CreateElement("MaxDegrees", NamespaceUri);
                minNode = Doc.CreateElement("MinDegrees", NamespaceUri);
            }
            if (Options.ToleranceX >= 0)
            {
                if (Options.ToleranceXType != XMLGenerator.ToleranceTypeString[(int)XMLGenerator.ToleranceType.Greater])
                {
                    appendNumericAttribute(maxNode, "x", AvgValue.X + Options.ToleranceX);
                }
                if (Options.ToleranceXType != XMLGenerator.ToleranceTypeString[(int)XMLGenerator.ToleranceType.Lesser])
                {
                    appendNumericAttribute(minNode, "x", AvgValue.X - Options.ToleranceX);
                }
            }
            if (Options.ToleranceY >= 0)
            {
                if (Options.ToleranceYType != XMLGenerator.ToleranceTypeString[(int)XMLGenerator.ToleranceType.Greater])
                {
                    appendNumericAttribute(maxNode, "y", AvgValue.Y + Options.ToleranceY);
                }
                if (Options.ToleranceYType != XMLGenerator.ToleranceTypeString[(int)XMLGenerator.ToleranceType.Lesser])
                {
                    appendNumericAttribute(minNode, "y", AvgValue.Y - Options.ToleranceY);
                }
            }
            if (Options.ToleranceZ >= 0)
            {
                if (Options.ToleranceZType != XMLGenerator.ToleranceTypeString[(int)XMLGenerator.ToleranceType.Greater])
                {
                    appendNumericAttribute(maxNode, "z", AvgValue.Z + Options.ToleranceZ);
                }
                if (Options.ToleranceZType != XMLGenerator.ToleranceTypeString[(int)XMLGenerator.ToleranceType.Lesser])
                {
                    appendNumericAttribute(minNode, "z", AvgValue.Z - Options.ToleranceZ);
                }
            }
            if (Type == XMLGenerator.RecognizerType.JointRelation && Options.ToleranceDist >= 0)
            {
                var dist = AvgValue.Length;
                if (Options.ToleranceDistType != XMLGenerator.ToleranceTypeString[(int)XMLGenerator.ToleranceType.Greater])
                {
                    appendNumericAttribute(maxNode, "dist", dist + Options.ToleranceDist);
                }
                if (Options.ToleranceDistType != XMLGenerator.ToleranceTypeString[(int)XMLGenerator.ToleranceType.Lesser])
                {
                    var minDist = dist - Options.ToleranceDist;
                    if (minDist > 0)
                    {
                        appendNumericAttribute(minNode, "dist", minDist);
                    }
                }
            }
            if (maxNode.HasAttributes)
            {
                RecognizerNode.AppendChild(maxNode);
            }
            if (minNode.HasAttributes)
            {
                RecognizerNode.AppendChild(minNode);
            }
        }
 private void jointSelectionChanged(object sender, RoutedEventArgs e)
 {
     if (IsLoaded && sender.GetType() == typeof(CheckBox))
     {
         var box   = (CheckBox)sender;
         var joint = FubiUtils.getJointID(box.Name);
         if (UseHand)
         {
             var handJoint = FubiUtils.getHandJointID(box.Name);
             if (handJoint != FubiUtils.SkeletonHandJoint.NUM_JOINTS)
             {
                 joint = (FubiUtils.SkeletonJoint)handJoint;
             }
         }
         if (joint != FubiUtils.SkeletonJoint.NUM_JOINTS)
         {
             if (box.IsChecked == true)
             {
                 if (SelectedJoints.Count == 0 ||
                     (Type == XMLGenerator.RecognizerType.TemplateRecording && SelectedJoints[SelectedJoints.Count - 1].Relative != FubiUtils.SkeletonJoint.NUM_JOINTS))
                 {
                     if (m_type == XMLGenerator.RecognizerType.FingerCount &&
                         ((!m_useHand && joint != FubiUtils.SkeletonJoint.LEFT_HAND && joint != FubiUtils.SkeletonJoint.RIGHT_HAND) ||
                          (m_useHand && joint != (FubiUtils.SkeletonJoint)FubiUtils.SkeletonHandJoint.PALM)))
                     {
                         box.IsChecked = false;
                         showToolTipOnElement(box, "You can only select the left/right hand or the palm for a " + Type.ToString());
                     }
                     else
                     {
                         SelectedJoints.Add(new XMLGenerator.RelativeJoint(joint));
                         box.Background = Brushes.LightGreen;
                     }
                 }
                 else if (SelectedJoints[SelectedJoints.Count - 1].Relative == FubiUtils.SkeletonJoint.NUM_JOINTS &&
                          ((SelectedJoints.Count == 1 && (Type == XMLGenerator.RecognizerType.JointRelation || Type == XMLGenerator.RecognizerType.LinearMovement)) ||
                           Type == XMLGenerator.RecognizerType.TemplateRecording))
                 {
                     SelectedJoints[SelectedJoints.Count - 1].Relative = joint;
                     box.Background = Brushes.Yellow;
                 }
                 else
                 {
                     box.IsChecked = false;
                     showToolTipOnElement(box, "You cannot select more joints for a " + Type.ToString());
                 }
             }
             else                     // box.IsChecked == false
             {
                 box.Background = Brushes.White;
                 if (SelectedJoints.Count == 1)
                 {
                     if (SelectedJoints[0].Main == joint)
                     {
                         if (SelectedJoints[0].Relative == FubiUtils.SkeletonJoint.NUM_JOINTS)
                         {
                             SelectedJoints.Clear();
                         }
                         else
                         {
                             SelectedJoints[0].Main     = SelectedJoints[0].Relative;
                             SelectedJoints[0].Relative = FubiUtils.SkeletonJoint.NUM_JOINTS;
                             var jointName = FubiUtils.getJointName(SelectedJoints[0].Main);
                             var otherBox  = (CheckBox)FindName(jointName);
                             if (otherBox != null)
                             {
                                 otherBox.Background = Brushes.LightGreen;
                             }
                         }
                     }
                     else if (SelectedJoints[0].Relative == joint)
                     {
                         SelectedJoints[0].Relative = FubiUtils.SkeletonJoint.NUM_JOINTS;
                     }
                 }
                 else                         // SelectedJoints.Count > 1
                 {
                     var relJoint = SelectedJoints.Find(j => j.Main == joint);
                     if (relJoint != null)
                     {
                         if (relJoint.Relative != FubiUtils.SkeletonJoint.NUM_JOINTS)
                         {
                             uncheckJointBox(relJoint.Relative);
                         }
                         SelectedJoints.Remove(relJoint);
                     }
                     relJoint = SelectedJoints.Find(j => j.Relative == joint);
                     if (relJoint != null)
                     {
                         relJoint.Relative = FubiUtils.SkeletonJoint.NUM_JOINTS;
                     }
                 }
             }
         }
         checkSelections();
     }
 }
        protected override void generateXML()
        {
            if (Options.Filtered)
            {
                appendStringAttribute(RecognizerNode, "useFilteredData", "true");
            }
            if (Options.MeasuringUnit != FubiUtils.BodyMeasurement.NUM_MEASUREMENTS)
            {
                appendStringAttribute(RecognizerNode, "measuringUnit", FubiUtils.getBodyMeasureName(Options.MeasuringUnit));
            }
            if (Options.Local)
            {
                appendStringAttribute(RecognizerNode, "useLocalTransformations", "true");
            }

            if (Options.MaxAngleDifference >= 0)
            {
                appendNumericAttribute(RecognizerNode, "maxRotation", Options.MaxAngleDifference, 3);
            }
            appendNumericAttribute(RecognizerNode, "maxDistance", Options.MaxDistance, 3);
            appendStringAttribute(RecognizerNode, "distanceMeasure", Options.DistanceMeasure.ToString().ToLower());
            if (Options.UseOrientations)
            {
                appendStringAttribute(RecognizerNode, "useOrientations", "true");
            }
            if (Options.AspectInvariant)
            {
                appendStringAttribute(RecognizerNode, "aspectInvariant", "true");
            }

            foreach (XMLGenerator.RelativeJoint j in Options.SelectedJoints)
            {
                var jointNode = Doc.CreateElement(UseHand ? "HandJoints" : "Joints", NamespaceUri);
                appendStringAttribute(jointNode, "main", getJointName(j.Main));
                if (j.Relative != FubiUtils.SkeletonJoint.NUM_JOINTS)
                {
                    appendStringAttribute(jointNode, "relative", getJointName(j.Relative));
                }
                RecognizerNode.AppendChild(jointNode);
            }

            var trainingNode = Doc.CreateElement("TrainingData", NamespaceUri);

            appendStringAttribute(trainingNode, "file", Options.PlaybackFile);
            appendNumericAttribute(trainingNode, "start", Options.PlaybackStart, 0);
            appendNumericAttribute(trainingNode, "end", Options.PlaybackEnd, 0);
            RecognizerNode.AppendChild(trainingNode);

            if (Options.IgnoreAxes != 0)
            {
                var ignoreAxesNode = Doc.CreateElement("IgnoreAxes", NamespaceUri);
                if ((Options.IgnoreAxes & (uint)FubiUtils.CoordinateAxis.X) != 0)
                {
                    appendStringAttribute(ignoreAxesNode, "x", "true");
                }
                if ((Options.IgnoreAxes & (uint)FubiUtils.CoordinateAxis.Y) != 0)
                {
                    appendStringAttribute(ignoreAxesNode, "y", "true");
                }
                if ((Options.IgnoreAxes & (uint)FubiUtils.CoordinateAxis.Z) != 0)
                {
                    appendStringAttribute(ignoreAxesNode, "z", "true");
                }
                RecognizerNode.AppendChild(ignoreAxesNode);
            }
        }