// 手の検出終了 void hands_HandDestroy(object sender, HandDestroyEventArgs e) { // 1.1.0.41 ではHandGenerator.StopTrackingでHandDestroyイベントが // 呼び出されるようで再帰になってしまう。 // そのためトラッキング停止状態でない場合のみ、トラッキング停止をする if (handStates != HandStatus.NoTracking) { handStates = HandStatus.NoTracking; handPoints.Clear(); // トラッキングの停止 hands.StopTracking(e.UserID); } }
//called when data for any output pin is requested public void Evaluate(int SpreadMax) { if (FContext != null) { if (FDepthGenerator != null && FEnabledIn[0]) { FFov[0] = new Vector2D(FDepthGenerator.FieldOfView.HorizontalAngle, FDepthGenerator.FieldOfView.VerticalAngle); Update(); } if (FHandGenerator != null && FEnabledIn[0]) { FIsTrackedOut.SliceCount = FHandIdOut.SliceCount = FHandPositionOut.SliceCount = FStartPositionIn.SliceCount; //for every given StartPosition check if it is currently tracked lock (FHandTrackerLock) for (int i = 0; i < FStartPositionIn.SliceCount; i++) { if (FDoTrackStartPosition[i]) { //find userID in FTrackedStartPositions int userID = -1; foreach (var tracker in FTrackedStartPositions) { if (tracker.Value == FStartPositionIn[i]) { userID = tracker.Key; break; } } //if present return tracking info if (userID > -1) { FIsTrackedOut[i] = true; FHandIdOut[i] = userID; FHandPositionOut[i] = FTrackedHands[userID]; } //else start tracking else { FIsTrackedOut[i] = false; FHandIdOut[i] = -1; FHandPositionOut[i] = FStartPositionIn[i]; var p = new Point3D((float)(FStartPositionIn[i].x * 1000), (float)(FStartPositionIn[i].y * 1000), (float)(FStartPositionIn[i].z * 1000)); FHandGenerator.StartTracking(p); } } else { //find the userID corresponding to the StartPosition //and stop tracking it int userID = -1; foreach (var tracker in FTrackedStartPositions) { if (tracker.Value == FStartPositionIn[i]) { userID = tracker.Key; break; } } if (userID > -1) { FHandGenerator.StopTracking(userID); } FIsTrackedOut[i] = false; FHandIdOut[i] = -1; FHandPositionOut[i] = FStartPositionIn[i]; } } } else { FIsTrackedOut.SliceCount = FHandIdOut.SliceCount = FHandPositionOut.SliceCount = 0; } } }
//called when data for any output pin is requested public void Evaluate(int SpreadMax) { if (FContextChanged) { if (FContextIn.PluginIO.IsConnected) { if (FContextIn[0] != null) { try { // Create and Hands generator FHandGenerator = new HandsGenerator(FContextIn[0]); FHandGenerator.HandCreate += FHands_HandCreate; FHandGenerator.HandDestroy += FHands_HandDestroy; FHandGenerator.HandUpdate += FHands_HandUpdate; FHandGenerator.StartGenerating(); FContextChanged = false; } catch (Exception ex) { FLogger.Log(ex); } } } else { CleanUp(); FContextChanged = false; } } if (FHandGenerator != null) { if (FDoTrackStartPosition.IsChanged) { bool enable = false; for (int i = 0; i < FDoTrackStartPosition.SliceCount; i++) { enable |= FDoTrackStartPosition[i]; } //enable if any slice is 1 if (enable) { FHandGenerator.StartGenerating(); } else { FHandGenerator.StopGenerating(); } } if (FHandGenerator.IsDataNew) { FIsTrackedOut.SliceCount = FHandIdOut.SliceCount = FHandPositionOut.SliceCount = FStartPositionIn.SliceCount; //for every given StartPosition check if it is currently tracked for (int i = 0; i < FStartPositionIn.SliceCount; i++) { if (FDoTrackStartPosition[i]) { //find userID in FTrackedStartPositions int userID = -1; foreach (var tracker in FTrackedStartPositions) { var p = new Point3D((float)(FStartPositionIn[i].x * 1000), (float)(FStartPositionIn[i].y * 1000), (float)(FStartPositionIn[i].z * 1000)); if (tracker.Value.Equals(p)) { userID = tracker.Key; break; } } //if present return tracking info if (userID > -1) { FIsTrackedOut[i] = true; FHandIdOut[i] = userID; var p = FTrackedHands[userID]; FHandPositionOut[i] = new Vector3D(p.X / 1000, p.Y / 1000, p.Z / 1000); } //else start tracking else { FIsTrackedOut[i] = false; FHandIdOut[i] = -1; FHandPositionOut[i] = FStartPositionIn[i]; var p = new Point3D((float)(FStartPositionIn[i].x * 1000), (float)(FStartPositionIn[i].y * 1000), (float)(FStartPositionIn[i].z * 1000)); FHandGenerator.StartTracking(p); } } else { //find the handID corresponding to the StartPosition //and stop tracking it int userID = -1; foreach (var tracker in FTrackedStartPositions) { var p = new Point3D((float)(FStartPositionIn[i].x * 1000), (float)(FStartPositionIn[i].y * 1000), (float)(FStartPositionIn[i].z * 1000)); if (tracker.Value.Equals(p)) { userID = tracker.Key; break; } } if (userID > -1) { FHandGenerator.StopTracking(userID); } FIsTrackedOut[i] = false; FHandIdOut[i] = -1; FHandPositionOut[i] = FStartPositionIn[i]; } } } } else { FIsTrackedOut.SliceCount = FHandIdOut.SliceCount = FHandPositionOut.SliceCount = 0; } }