private uint getPlaybackOrClosestHandID() { if (Fubi.isPlayingSkeletonData()) { return(FubiUtils.PlaybackHandID); } return(Fubi.getClosestHandID()); }
public void generateXML(MainWindow w, CancellationToken ct) { // Important for corrrectly converting numbers to strings Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); RecognizerXMLGenerator recognizerGen = null; switch (Type) { case RecognizerType.JointRelation: case RecognizerType.JointOrientation: recognizerGen = new StaticPostureXmlGenerator(RecognizerName, w, RecOptions, Type); break; case RecognizerType.LinearMovement: recognizerGen = new LinearMovementXmlGenerator(RecognizerName, w, RecOptions, Type); break; case RecognizerType.AngularMovement: recognizerGen = new AngularMovementXmlGenerator(RecognizerName, w, RecOptions, Type); break; case RecognizerType.FingerCount: recognizerGen = new FingerCountXmlGenerator(RecognizerName, w, RecOptions, Type); break; case RecognizerType.TemplateRecording: recognizerGen = new TemplateRecordingXMLGenerator(RecognizerName, w, RecOptions); break; case RecognizerType.Combination: recognizerGen = new CombinationXMLGenerator(RecognizerName, w, CombOptions); break; } if (recognizerGen != null) { recognizerGen.UseHand = UseHand; recognizerGen.trainValues(Start, Duration, ct); if (!ct.IsCancellationRequested) { var trainedFromPlaybackUser = Fubi.isPlayingSkeletonData() || Type == RecognizerType.TemplateRecording || StartedWithPlayback; if (recognizerGen.generateAndSaveXML() && trainedFromPlaybackUser && !String.IsNullOrEmpty(RecOptions.PlaybackFile)) { // Save start and end markers of the file in case of success var file = new XmlDocument(); file.Load(RecOptions.PlaybackFile); var currentFubiRecNode = file.GetElementsByTagName("FubiRecording")[0] as XmlElement; if (currentFubiRecNode != null) { currentFubiRecNode.SetAttribute("startMarker", RecOptions.PlaybackStart.ToString()); currentFubiRecNode.SetAttribute("endMarker", RecOptions.PlaybackEnd.ToString()); file.Save(RecOptions.PlaybackFile); } } } } w.Dispatcher.BeginInvoke((Action)(() => { w.menuTabCtrl.IsEnabled = true; })); }
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); } }