//Adds the gaze data to the list.
 private void EnqueueGazeData(HMDGazeData gazeData)
 {
     if (gazeData != null)
     {
         gazeDataBuffer.Add(gazeData);
     }
 }
Exemple #2
0
        //Load the gaze data from recording with index fileIndex. Set append to true if reading from several data files.
        private void LoadData(int fileIndex, bool append)
        {
            SetFileName();

            //Set the file path.
            string path;

            if (fileIndex == 0)
            {
                path = Path.Combine(HMDDataSettings.DATA_FILE_DIRECTORY, fileName + HMDDataSettings.DATA_FILE_ENDING);
            }
            else
            {
                path = Path.Combine(HMDDataSettings.DATA_FILE_DIRECTORY, fileName + "(" + fileIndex + ")" + HMDDataSettings.DATA_FILE_ENDING);
            }

            //Check that the file exists.
            if (!File.Exists(path))
            {
                Debug.Log("GazeDataLoader could not find a file matching the path: " + path + ". Please ensure the GazeRecorder has been running.");
                return;
            }

            string[] jsonStrings = File.ReadAllLines(path);

            //Check that data was loaded.
            if (jsonStrings.Length == 0)
            {
                Debug.Log("The data file found at " + path + " was empty.");
                return;
            }

            //If append is false, clear the data list to repopulate it.
            if (!append)
            {
                dataList.Clear();
                invalidDataCount = 0;
            }

            //Load the data
            HMDGazeData tempData = new HMDGazeData();

            for (int i = 0; i < jsonStrings.Length; i++)
            {
                tempData = (HMDGazeData)JsonUtility.FromJson(jsonStrings[i], typeof(HMDGazeData));
                if (tempData.valid || tempData.pupilsValid || loadInvalid)
                {
                    dataList.Add(tempData);
                }
                else
                {
                    invalidDataCount++;
                }
            }

            Debug.Log("HMDDataLoader loaded " + dataList.Count + " data objects, and discarded " + invalidDataCount + " invalid data objects.");
        }
        //Load data and initialize the replayer.
        private bool Initialize()
        {
            if (initialized)
            {
                return(true);
            }
            replaying = false;

            if (gazeReplayPoint == null)
            {
                Debug.Log("The Gaze Replay Point has not been assigned. Couldn't initialize.");
                return(false);
            }

            gazeReplayPointMeshRenderer = gazeReplayPoint.GetComponent <MeshRenderer>();

            if (gazeReplayPointMeshRenderer == null)
            {
                Debug.Log("The gaze replay point has no Mesh Renderer. Did not initialize.");
                return(false);
            }

            pointImage    = point.GetComponent <Image>();
            pointPosition = Vector2.zero;
            canvas        = GetComponentInChildren <Canvas>();
            if (canvas == null)
            {
                Debug.Log("Could not find a canvas component in children. Init failed.");
                return(false);
            }

            if (pointImage == null)
            {
                Debug.Log("pointImage was not found, did not initalize.");
                return(false);
            }

            HMDDataLoader.instance.LoadData(fileIndex);
            dataIndex = 0;
            dataCount = HMDDataLoader.instance.GetData().Count;
            if (dataCount > 0)
            {
                currentData = HMDDataLoader.instance.GetData(0);
                if (currentData != null)
                {
                    startTime = currentData.timestamp;
                    playTime  = startTime;
                    totalTime = 0;
                    return(true);
                }
            }
            return(false);
        }
        //Turn a data object from the eye tracker into a custom gaze tracker object, ready to be serialized.
        private HMDGazeData EncodeGazeData(IVRGazeData _IVRGazeData)
        {
            if (_IVRGazeData == null)
            {
                return(null);
            }

            HMDGazeData gazeData = new HMDGazeData();

            gazeData.valid     = _IVRGazeData.CombinedGazeRayWorldValid;
            gazeData.timestamp = Time.time;

            Vector3 viewportPoint = Vector3.zero;

            if (gazeData.valid)
            {
                viewportPoint = GazeToViewportPoint(mainCamera, _IVRGazeData.CombinedGazeRayWorld.direction);
            }

            string objectName = "None";
            float  distance   = lastDistance;

            if (raycast)
            {
                RaycastHit hit;
                if (Physics.Raycast(_IVRGazeData.CombinedGazeRayWorld, out hit))
                {
                    distance     = hit.distance;
                    lastDistance = distance;

                    GameObject target = hit.collider.gameObject;
                    if (target != null)
                    {
                        objectName = target.name;
                    }
                }
            }
            else
            {
                objectName = "Not Tracked";
            }

            gazeData.viewPortPoint = viewportPoint;
            gazeData.distance      = distance;
            gazeData.origin        = _IVRGazeData.CombinedGazeRayWorld.origin;
            gazeData.direction     = _IVRGazeData.CombinedGazeRayWorld.direction;
            gazeData.objectName    = objectName;
            gazeData.pupilsValid   = IsPupilDataValid(_IVRGazeData);
            gazeData.pupilSize     = AveragePupilDiameter(_IVRGazeData);

            return(gazeData);
        }
        private void UpdateGazeData()
        {
            //Check if there is data in the list.
            if (dataCount == 0)
            {
                initialized = false;
                return;
            }

            //Update current data.
            if (dataIndex < dataCount)
            {
                HMDGazeData nextData = HMDDataLoader.instance.GetData(dataIndex);
                if (nextData != null)
                {
                    currentData = nextData;
                }
            }
        }