Ejemplo n.º 1
0
        public void GetSample(Point target)
        {
            if (target.X != -1 && target.Y != -1)//if (-1,-1) : target is not detected in the image
            {
                failedBlobDetectionCount = 0;

                tempCalibration.ScenePoints.Add(new AForge.Point(target.X, target.Y));
                tempCalibration.Destination[0, tempCalibration.CalibrationTarget] = target.X;
                tempCalibration.Destination[1, tempCalibration.CalibrationTarget] = target.Y;



                tempCalibration.CalibrationTarget++;


                if (tempCalibration.CalibrationTarget == numberOfPictures)
                {
                    METState.Current.GlassServer.Send(myGlass.MessageType.toGLASS_Calibrate_Scene, new Point(-2, -2));//DONE

                    tempCalibration.CalibrationTarget = 0;
                    tempCalibration.Calibrate();
                    tempCalibration.Calibrated = true;

                    METState.Current.EyeToScene_Mapping = tempCalibration;
                    Finish();
                }
                else
                {
                    METState.Current.GlassServer.Send(myGlass.MessageType.toGLASS_Calibrate_Scene, new Point(tempCalibration.CalibrationTarget, calibPoints[tempCalibration.CalibrationTarget]));
                }
            }


            else if (target.X == -1 && target.Y == -1)
            {
                failedBlobDetectionCount++;

                if (failedBlobDetectionCount <= failedBlobDetectionCount_Max)
                {
                    //tell the user to look at the next target
                    METState.Current.GlassServer.Send(myGlass.MessageType.toGLASS_Calibrate_Scene, new Point(-5, -5));
                }



                else
                {
                    failedBlobDetectionCount = 0;
                    //Calibration terminated!
                    METState.Current.GlassServer.Send(myGlass.MessageType.toGLASS_Calibrate_Scene, new Point(-3, -3));

                    Finish();
                }
            }
        }
Ejemplo n.º 2
0
    /// <summary>
    /// Calibration starts if the calibration button is pressed
    /// </summary>
    void Update()
    {
        if (currentCal.calibrating == true)
        {
            currentCal.Calibrate();
            slider.value = currentCal.pressure;
        }

        if (currentCal.calibrationFinished == true && calComplete == false)
        {
            calComplete = true;
            StartCoroutine("EndCalibration");
        }
    }
Ejemplo n.º 3
0
    private void DrawPopup()
    {
        if (popUp)
        {
            GUI.Box(new Rect(scaledResolutionWidth / 2 - 350, nativeVerticalResolution / 2 - 445, 700, 750), "", "Window");

            if (calibrationError)
            {
                GUI.Box(new Rect(scaledResolutionWidth / 2 - 270, nativeVerticalResolution / 2 - 400, 540, 540), Languages.Instance.GetTranslation("Calibration Error!") + "\n\n" + Languages.Instance.GetTranslation("Make sure the part of the box with 'table' on it is closest to the table."), "EndBox");

                if (GUI.Button(new Rect(scaledResolutionWidth / 2 - 150, nativeVerticalResolution - 380, 300, 100), Languages.Instance.GetTranslation("Okay")))
                {
                    popUp = false;
                    calibrationError = false;
                }
            }
            else
            {
                GUI.Box(new Rect(scaledResolutionWidth / 2 - 270, nativeVerticalResolution / 2 - 400, 540, 540), Languages.Instance.GetTranslation("Make sure the circle on your calibration box is centered with the patient's body!"), "EndBox");

                if (GUI.Button(new Rect(scaledResolutionWidth / 2 - 150, nativeVerticalResolution - 380, 300, 100), Languages.Instance.GetTranslation("Okay")))
                {
                    GameControl.Instance.IsCalibrating = true;
                    GameControl.Instance.IsCalibrated = false;
                    try
                    {
                        calibration.Kill();
                    }
                    catch (Exception)
                    { }
                    EventLogger.Instance.LogData(Languages.Instance.GetTranslation("Calibration Started"));
                    calibration = new Calibration();
                    calibration.Calibrate();
                    popUp = false;
                }
            }

            //if (GUI.Button(new Rect(scaledResolutionWidth / 2 + 15, nativeVerticalResolution - 380, 300, 100), Languages.Instance.GetTranslation("No")))
            //{
            //    popUp = false;
            //}
        }
    }
Ejemplo n.º 4
0
        public static void Calibrate(string[] args)
        {
            var fileName      = args.Length < 2 ? "data/calibration_dto" : args[1];
            var isSecondOrder = args.Length < 3 ? false : Boolean.Parse(args[2]);

            string[] lines = File.ReadAllLines(String.Format("{0}.txt", fileName));
            var      data  = lines.Aggregate(new List <CalibrationLine>(), (p, c) =>
            {
                var split  = c.Split(' ');
                var result = new CalibrationLine
                {
                    Energy   = Double.Parse(split[0]),
                    Area     = Double.Parse(split[1]),
                    Centroid = Double.Parse(split[2])
                };
                p.Add(result);
                return(p);
            });

            Calibration.Calibrate(data, isSecondOrder);
        }
Ejemplo n.º 5
0
    /// <summary>
    /// Calibration starts if the calibration button is pressed
    /// </summary>
    void Update()
    {
        if (currentCal.calibrating == true)
        {
            currentCal.Calibrate();
            slider.value = currentCal.pressure;
            status.text  = currentCal.calibrationStatus;
            status.color = currentCal.calibrationColor;

            if (currentCal.calibrating == false)
            {
                startButton.text       = "Start Step " + currentCal.calibrationStep;
                changeTag.interactable = true;
                startCal.interactable  = true;
            }
        }

        if (currentCal.calibrationFinished == true && calComplete == false)
        {
            calComplete = true;
            StartCoroutine("EndCalibration");
        }
    }
Ejemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        UpdateIK();

        if (!profileExists)
        {
            AutoAdjustHeight();
        }

        bool triggerClicked = false;
        bool gripClicked    = false;
        bool touchClicked   = false;

        int currentTrackedDeviceCount = 0;

        for (int i = 1; i < (int)SteamVR_TrackedObject.EIndex.Device15; i++)
        {
            var device = SteamVR_Controller.Input(i);
            if (device.hasTracking && device.connected && device.valid)
            {
                var deviceClass = OpenVR.System.GetTrackedDeviceClass((uint)i);
                if (deviceClass == ETrackedDeviceClass.Controller || deviceClass == ETrackedDeviceClass.GenericTracker)
                {
                    if (!trackedDevices.ContainsKey(i))
                    {
                        trackedDevices.Add(i, device);
                        debugTrackerController.SetTrackerModels(deviceClass, i);
                        logText.text += "\n Found device with number " + i + ", type " + deviceClass;
                    }

                    currentTrackedDeviceCount++;
                    triggerClicked |= device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger);
                    gripClicked    |= device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad);
                    touchClicked   |= device.GetPressUp(SteamVR_Controller.ButtonMask.Grip);
                }
            }
        }

        numberOfDevicesText.text = string.Format("Number of devices: {0}", currentTrackedDeviceCount);

        if (!turnedOffDeviceLogged && trackedDevices.Count > 0)
        {
            foreach (var trackedDevice in previousTrackedDevices)
            {
                if (!trackedDevices.ContainsKey(trackedDevice.Key))
                {
                    logText.text += "\n " + (SteamVR_TrackedObject.EIndex)trackedDevice.Key + ", type = " + trackedDevice.Value + "turned off";
                    Debug.Log((SteamVR_TrackedObject.EIndex)trackedDevice.Key + ", type = " + trackedDevice.Value + " turned off");
                }
            }
            turnedOffDeviceLogged = true;
        }

        //If some device is turned off, entire device list is recalculated inside SteamVR
        if (currentTrackedDeviceCount < trackedDevices.Count)
        {
            previousTrackedDevices = trackedDevices;
            trackedDevices         = new Dictionary <int, SteamVR_Controller.Device>();
            turnedOffDeviceLogged  = false;
        }

        if (gripClicked)
        {
            ////var offset = leftHandOffsetObject.transform.position - savedProfile.CalibrationPoints.FirstOrDefault(x => x.Type == CalibrationPointType.LeftHand).DevicePosition;

            //var calibrationPoints = calibration.Calibrate(trackedDevices);
            ////leftHandOffsetObject.transform.position = calibrationPoints.Where(x => x.Type == CalibrationPointType.LeftHand).FirstOrDefault().Position - offset;
            ////rightHandOffsetObject.transform.position = calibrationPoints.Where(x => x.Type == CalibrationPointType.RightHand).FirstOrDefault().Position - offset;
            //updateIK = true;
            //gripClicked = false;

            gripClicked       = false;
            updateIK          = false;
            chartcterSwitcher = true;
            //offsetTrackedList = new List<OffsetTracking>();
            currentCharacter.SetActive(false);
            var chaarterIndex = characters.IndexOf(currentCharacter) + 1;

            currentCharacter = characters[chaarterIndex == -1 ? 0 : chaarterIndex % characters.Count];
            currentCharacter.SetActive(true);
            eyeTransform = currentCharacter.GetComponent <HeadIK>().EyeTransform;
            if (calibrated)
            {
                var root = offsetTrackedList.FirstOrDefault(x => x.pointType == CalibrationPointType.LowerBack);
                if (root != null)
                {
                    root.targetTrans          = currentCharacter.transform;
                    root.targetTrans.rotation = Quaternion.identity;
                }
                StartIK();
                updateIK = true;
            }
        }

        //if (touchClicked)
        //{
        //    var calibrationPoints = calibration.Calibrate(trackedDevices);
        //    StartTracking2(calibrationPoints);
        //}

        if (triggerClicked && !calibrated)
        {
            var calibrationPoints = calibration.Calibrate(trackedDevices);
            StartTracking(calibrationPoints);
            var root = offsetTrackedList.FirstOrDefault(x => x.pointType == CalibrationPointType.LowerBack);
            if (root != null)
            {
                root.targetTrans          = currentCharacter.transform;
                root.targetTrans.rotation = Quaternion.identity;
            }
            StartIK();
            updateIK      = true;
            calibrated    = true;
            profileExists = true;
            headset.SetActive(false);
            //SaveProfile(calibrationPoints);
        }
        if (updateIK)
        {
            if (chartcterSwitcher)
            {
                leftHandOffsetObject.transform.localPosition  = initModelState.handMarkerLeftPos;
                rightHandOffsetObject.transform.localPosition = initModelState.handMarkerRightPos;
                leftHandOffsetObject.transform.localRotation  = Quaternion.Euler(0, 90, 0);
                rightHandOffsetObject.transform.localRotation = Quaternion.Euler(0, -90, 0);
            }
            UpdateOffsetTracking();
        }
    }