Пример #1
0
    void VisualizeGaze()
    {
        if (Settings.DataProcessState == PupilSettings.EStatus.ProcessingGaze)
        {
            if (Settings.calibration.currentMode == Calibration.Mode._2D)
            {
                var eyeID = PupilData.currentEyeID;
                if (eyeID == GazeSource.LeftEye || eyeID == GazeSource.RightEye)
                {
                    if (OnEyeGaze != null)
                    {
                        OnEyeGaze(this);
                    }
                }

                _markerLeftEye.UpdatePosition(PupilData._2D.GetEyeGaze(GazeSource.LeftEye));
                _markerRightEye.UpdatePosition(PupilData._2D.GetEyeGaze(GazeSource.RightEye));
                _markerGazeCenter.UpdatePosition(PupilData._2D.GetEyeGaze(GazeSource.BothEyes));
            }
            else if (Settings.calibration.currentMode == Calibration.Mode._3D)
            {
                _gaze3D.UpdatePosition(PupilData._3D.GazePosition);
            }
        }
    }
Пример #2
0
 void VisualizeGaze()
 {
     if (PupilTools.IsGazing)
     {
         lEye.UpdatePosition(PupilData._2D.LeftEyePosition);
         rEye.UpdatePosition(PupilData._2D.RightEyePosition);
         marker.UpdatePosition(PupilData._2D.GazePosition);
         gaze.UpdatePosition(PupilData._3D.GazePosition);
     }
 }
Пример #3
0
 void VisualizeGaze()
 {
     if (PupilTools.IsGazing)
     {
         if (PupilTools.CalibrationMode == Calibration.Mode._2D)
         {
             _markerLeftEye.UpdatePosition(PupilData._2D.LeftEyePosition);
             _markerRightEye.UpdatePosition(PupilData._2D.RightEyePosition);
             _markerGazeCenter.UpdatePosition(PupilData._2D.GazePosition);
         }
         else if (PupilTools.CalibrationMode == Calibration.Mode._3D)
         {
             _gaze3D.UpdatePosition(PupilData._3D.GazePosition);
         }
     }
 }
Пример #4
0
    public static void Calibrate()
    {
        float[] _currentCalibPointPosition = Settings.calibration.GetCalibrationPoint(currentCalibrationPoint);// .currentCalibrationType.calibPoints [currentCalibrationPoint];
        calibrationMarker.UpdatePosition(_currentCalibPointPosition);

        float t = Settings.connection.GetPupilTimestamp();

        if (t - lastTimeStamp > 0.02f) // was 0.1, 1000/60 ms wait in old version
        {
            lastTimeStamp = t;

            //			print ("its okay to go on");

            //Create reference data to pass on. _cPointFloatValues are storing the float values for the relevant current Calibration mode
            AddCalibrationPointReferencePosition(_currentCalibPointPosition, t, 0); //Adding the calibration reference data to the list that wil;l be passed on, once the required sample amount is met.
            AddCalibrationPointReferencePosition(_currentCalibPointPosition, t, 1); //Adding the calibration reference data to the list that wil;l be passed on, once the required sample amount is met.

            if (Settings.debug.printSampling)
            {
                print("Point: " + currentCalibrationPoint + ", " + "Sampling at : " + currentCalibrationSamples + ". On the position : " + _currentCalibPointPosition[0] + " | " + _currentCalibPointPosition[1]);
            }

            currentCalibrationSamples++;//Increment the current calibration sample. (Default sample amount per calibration point is 120)

            if (currentCalibrationSamples >= defaultCalibrationCount)
            {
                currentCalibrationSamples = 0;
                currentCalibrationPoint++;

                //Send the current relevant calibration data for the current calibration point. _CalibrationPoints returns _calibrationData as an array of a Dictionary<string,object>.
                AddCalibrationReferenceData();

                if (currentCalibrationPoint >= currentCalibrationType.points)
                {
                    StopCalibration();
                }
            }
        }
    }
Пример #5
0
    void Update()
    {
        if (PupilTools.IsConnected && PupilTools.IsGazing && (isTraining || isStudy))
        {
            //timeManager time = new timeManager();
            if (isStudy && !Lock)
            {
                //set target to next index
                //if no target set to false and save data
                if (currentOrder < 24)
                {
                    Debug.Log("set random target for study");
                    targetclicker.setTargetActive(order[currentOrder]);
                    currentOrder++;
                    Lock = true;
                }
                else
                {
                    isStudy = false;
                    streamWriter.Close();
                    currentOrder = 0;
                    return;
                }

                //save data
            }
            else if (isTraining && !Lock)
            {
                Debug.Log("set random target for training");
                //random generate data
                int trainingIndex = UnityEngine.Random.Range(0, order.Length);
                targetclicker.setTargetActive(trainingIndex);
                Lock = true;
            }

            if (isRefining)
            {
                Vector2 deltaHead = this.transform.forward - lockHeadForward;
                gazePointCenter = lockCursor.camera.WorldToViewportPoint(lockEyeWorldPoint);
                lockCursor.UpdatePosition(gazePointCenter);
                headCursor.UpdatePosition(gazePointCenter + Vector2.Scale(scaler, deltaHead));
            }
            else
            {
                gazePointCenter = PupilData._2D.GazePosition;
            }


            //missing head point
            streamWriter.WriteLine(gazePointCenter);//save in json
            if (Input.GetKeyDown(KeyCode.R))
            {
                if (!isRefining)
                {
                    Debug.Log("Enter refinement mode.");
                    isRefining      = true;
                    lockHeadForward = this.transform.forward;
                    PupilGazeTracker.Instance.hideGaze();
                    headCursor = new PupilMarker("Head", Color.blue);
                    headCursor.UpdatePosition(gazePointCenter);
                    lockCursor = new PupilMarker("Lock", Color.red);
                    lockCursor.UpdatePosition(gazePointCenter);
                    lockEyeWorldPoint    = lockCursor.WorldPoint();
                    storedCameraRotation = Camera.main.transform.rotation;
                    timeManager.myInstance.pressRefine();
                    streamWriter.WriteLine("enter refine:" + gazePointCenter);
                    Debug.Log(gazePointCenter);
                }
            }
            else if (Input.GetKeyUp(KeyCode.R) && isRefining)
            {
                //Debug.Log(time.selectTime);
                Debug.Log("Exit refinement mode.");
                //write to Txt file
                streamWriter.WriteLine("exit refine:" + gazePointCenter);
                Debug.Log(gazePointCenter);

                // AssetDatabase.ImportAsset(path);
                // TextAsset asset = Resources.Load("test");
                isRefining = false;
                PupilGazeTracker.Instance.showGaze();
                PupilMarker.TryToSetActive(headCursor, false);
                PupilMarker.TryToSetActive(lockCursor, false);
                timeManager.myInstance.releaseRefine();
                Lock = false;
                //send request to upload movement data
            }
        }
        //change condition
        if (Input.GetKey(KeyCode.Z) && !isStudy)
        {
            Debug.Log("switch to condition1");
            conditionID  = 0;
            path         = "Assets/test" + idNum.ToString() + "_" + conditionID.ToString() + ".txt"; //txt save file
            fileStream   = new FileStream(path, FileMode.Create);
            streamWriter = new StreamWriter(fileStream);
            isTraining   = true;
            setCenter();
        }
        else if (Input.GetKey(KeyCode.X) && !isStudy)
        {
            Debug.Log("switch to condition2");
            conditionID  = 1;
            path         = "Assets/test" + idNum.ToString() + "_" + conditionID.ToString() + ".txt"; //txt save file
            fileStream   = new FileStream(path, FileMode.Create);
            streamWriter = new StreamWriter(fileStream);
            isTraining   = true;
            setCenter();
        }
        else if (Input.GetKey(KeyCode.C) && !isStudy)
        {
            Debug.Log("switch to condition3");
            conditionID  = 2;
            path         = "Assets/test" + idNum.ToString() + "_" + conditionID.ToString() + ".txt"; //txt save file
            fileStream   = new FileStream(path, FileMode.Create);
            streamWriter = new StreamWriter(fileStream);
            isTraining   = true;
            setCenter();
        }
        else if (Input.GetKey(KeyCode.V) && !isStudy)
        {
            Debug.Log("switch to condition4");
            conditionID  = 3;
            path         = "Assets/test" + idNum.ToString() + "_" + conditionID.ToString() + ".txt"; //txt save file
            fileStream   = new FileStream(path, FileMode.Create);
            streamWriter = new StreamWriter(fileStream);
            isTraining   = true;
            setCenter();
        }
        else if (Input.GetKey(KeyCode.Space))
        {
            if (isTraining)
            {
                isTraining = false;
                generateOrder();
                isStudy = true;
            }
        }
    }