Пример #1
0
 // キーイベント
 private void xnKeyDown(Keys key)
 {
     // ジェスチャーの変更
     if (key == Keys.G)
     {
         gesture.StopGenerating();
         gesture.RemoveGesture(gestures[gestureIndex]);
         ++gestureIndex;
         if (gestureIndex >= gestures.Length)
         {
             gestureIndex = 0;
         }
         gesture.AddGesture(gestures[gestureIndex]);
         gesture.StartGenerating();
     }
 }
Пример #2
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
                        {
                            FGestureGenerator = new GestureGenerator(FContextIn[0]);

                            FGestureGenerator.GestureRecognized += FGesture_GestureRecognized;
                            FGestureGenerator.GestureProgress   += FGesture_GestureProgress;

                            //Write all possible gestures to the Output Pin
                            var gestures = FGestureGenerator.EnumerateAllGestures();
                            EnumManager.UpdateEnum("OpenNIGestures", gestures[0], gestures);

                            FGestureGenerator.StartGenerating();

                            FContextChanged = false;
                        }
                        catch (Exception ex)
                        {
                            FLogger.Log(ex);
                        }
                    }
                }
                else
                {
                    CleanUp();
                    FContextChanged = false;
                }
            }

            if (FActiveGestureIn.IsChanged)
            {
                FUpdateGestures = true;
            }

            if (FGestureGenerator != null)
            {
                if (FEnabledIn.IsChanged)
                {
                    if (FEnabledIn[0])
                    {
                        FGestureGenerator.StartGenerating();
                    }
                    else
                    {
                        FGestureGenerator.StopGenerating();
                    }
                }

                if (FGestureGenerator.IsDataNew)
                {
                    //Check the Incomming gestures and try to add them to the Gesture generator
                    if (FUpdateGestures)
                    {
                        //first remove all active gestures
                        string[] ActiveGesture = FGestureGenerator.GetAllActiveGestures();
                        if (ActiveGesture.Length > 0)
                        {
                            foreach (string Gesture in ActiveGesture)
                            {
                                try
                                {
                                    FGestureGenerator.RemoveGesture(Gesture);
                                }
                                catch (StatusException ex)
                                {
                                    FLogger.Log(LogType.Error, String.Format("Cannot Remove Gesture: {0}", Gesture));
                                    FLogger.Log(LogType.Message, ex.Message);
                                }
                            }
                        }

                        //add all gestures to the Gesture Generator
                        foreach (var gesture in FActiveGestureIn)
                        {
                            try
                            {
                                FGestureGenerator.AddGesture(gesture.Name);
                            }
                            catch (StatusException ex)
                            {
                                FLogger.Log(LogType.Error, String.Format("Cannot Add Gesture: {0}", gesture));
                                FLogger.Log(LogType.Message, ex.Message);
                            }
                        }

                        FUpdateGestures = false;
                    }

                    // Handle the Output Pins
                    FGesturesRegOut.SliceCount     = FGestureRecognized.Count;
                    FGesturePositionOut.SliceCount = FGestureRecognized.Count;
                    int Slice = 0;

                    // Write the received Gestures with their endposition to the output
                    foreach (KeyValuePair <Vector3D, string> item in FGestureRecognized)
                    {
                        FGesturesRegOut[Slice]     = item.Value;
                        FGesturePositionOut[Slice] = item.Key / 1000;
                        Slice++;
                    }

                    FGestureRecognized.Clear();
                }
            }
            else
            {
                FGesturesRegOut.SliceCount     = 0;
                FGesturePositionOut.SliceCount = 0;
            }
        }