Exemple #1
0
        private static void AddToRecording(string identifier, Vector3 position, bool isViewportPosition = false)
        {
            var timestamp = PupilDataParser.FloatFromDictionary(gazeDictionary, "timestamp");

            unityWorldPosition = isViewportPosition ? _settings.currentCamera.ViewportToWorldPoint(position + Vector3.forward) :
                                 _settings.currentCamera.cameraToWorldMatrix.MultiplyPoint3x4(position);

            if (!isViewportPosition)
            {
                position.y *= -1;               // Pupil y axis is inverted
            }
            recordingString += string.Format("{0},{1},{2},{3},{4},{5},{6},{7}\n"
                                             , timestamp.ToString("F4")
                                             , identifier
                                             , position.x.ToString("F4"), position.y.ToString("F4"), position.z.ToString("F4")
                                             , unityWorldPosition.x.ToString("F4"), unityWorldPosition.y.ToString("F4"), unityWorldPosition.z.ToString("F4")
                                             );
        }
        public void InitializeSubscriptionSocket(string topic)
        {
            if (SubscriptionSocketForTopic.ContainsKey(topic))
            {
                return;
            }
            SubscriptionSocketForTopic.Add(topic, new SubscriberSocket(Settings.IPHeader + Settings.Subport));
            SubscriptionSocketForTopic[topic].Subscribe(topic);

            Debug.Log("initializing conneciton " + topic);
            //André: Is this necessary??
            //subscriptionSocketForTopic[topic].Options.SendHighWatermark = PupilSettings.numberOfMessages;// 6;
            SubscriptionSocketForTopic[topic].ReceiveReady += (s, a) =>
            {
                var 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;

                    var msgType = m[0].ConvertToString();
                    _mStream = new MemoryStream(m[1].ToByteArray());
                    byte[] thirdFrame = null;
                    if (m.FrameCount >= 3)
                    {
                        thirdFrame = m[2].ToByteArray();
                    }
                    if (PupilManager.Instance.Settings.debug.printMessageType)
                    {
                        Debug.Log(msgType);
                    }
                    if (PupilManager.Instance.Settings.debug.printMessage)
                    {
                        Debug.Log(MessagePackSerializer.ToJson(m[1].ToByteArray()));
                    }
                    if (PupilController.ReceiveDataIsSet)
                    {
                        PupilController.ReceiveData(msgType, MessagePackSerializer.Deserialize <Dictionary <string, object> >(_mStream), thirdFrame);
                    }

                    switch (msgType)
                    {
                    case "notify.calibration.successful":
                        PupilController.CalibrationFinished();
                        Debug.Log(msgType);
                        break;

                    case "notify.calibration.failed":
                        PupilController.CalibrationFailed();
                        Debug.Log(msgType);
                        break;

                    case "gaze":
                    case "gaze.2d.0.":
                    case "gaze.2d.1.":
                    case "pupil.0":
                    case "pupil.1":
                    case "gaze.3d.0.":
                    case "gaze.3d.1.":
                    case "gaze.3d.01.":
                        var dictionary = MessagePackSerializer.Deserialize <Dictionary <string, object> >(_mStream);
                        var confidence = PupilDataParser.FloatFromDictionary(dictionary, "confidence");
                        if (PupilController.IsCalibrating)
                        {
                            var eyeID = PupilDataParser.StringFromDictionary(dictionary, "id");
                            PupilController.UpdateCalibrationConfidence(eyeID, confidence);
                        }
                        else if (msgType.StartsWith("gaze") & confidence > Settings.ConfidenceThreshold)
                        {
                            PupilController.gazeDictionary = dictionary;
                        }
                        break;

                    case "frame.eye.0":
                    case "frame.eye.1":
                        break;

                    default:
                        Debug.Log("No case to handle message with message type " + msgType);
                        break;
                    }
                }
            };
        }