Example #1
0
        /// <summary>
        /// Converts the default confidence result list to a list where gestures have been linked.
        /// </summary>
        /// <param name="aResultList">A list of unlinked gesture results</param>
        /// <returns>A dictionairy that uses PseudoGesture names to search for their confidence values</returns>
        public Dictionary <string, float> getLinkedDiscreteResults(IReadOnlyDictionary <Gesture, DiscreteGestureResult> aResultList)
        {
            Dictionary <string, float> returnDict = null;

            if (aResultList != null)
            {
                returnDict = new Dictionary <string, float>();
                GestureLink tempLink = null;
                bool        ignored  = false;
                //check every gesture in the resultList
                foreach (KeyValuePair <Gesture, DiscreteGestureResult> entry in aResultList)
                {
                    ignored  = false;
                    tempLink = null;
                    if (conf != null)
                    {
                        //check if the current gesture should be ignored
                        foreach (string s in conf.ignoreList)
                        {
                            if (s.Equals(entry.Key.Name))
                            {
                                ignored = true;
                                break;
                            }
                        }

                        //check if the current gesture from VGBsource is included in a link from the config
                        if (!ignored)
                        {
                            tempLink = conf.findGestureInLink(entry.Key.Name);//null if not included
                        }
                    }

                    //was it included?
                    if (tempLink != null)
                    {
                        //if the dictionairy doesn't contain a gesture that represents a link, add a gesture to work as the link
                        if (!returnDict.ContainsKey(tempLink.commonName))
                        {
                            //In case of a link that is available, we only want to know the confidence of the gesture with highest confidence
                            //so in order to do that, we need to find out which of the gestures in a link have the highest confidence
                            DiscreteGestureResult gestResult = null;
                            float highestConfidence          = 0;
                            //read all gesturenames from the linked gestures list
                            foreach (string gestureName in tempLink.linkedGesturesList)
                            {
                                //search trough the result dictionairy to find the correct gesture confidence
                                foreach (KeyValuePair <Gesture, DiscreteGestureResult> gesture in aResultList)
                                {
                                    //find the gesture that has the same name as the current gesture we got from the link list
                                    if (gesture.Key.Name.Equals(gestureName))
                                    {
                                        //read out the confidence this gesture has
                                        aResultList.TryGetValue(gesture.Key, out gestResult);
                                        //check if this gesture has the highest confidence
                                        if (highestConfidence < gestResult.Confidence)
                                        {
                                            //if so set this confidence as the final confidence
                                            highestConfidence = gestResult.Confidence;
                                        }
                                        //we found the gesture we wanted, no need to search trough the dictionary anymore
                                        break;
                                    }
                                }
                            }
                            returnDict.Add(tempLink.commonName, highestConfidence);
                        }
                    }// END OF --- templink != null
                    else
                    {
                        if (!ignored)
                        {
                            //if the gesture wasn't included in a link, we can add it directly to the returnDict
                            DiscreteGestureResult gestResult = null;
                            aResultList.TryGetValue(entry.Key, out gestResult);
                            returnDict.Add(entry.Key.Name, gestResult.Confidence);
                        }
                    }
                }
            }
            return(returnDict);
        }
Example #2
0
        /// <summary>
        /// Reads from the configuration file and returns a list of gestures that are linked together
        /// </summary>
        /// <param name="aVgbSource">A VGB frame source which stores references to gestures in a database</param>
        /// <returns>A list of PseudoGestures that represent Linked Gestures</returns>
        public List <PseudoGesture> linkGestures(VisualGestureBuilderFrameSource aVgbSource)
        {
            List <PseudoGesture> returnList = new List <PseudoGesture>();
            GestureLink          tempLink   = null;
            bool ignored = false;

            foreach (Gesture gest in aVgbSource.Gestures)
            {
                ignored  = false;
                tempLink = null;
                if (conf != null)
                {
                    //check if the current gesture should be ignored
                    foreach (string s in conf.ignoreList)
                    {
                        if (s.Equals(gest.Name))
                        {
                            ignored = true;
                            break;
                        }
                    }

                    //check if the current gesture from VGBsource is included in a link from the config
                    if (!ignored)
                    {
                        tempLink = conf.findGestureInLink(gest.Name);//null if not included
                    }
                }
                //was it included?
                if (tempLink != null)
                {
                    string gestureType = "Discrete";
                    if (gest.GestureType == GestureType.Continuous)
                    {
                        gestureType = "Continuous";
                    }
                    if (tempLink.gestureType != null)
                    {
                        //Make sure that the discrete gestures get added to discrete links, and continuous with continuous
                        if (gestureType.Equals(tempLink.gestureType, StringComparison.OrdinalIgnoreCase))
                        {
                            //check if any elements are added to the returnList incase of when the current link was already added
                            if (returnList.Count > 0)
                            {
                                //if the list doesn't contain a gesture that represents a link, add a gesture to work as the link
                                if (!returnList.Exists(x => x.gestureName.Equals(tempLink.commonName)))
                                {
                                    returnList.Add(new PseudoGesture(tempLink.commonName, gest.GestureType));
                                }
                            }
                            else
                            {
                                //if the returnList is empty, we don't have to check if the link already has been added as gesture
                                returnList.Add(new PseudoGesture(tempLink.commonName, gest.GestureType));
                            }
                        }
                        else
                        {
                            System.Console.WriteLine("Configuration error, a discrete gesture was added to a continuous link or vice versa.");
                            evHandler.raiseMessageEvent(1, "Configuration error, a discrete gesture was added to a continuous link or vice versa.");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Configuration error, a link didn't have a defined gestureType.");
                        evHandler.raiseMessageEvent(1, "Configuration error, a link didn't have a defined gestureType.");
                    }
                }
                else
                {
                    //if the gesture wasn't included in a link, we can add it directly to the returnlist
                    if (!ignored)
                    {
                        returnList.Add(new PseudoGesture(gest.Name, gest.GestureType));
                    }
                }
            }
            return(returnList);
        }