Ejemplo n.º 1
0
        private void updateStats()
        {
            //Check all users
            var numUsers = Fubi.getNumUsers();
            var numHands = Fubi.getNumHands();

            if (numUsers == 0 && numHands == 0)
            {
                warnLabel.Visibility = Visibility.Visible;
            }
            else
            {
                warnLabel.Visibility = Visibility.Hidden;
            }

            int currentIndex = 0;

            for (uint i = 0; i < numUsers + 1; i++)
            {
                var id = (i == numUsers && Fubi.isPlayingSkeletonData()) ? FubiUtils.PlaybackUserID : Fubi.getUserID(i);
                if (id > 0)
                {
                    // Not existent yet
                    if (currentIndex >= statsTree.Items.Count)
                    {
                        statsTree.Items.Add(new TvUser());
                        ((TvUser)statsTree.Items[currentIndex]).IsExpanded = true;
                    }
                    // Wrong type, i.e. TvHand instead of TvUser
                    if (statsTree.Items[currentIndex].GetType() != typeof(TvUser))
                    {
                        statsTree.Items[currentIndex] = new TvUser();
                        ((TvUser)statsTree.Items[currentIndex]).IsExpanded = true;
                    }
                    var tUser = (TvUser)statsTree.Items[currentIndex];
                    tUser.id = id;

                    // Update user defined combinations
                    var  numRecs    = Fubi.getNumUserDefinedCombinationRecognizers();
                    uint actualRecs = 0;
                    for (uint pc = 0; pc < numRecs; ++pc)
                    {
                        var name = Fubi.getUserDefinedCombinationRecognizerName(pc);
                        while (actualRecs >= tUser.Recs.Count)
                        {
                            tUser.Recs.Add(new TvRec());
                        }

                        var rec = tUser.Recs[(int)actualRecs];
                        rec.id   = pc;
                        rec.name = name;
                        uint numStates;
                        bool isInterrupted, isInTransition;
                        rec.currState      = Fubi.getCurrentCombinationRecognitionState(name, id, out numStates, out isInterrupted, out isInTransition) + 1;
                        rec.numStates      = numStates;
                        rec.isInterrupted  = isInterrupted;
                        rec.isInTransition = isInTransition;
                        if (Recognitions.ContainsKey(id) && Recognitions[id].ContainsKey(name) && Fubi.getCurrentTime() - Recognitions[id][name] < 2.0)
                        {
                            rec.bgColor = "LightGreen";
                        }
                        else
                        {
                            rec.bgColor = Color.Transparent.Name;
                        }
                        if (Hints.ContainsKey(id) && Hints[id].ContainsKey(name))
                        {
                            rec.hint = Hints[id][name];
                        }
                        actualRecs++;
                    }

                    while (tUser.Recs.Count > actualRecs)
                    {
                        tUser.Recs.RemoveAt(tUser.Recs.Count - 1);
                    }

                    ++currentIndex;
                }
            }

            for (uint i = 0; i < numHands + 1; i++)
            {
                var id = (i == numHands && Fubi.isPlayingSkeletonData()) ? FubiUtils.PlaybackHandID : Fubi.getHandID(i);
                if (id > 0)
                {
                    if (currentIndex >= statsTree.Items.Count)
                    {
                        statsTree.Items.Add(new TvHand());
                        ((TvHand)statsTree.Items[currentIndex]).IsExpanded = true;
                    }
                    // Wrong type, i.e. TvUser instead of TvUHand
                    if (statsTree.Items[currentIndex].GetType() != typeof(TvHand))
                    {
                        statsTree.Items[currentIndex] = new TvHand();
                        ((TvHand)statsTree.Items[currentIndex]).IsExpanded = true;
                    }
                    var tHand = (TvHand)statsTree.Items[currentIndex];
                    tHand.id = id;

                    // Update combinations
                    var  numRecs    = Fubi.getNumUserDefinedCombinationRecognizers();
                    uint actualRecs = 0;
                    for (uint pc = 0; pc < numRecs; ++pc)
                    {
                        var name = Fubi.getUserDefinedCombinationRecognizerName(pc);
                        while (actualRecs >= tHand.Recs.Count)
                        {
                            tHand.Recs.Add(new TvRec());
                        }

                        var rec = tHand.Recs[(int)actualRecs];
                        rec.id   = pc;
                        rec.name = name;
                        uint numStates;
                        bool isInterrupted, isInTransition;
                        rec.currState      = Fubi.getCurrentCombinationRecognitionStateForHand(name, id, out numStates, out isInterrupted, out isInTransition) + 1;
                        rec.numStates      = numStates;
                        rec.isInterrupted  = isInterrupted;
                        rec.isInTransition = isInTransition;
                        if (HandRecognitions.ContainsKey(id) && HandRecognitions[id].ContainsKey(name) && Fubi.getCurrentTime() - HandRecognitions[id][name] < 2.0)
                        {
                            rec.bgColor = "LightGreen";
                        }
                        else
                        {
                            rec.bgColor = Color.Transparent.Name;
                        }
                        if (HandHints.ContainsKey(id) && HandHints[id].ContainsKey(name))
                        {
                            rec.hint = HandHints[id][name];
                        }

                        actualRecs++;
                    }

                    while (tHand.Recs.Count > actualRecs)
                    {
                        tHand.Recs.RemoveAt(tHand.Recs.Count - 1);
                    }

                    ++currentIndex;
                }
            }

            while (statsTree.Items.Count > currentIndex)
            {
                statsTree.Items.RemoveAt(statsTree.Items.Count - 1);
            }
        }