Exemplo n.º 1
0
        public MainViewModel(OpenGL gl, System.Windows.Controls.ScrollViewer scrollViewer, System.Windows.Controls.TextBox outputWindowTextBox,
                             GestureLibrary gestureLibraryControl, EditStaticGesture editStaticGestureControl, EditDynamicGesture editDynamicGestureControl,
                             RecognitionMonitor recognitionMonitorControl, Controller controller)
        {
            _gl                    = gl;
            _controller            = controller;
            _camera                = new Camera(_gl);
            _scrollViewer          = scrollViewer;
            _outputWindowTextBox   = outputWindowTextBox;
            _gestureLibraryControl = gestureLibraryControl;
            _gestureLibraryControl.SetMvm(this);
            _editStaticGestureControl = editStaticGestureControl;
            _editStaticGestureControl.SetMvm(this);
            _editDynamicGestureControl = editDynamicGestureControl;
            _editDynamicGestureControl.SetMvm(this);
            _sqliteProvider = new SQLiteProvider(Constants.SQLiteFileName);
            _config         = new LGR_Configuration(_sqliteProvider);
            _glHelper       = new SharpGLHelper(_gl, _config.BoneColors);

            UpdateStaticGestureLibrary();
            UpdateDynamicGestureLibrary();

            initMenuBar();

            // Needs to be initialized after UpdateGestureLibrary()
            _classifier = new StatisticalClassifier(StaticGestures, DynamicGestures);

            _recognitionMonitorControl    = recognitionMonitorControl;
            _recognitionMonitorControl.VM = new RecognitionMonitorViewModel(_classifier);

            FrameReceived += _recognitionMonitorControl.VM.OnFrameReceived;
        }
        public void AddGesture(View v)
        {
            if (mGesture != null)
            {
                TextView input = (TextView)FindViewById(Resource.Id.gesture_name);
                var      name  = input.TextFormatted;
                if (name.Length() == 0)
                {
                    input.Error = GetString(Resource.String.error_missing_name);
                    return;
                }

                GestureLibrary store = GestureBuilderActivity.Store;
                store.AddGesture(name.ToString(), mGesture);
                store.Save();

                SetResult(Result.Ok);

                string path = Path.Combine(Environment.ExternalStorageDirectory.AbsolutePath, "gestures");
                Toast.MakeText(this, GetString(Resource.String.save_success, path), ToastLength.Long).Show();
            }
            else
            {
                SetResult(Result.Canceled);
            }

            Finish();
        }
 void Awake()
 {
     instance     = this;
     m_GestureLib = new GestureLibrary(Application.dataPath + "/BHZ.GLIB");
     m_VTLeft     = m_TCLeft.GetComponent <VelocityTracker>();
     m_VTRight    = m_TCRight.GetComponent <VelocityTracker>();
 }
Exemplo n.º 4
0
 void Start()
 {
     gl                  = new GestureLibrary(libraryToLoad);
     platform            = Application.platform;
     gestureLineRenderer = gestureOnScreen.GetComponent <LineRenderer>();
     drawArea            = new Rect(0, 0, Screen.width - 370, Screen.height);
 }
Exemplo n.º 5
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            // This activity will use a GestureOverlayView as it's content view. The layout file
            // will be added as a subview of this.
            GestureOverlayView gestureOverlayView = new GestureOverlayView(this);

            SetContentView(gestureOverlayView);

            // Load the binary gesture file that we created.
            _gestureLibrary = GestureLibraries.FromRawResource(this, Resource.Raw.gestures);
            if (!_gestureLibrary.Load())
            {
                Log.Wtf(GetType().FullName, "There was a problem loading the gesture library.");
                Finish();
            }

            // Load up the layout file for this activity and add it as child view of the
            // GestureOverlayView
            View view = LayoutInflater.Inflate(Resource.Layout.custom_gesture_layout, null);

            _imageView = view.FindViewById <ImageView> (Resource.Id.imageView1);
            gestureOverlayView.AddView(view);

            gestureOverlayView.GesturePerformed += GestureOverlayViewOnGesturePerformed;
        }
Exemplo n.º 6
0
    // Use this for initialization
    virtual protected void Start()
    {
        MaxHealth = 100;
        Health    = MaxHealth;

        //Load the gesture library
        m_GestureLibrary = new GestureLibrary(m_LibraryName);
        m_LineRenderer   = m_GestureOnScreen.GetComponent <LineRenderer>();
    }
Exemplo n.º 7
0
    public void MakeNewGestureFile()
    {
        //make a new xml file for this gesture
        Debug.Log($"Making new Gesture Lib file {libraryToLoad}");
        TextAsset templateFile = Resources.Load <TextAsset>($"{Const.GESTURE_FOLDER_NAME}/{Const.GESTURE_LIBRARY_TEMPLATE_NAME}");
        string    path         = Path.Combine(Path.Combine(Application.dataPath, $"Resources/{Const.GESTURE_FOLDER_NAME}"), $"{libraryToLoad}.xml");

        FileTools.Write(path, templateFile.text);
        gl = new GestureLibrary(libraryToLoad, forceCopy);
    }
Exemplo n.º 8
0
    // Load the library.
    void Start()
    {
        gl = new GestureLibrary(libraryToLoad, forceCopy);

        if (gestureLimitType == GestureLimitType.RectBoundsClamp)
        {
            parentCanvas               = gestureLimitRectBounds.GetComponentInParent <Canvas>();
            gestureLimitRect           = RectTransformUtility.PixelAdjustRect(gestureLimitRectBounds, parentCanvas);
            gestureLimitRect.position += new Vector2(gestureLimitRectBounds.position.x, gestureLimitRectBounds.position.y);
        }
    }
Exemplo n.º 9
0
    //[MenuItem("Tools/Test Load All Stage Pictures")]
    public static async void TestLoadStagePictureAsync()
    {
        if (!Application.isPlaying)
        {
            Debug.LogError("Async only work in play mode");
            return;
        }
        testRunning = true;
        Debug.Log("Test started");
        var time       = DateTime.Now;
        int errorCount = 0;
        var service    = GameDatabase.GetDataServiceInEditMode();
        List <StageData> stageDatas = service.GetAllStageData().ToList();

        Debug.Log($"Testing {stageDatas.Count} stages");
        for (int i = 0; i < stageDatas.Count; i++)
        {
            if (stopTest)
            {
                stopTest = false;
                break;
            }
            Debug.Log($"Testing stage {stageDatas[i].id}");
            PictureData pictureData = service.GetPictureData(stageDatas[i].picture_name);
            if (pictureData == null)
            {
                Debug.LogError($"Picture data not found {stageDatas[i].id}");
                continue;
            }
            var picture = await AddressableImage.GetSpriteFromAtlasAsync(pictureData.name);

            if (picture == null)
            {
                Debug.LogError($"{pictureData.name} load failed");
                errorCount++;
            }
            var pictureSolution = await AddressableImage.GetSpriteFromAtlasAsync(StagePictureControl.GetPictureSolutionName(pictureData.name));

            if (pictureSolution == null)
            {
                Debug.LogError($"{StagePictureControl.GetPictureSolutionName(pictureData.name)} solution load failed");
                errorCount++;
            }

            //test load Gesture
            GestureLibrary gl = new GestureLibrary(pictureData.name, true, pictureData.use_v4);
        }
        TimeSpan timePassed = DateTime.Now - time;

        Debug.Log($"Test completed in {timePassed}, error count: {errorCount}");
        testRunning = false;
    }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.gestures_list);

            mAdapter    = new GesturesAdapter(this);
            ListAdapter = mAdapter;

            if (sStore == null)
            {
                sStore = GestureLibraries.FromFile(mStoreFile);
            }
            mEmpty = (TextView)FindViewById(Android.Resource.Id.Empty);
            LoadGestures();

            RegisterForContextMenu(ListView);
        }
Exemplo n.º 11
0
    public override void OnInspectorGUI()
    {
        GestureLibrary library = (GestureLibrary)target;

        if (GUILayout.Button("Open in Gesture Editor"))
        {
            GestureEditor.Init();
        }

        if (GUILayout.Button("Resample Gestures"))
        {
            library.ResampleGestures();
        }

        GUILayout.BeginHorizontal();

        if (GUILayout.Button("Expand All"))
        {
            for (int i = 0; i < library.Gestures.Count; i++)
            {
                library.Gestures[i].IsShown = true;
            }
        }

        if (GUILayout.Button("Collapse All"))
        {
            for (int i = 0; i < library.Gestures.Count; i++)
            {
                library.Gestures[i].IsShown = false;
            }
        }

        GUILayout.EndHorizontal();

        for (int i = 0; i < library.Gestures.Count; i++)
        {
            library.Gestures[i].IsShown = EditorGUILayout.Foldout(library.Gestures[i].IsShown, library.Gestures[i].Name);

            if (library.Gestures[i].IsShown)
            {
                GUILayout.Box("", GUILayout.Width(256), GUILayout.Height(256));
                GestureEditorUtility.DrawGesture(library.Gestures[i], GUILayoutUtility.GetLastRect());
            }
        }
    }
Exemplo n.º 12
0
    static IEnumerator CoTestLoadStagePicture()
    {
        testRunning = true;
        Debug.Log("Test started");
        var time = DateTime.Now;

        errorCount = 0;
        var service = GameDatabase.GetDataServiceInEditMode();
        List <StageData> stageDatas = service.GetAllStageData().ToList();

        Debug.Log($"Testing {stageDatas.Count} stages");
        for (int i = 0; i < stageDatas.Count; i++)
        {
            if (stopTest)
            {
                stopTest = false;
                break;
            }
            Debug.Log($"Testing stage {stageDatas[i].id}");
            PictureData pictureData = service.GetPictureData(stageDatas[i].picture_name);
            if (pictureData == null)
            {
                Debug.LogError($"Picture data not found {stageDatas[i].id}");
                continue;
            }

            yield return(tempMono.StartCoroutine(CoTestLoadPicture(pictureData.name)));

            yield return(tempMono.StartCoroutine(CoTestLoadPicture(StagePictureControl.GetPictureSolutionName(pictureData.name))));

            //test load Gesture
            GestureLibrary gl = new GestureLibrary(pictureData.name, true, pictureData.use_v4);
            if (errorCount > 0)
            {
                Debug.Log("Test aborted");
                break;
            }
        }
        TimeSpan timePassed = DateTime.Now - time;

        Debug.Log($"Test completed in {timePassed}, error count: {errorCount}");
        testRunning = false;
    }
Exemplo n.º 13
0
    public Result Recognize(GestureLibrary gestureLibrary, bool fast = false)
    {
        if (this.Points.Count <= 2)
        {
            return(new Result("Not enough points captured", 0f));
        }
        else
        {
            List <Gesture> library = gestureLibrary.Library;

            float b = float.MaxValue;
            int   u = -1;

            for (int i = 0; i < library.Count; i++)
            {
                float d = 0;

                if (fast)
                {
                    d = GetOptimalCosineDistance(library[i].Vector, this.Vector);
                }
                else
                {
                    d = GetDistanceAtBestAngle(library[i], -this.ANGLE_RANGE, +this.ANGLE_RANGE, this.ANGLE_PRECISION);
                }

                if (d < b)
                {
                    b = d;
                    u = i;
                }
            }

            if (u == -1)
            {
                return(new Result("No match", 0f));
            }
            else
            {
                return(new Result(library[u].Name, fast ? 1f / b : 1f - b / this.HALF_DIAGONAL));
            }
        }
    }
Exemplo n.º 14
0
    // Load the library.
    public void Setup(string id)
    {
        libraryToLoad = id;
        string resPath = $"{GestureLibrary.GetResourcesPath(libraryToLoad)}.xml";

        if (!File.Exists(resPath))
        {
            TextAsset textAsset = Resources.Load <TextAsset>($"{Const.GESTURE_FOLDER_NAME}/{libraryToLoad}");
            if (textAsset == null)
            {
                Debug.Log($"Gesture file doesn't exist, making new gesture file {libraryToLoad}");
                MakeNewGestureFile();
            }
        }
        else
        {
            gl = new GestureLibrary(libraryToLoad, forceCopy);
        }
    }
Exemplo n.º 15
0
 void Start()
 {
     gl            = new GestureLibrary("gestures");
     Life          = new GameObject[3];
     figGesture    = new GameObject[5];
     scene         = SceneManager.GetActiveScene();
     figGesture[0] = GameObject.FindGameObjectWithTag("infinity");
     figGesture [0].SetActive(false);
     figGesture[1] = GameObject.FindGameObjectWithTag("rectangle");
     figGesture [1].SetActive(false);
     figGesture[2] = GameObject.FindGameObjectWithTag("circle");
     figGesture [2].SetActive(false);
     figGesture[3] = GameObject.FindGameObjectWithTag("zig zag");
     figGesture [3].SetActive(false);
     figGesture[4] = GameObject.FindGameObjectWithTag("star");
     figGesture [4].SetActive(false);
     Life [0] = GameObject.FindGameObjectWithTag("Life 3");
     Life [1] = GameObject.FindGameObjectWithTag("Life 2");
     Life [2] = GameObject.FindGameObjectWithTag("Life 1");
 }
            protected override int RunInBackground(params Object [] parms)
            {
                if (IsCancelled)
                {
                    return((int)GestureBuilderActivity.Status.Cancelled);
                }
                if (!Environment.MediaMounted.Equals(Environment.ExternalStorageState))
                {
                    return((int)GestureBuilderActivity.Status.NoStorage);
                }

                GestureLibrary store = sStore;

                if (store.Load())
                {
                    foreach (string name in store.GestureEntries)
                    {
                        if (IsCancelled)
                        {
                            break;
                        }

                        foreach (Gesture gesture in store.GetGestures(name))
                        {
                            Bitmap bitmap = gesture.ToBitmap(mThumbnailSize, mThumbnailSize,
                                                             mThumbnailInset, mPathColor);
                            NamedGesture namedGesture = new NamedGesture();
                            namedGesture.Gesture = gesture;
                            namedGesture.Name    = name;

                            parent.mAdapter.AddBitmap(namedGesture.Gesture.ID, bitmap);
                            PublishProgress(namedGesture);
                        }
                    }

                    return((int)GestureBuilderActivity.Status.Success);
                }

                return((int)GestureBuilderActivity.Status.NotLoaded);
            }
Exemplo n.º 17
0
 // Load the library.
 void Start()
 {
     gl = new GestureLibrary(libraryToLoad, forceCopy);
 }