void CustomReceiveData(string topic, Dictionary <string, object> dictionary, byte[] thirdFrame = null) { if (topic.StartsWith("pupil")) { foreach (var item in dictionary) { switch (item.Key) { case "topic": case "method": case "id": var textForKey = PupilTools.StringFromDictionary(dictionary, item.Key); // Do stuff break; case "confidence": print("Conf : " + PupilTools.FloatFromDictionary(dictionary, item.Key)); // Do stuff break; case "norm_pos": print("Norm : " + PupilTools.VectorFromDictionary(dictionary, item.Key)); // Do stuff break; case "ellipse": var dictionaryForKey = PupilTools.DictionaryFromDictionary(dictionary, item.Key); foreach (var pupilEllipse in dictionaryForKey) { switch (pupilEllipse.Key.ToString()) { case "angle": var angle = (float)(double)pupilEllipse.Value; // Do stuff break; case "center": print("Center : " + PupilTools.ObjectToVector(pupilEllipse.Value)); break; case "axes": print("Axes : " + PupilTools.ObjectToVector(pupilEllipse.Value)); // Do stuff break; default: break; } } // Do stuff break; default: break; } } } }
private void AddToLog() { if (PupilData._2D.GazePosition != Vector2.zero) { gazeToWorld = dedicatedCapture.ViewportToWorldPoint(new Vector3(PupilData._2D.GazePosition.x, PupilData._2D.GazePosition.y, Camera.main.nearClipPlane)); } //var raycastHit = EyeRay.CurrentlyHit; var tmp = new { // default variables for all scenes a = DateTime.Now, b = (int)(1.0f / Time.unscaledDeltaTime), // frames per second during the last frame, could calucate an average frame rate instead //c = PupilManager.SceneClass.sceneStat, //cc = SceneTimer.sceneTimer, d = dedicatedCapture.transform.position.x, e = dedicatedCapture.transform.position.y, f = dedicatedCapture.transform.position.z, g = dedicatedCapture.transform.rotation.x, h = dedicatedCapture.transform.rotation.y, i = dedicatedCapture.transform.rotation.z, j = PupilData._2D.GazePosition != Vector2.zero ? PupilData._2D.GazePosition.x : double.NaN, k = PupilData._2D.GazePosition != Vector2.zero ? PupilData._2D.GazePosition.y : double.NaN, l = PupilData._2D.GazePosition != Vector2.zero ? gazeToWorld.x : double.NaN, m = PupilData._2D.GazePosition != Vector2.zero ? gazeToWorld.y : double.NaN, n = PupilData._2D.GazePosition != Vector2.zero ? PupilTools.FloatFromDictionary(PupilTools.gazeDictionary, "confidence") : double.NaN, // confidence value calculated after calibration /* * // Baking tray variables * o = SceneManage.loadTestScene == 2 ? SceneManage.getViveCtrlRight.transform.position.x : double.NaN, * p = SceneManage.loadTestScene == 2 ? SceneManage.getViveCtrlRight.transform.position.y : double.NaN, * q = SceneManage.loadTestScene == 2 ? SceneManage.getViveCtrlRight.transform.position.z : double.NaN, * r = SceneManage.loadTestScene == 2 ? SceneManage.getViveCtrlRight.transform.rotation.x : double.NaN, * s = SceneManage.loadTestScene == 2 ? SceneManage.getViveCtrlRight.transform.rotation.y : double.NaN, * t = SceneManage.loadTestScene == 2 ? SceneManage.getViveCtrlRight.transform.rotation.z : double.NaN, * tt = SceneManage.loadTestScene == 2 ? ControllerGrabObject.bunLastActive.ctrlEventHolder : "null", * ttt = SceneManage.loadTestScene == 2 && ControllerGrabObject.objectInHand != null ? ControllerGrabObject.bunLastActive.bunActive.name : "null", * u = SceneManage.loadTestScene == 2 && ControllerGrabObject.objectInHand != null ? ControllerGrabObject.bunLastActive.bunActive.transform.position.x : double.NaN, * v = SceneManage.loadTestScene == 2 && ControllerGrabObject.objectInHand != null ? ControllerGrabObject.bunLastActive.bunActive.transform.position.y : double.NaN, * x = SceneManage.loadTestScene == 2 && ControllerGrabObject.objectInHand != null ? ControllerGrabObject.bunLastActive.bunActive.transform.position.z : double.NaN, * * // Museum variables * cbis = SceneManage.loadTestScene == 3 && PaintingsSets.CurrentSet != null ? PaintingsSets.CurrentSet.SetName : "null", * ord = SceneManage.loadTestScene == 3 ? PaintingsSets.myIntArrayString : "null", * oo = SceneManage.loadTestScene == 3 && raycastHit.transform != null ? raycastHit.transform.name : "null", * ox = SceneManage.loadTestScene == 3 && raycastHit.transform != null ? raycastHit.transform.position.x : double.NaN, * oy = SceneManage.loadTestScene == 3 && raycastHit.transform != null ? raycastHit.transform.position.y : double.NaN, * oz = SceneManage.loadTestScene == 3 && raycastHit.transform != null ? raycastHit.transform.position.z : double.NaN, * oox = SceneManage.loadTestScene == 3 && raycastHit.transform != null ? CalculEyeGazeOnObject(raycastHit).x : double.NaN, * ooy = SceneManage.loadTestScene == 3 && raycastHit.transform != null ? CalculEyeGazeOnObject(raycastHit).y : double.NaN, * ooz = SceneManage.loadTestScene == 3 && raycastHit.transform != null ? CalculEyeGazeOnObject(raycastHit).z : double.NaN * */ }; _toLog.Add(tmp); }
void CustomReceiveData(string topic, Dictionary <string, object> dictionary, byte[] thirdFrame = null) { if (topic.StartsWith("pupil.1")) { foreach (var item in dictionary) { switch (item.Key) { case "confidence": countDown -= Time.deltaTime; if (countDown < 0) { confidence1 = PupilTools.FloatFromDictionary(dictionary, item.Key); lconf.text = "Left confidence\n" + (confidence1 * 100) + "%"; } break; default: break; } } } if (topic.StartsWith("pupil.0")) { foreach (var item in dictionary) { switch (item.Key) { case "confidence": if (countDown < 0) { confidence0 = PupilTools.FloatFromDictionary(dictionary, item.Key); rconf.text = "Right confidence\n" + (confidence0 * 100) + "%"; } break; default: break; } } } if (topic.StartsWith("gaze")) { foreach (var item in dictionary) { switch (item.Key) { case "confidence": if (countDown < 0) { gazeConfidence = PupilTools.FloatFromDictionary(dictionary, item.Key); print(gazeConfidence); ConfidenceList.Add(gazeConfidence); countDown = refreshTime; } break; default: break; } } } }
public void InitializeSubscriptionSocket(string topic) { if (!subscriptionSocketForTopic.ContainsKey(topic)) { subscriptionSocketForTopic.Add(topic, new SubscriberSocket(IPHeader + subport)); subscriptionSocketForTopic[topic].Subscribe(topic); //André: Is this necessary?? // subscriptionSocketForTopic[topic].Options.SendHighWatermark = PupilSettings.numberOfMessages;// 6; subscriptionSocketForTopic[topic].ReceiveReady += (s, a) => { int i = 0; NetMQMessage m = new NetMQMessage(); while (a.Socket.TryReceiveMultipartMessage(ref m)) { // We read all the messages from the socket, but disregard the ones after a certain point // if ( i > PupilSettings.numberOfMessages ) // 6) // continue; string msgType = m[0].ConvertToString(); mStream = new MemoryStream(m[1].ToByteArray()); byte[] thirdFrame = null; if (m.FrameCount >= 3) { thirdFrame = m[2].ToByteArray(); } if (PupilSettings.Instance.debug.printMessageType) { Debug.Log(msgType); } if (PupilSettings.Instance.debug.printMessage) { Debug.Log(MessagePackSerializer.ToJson(m[1].ToByteArray())); } if (PupilTools.ReceiveDataIsSet) { PupilTools.ReceiveData(msgType, MessagePackSerializer.Deserialize <Dictionary <string, object> >(mStream), thirdFrame); // Uncomment if this is not the problem for skipping gazepoint //the continue block subscribing to multiple topics // continue; } switch (msgType) { case "notify.calibration.successful": PupilTools.CalibrationFinished(); Debug.Log(msgType); break; case "notify.calibration.failed": PupilTools.CalibrationFailed(); Debug.Log(msgType); break; case "gaze": case "gaze.2d.0.": case "gaze.2d.1.": case "pupil.0": var dictionary0 = MessagePackSerializer.Deserialize <Dictionary <string, object> >(mStream); confidence0 = PupilTools.FloatFromDictionary(dictionary0, "confidence"); if (PupilTools.IsCalibrating) { string eyeID = PupilTools.StringFromDictionary(dictionary0, "id"); PupilTools.UpdateCalibrationConfidence(eyeID, confidence0); break; } if ((confidence0 > confidenceThreshold) && msgType.StartsWith("gaze")) { PupilTools.gazeDictionary = dictionary0; } break; case "pupil.1": var dictionary = MessagePackSerializer.Deserialize <Dictionary <string, object> >(mStream); confidence1 = PupilTools.FloatFromDictionary(dictionary, "confidence"); if (PupilTools.IsCalibrating) { string eyeID = PupilTools.StringFromDictionary(dictionary, "id"); PupilTools.UpdateCalibrationConfidence(eyeID, confidence1); break; } if ((confidence1 > confidenceThreshold) && msgType.StartsWith("gaze")) { PupilTools.gazeDictionary = dictionary; } break; case "frame.eye.0": case "frame.eye.1": break; default: Debug.Log(msgType); break; } i++; } }; } }
void CustomReceiveData(string topic, Dictionary <string, object> dictionary, byte[] thirdFrame = null) { if (topic.StartsWith("pupil.1")) { foreach (var item in dictionary) { switch (item.Key) { case "confidence": countDown -= Time.deltaTime; if (countDown < 0) { confidence1 = PupilTools.FloatFromDictionary(dictionary, item.Key); lconf.text = "Left confidence\n" + (confidence1 * 100) + "%"; } break; case "norm_pos": var positionForKey = PupilTools.VectorFromDictionary(dictionary, item.Key); // print("norm_pos_x : " + positionForKey.x + " / norm_pos_y : " + positionForKey.y); if (positionForKey.x != 0 && positionForKey.y != 1 && leftPupil != null) { positionForKey.x -= 0.5f; positionForKey.y -= 0.5f; positionForKey.x *= -1; leftPupil.transform.localPosition = positionForKey; if (confidence1 > .6) { leftPupil.GetComponent <Renderer>().material.color = Color.green; } else { leftPupil.GetComponent <Renderer>().material.color = Color.red; } } break; case "ellipse": var dictionaryForKey = PupilTools.DictionaryFromDictionary(dictionary, item.Key); foreach (var pupilEllipse in dictionaryForKey) { switch (pupilEllipse.Key.ToString()) { case "center": // var center = PupilTools.ObjectToVector(pupilEllipse.Value); // // center.x -= 0.5f; // // center.y -= 0.5f; // // center.x *= -1; // GameObject.FindGameObjectWithTag("lcenter").transform.localPosition = center; break; default: break; } } // Do stuff break; default: break; } } } if (topic.StartsWith("pupil.0")) { foreach (var item in dictionary) { switch (item.Key) { case "confidence": if (countDown < 0) { confidence0 = PupilTools.FloatFromDictionary(dictionary, item.Key); rconf.text = "Right Confidence\n" + (confidence0 * 100) + "%"; countDown = refreshTime; } break; case "norm_pos": var positionForKey = PupilTools.VectorFromDictionary(dictionary, item.Key); // print("norm_pos_x : " + positionForKey.x + " / norm_pos_y : " + positionForKey.y); if (positionForKey.x != 0 && positionForKey.y != 1 && rightPupil != null) { positionForKey.x -= 0.5f; positionForKey.y -= 0.5f; positionForKey.y *= -1; rightPupil.transform.localPosition = positionForKey; if (confidence0 > .6) { rightPupil.GetComponent <Renderer>().material.color = Color.green; } else { rightPupil.GetComponent <Renderer>().material.color = Color.red; } } break; case "ellipse": var dictionaryForKey = PupilTools.DictionaryFromDictionary(dictionary, item.Key); foreach (var pupilEllipse in dictionaryForKey) { switch (pupilEllipse.Key.ToString()) { case "center": // var center = PupilTools.ObjectToVector(pupilEllipse.Value); // // center.x -= 0.5f; // // center.y -= 0.5f; // // center.x *= -1; // GameObject.FindGameObjectWithTag("rcenter").transform.localPosition = center; break; default: break; } } // Do stuff break; default: break; } } } }
/// <summary> /// Reading subscribed topics, doesn't need to call it except in the start method with "PupilTools.OnReceiveData += CustomReceiveData;" /// </summary> void CustomReceiveData(string topic, Dictionary <string, object> dictionary, byte[] thirdFrame = null) { //countdown for the confidence countDown -= Time.deltaTime; //reading the pupil topic of the left eye if (topic.StartsWith("pupil.1")) { //parsing the topic foreach (var item in dictionary) { //switch between the different variable available in the given topic switch (item.Key) { //at confidence when the countdown is under 0 save the confidence value and show it to the user case "confidence": if (countDown < 0) { confidence1 = PupilTools.FloatFromDictionary(dictionary, item.Key); } lconf.text = "Left confidence\n" + System.Math.Round(confidence1 * 100) + "%"; break; //Normalized position of the fixation's centroid, used to show where is the pupil on the frame case "norm_pos": var positionForKey = PupilTools.VectorFromDictionary(dictionary, item.Key); //check if the eye is tracked and the gameobject is still there //if the eye is not tracked the x will be 0 and the y will be 1, //as it changes from the last tracked position we ignore it if (positionForKey.x != 0 && positionForKey.y != 1 && leftPupil != null) { positionForKey.x -= 0.5f; positionForKey.y -= 0.5f; positionForKey.x *= -1; leftPupil.transform.localPosition = positionForKey; //if the confidence is above 0.6 (60%) the pupil color will be green, else red // above 60% of confidence the position is trusty enough according to the pupil lab doc if (confidence1 > .6) { leftPupil.GetComponent <Renderer>().material.color = Color.green; } else { leftPupil.GetComponent <Renderer>().material.color = Color.red; } } break; default: break; } } } //same as the topic pupil.0 if (topic.StartsWith("pupil.0")) { foreach (var item in dictionary) { switch (item.Key) { case "confidence": if (countDown < 0) { confidence0 = PupilTools.FloatFromDictionary(dictionary, item.Key); } rconf.text = "Right Confidence\n" + System.Math.Round(confidence0 * 100) + "%"; break; case "norm_pos": var positionForKey = PupilTools.VectorFromDictionary(dictionary, item.Key); if (positionForKey.x != 0 && positionForKey.y != 1 && rightPupil != null) { positionForKey.x -= 0.5f; positionForKey.y -= 0.5f; positionForKey.y *= -1; rightPupil.transform.localPosition = positionForKey; if (confidence0 > .6) { rightPupil.GetComponent <Renderer>().material.color = Color.green; } else { rightPupil.GetComponent <Renderer>().material.color = Color.red; } } break; default: break; } } } if (countDown < 0) { //save the average between right and left eye confidence and increment the index confArray[arrayIndex] = (confidence0 + confidence1) / 2; arrayIndex++; //as we only need the last 50 confidence value, reset the index if (arrayIndex == 50) { arrayIndex = 0; } //reset the countdown countDown = refreshTime; } }