Esempio n. 1
0
    void ParseObjectDetectionResult(int read_length, byte[] result_bytes)
    {
        if (read_length < 26)
        {
            Debug.Log("No detected object. Lenght: " + read_length.ToString());
            return;
        }
        else
        {
            float panelWidth  = canvasRectTransform.rect.width;  // * canvasRectTransform.localScale.x;
            float panelHeight = canvasRectTransform.rect.height; // * canvasRectTransform.localScale.y;

            var labelArray    = new byte[10];
            var positionArray = new float[4];

            // Show no more than MAX_OBJECT_NUM objects
            read_length = Math.Min(MAX_OBJECT_NUM * 26, read_length);

            Vector3[] positions = new Vector3[read_length / 26];
            Vector3[] qs        = new Vector3[read_length / 26];
            float[]   freqs     = new float[read_length / 26];
            string[]  labels    = new string[read_length / 26];
            for (int i = 0; i < read_length; i += 26)
            {
                System.Buffer.BlockCopy(result_bytes, i, labelArray, 0, 10);
                string label = Encoding.UTF8.GetString(labelArray);
                Debug.Log(label);

                System.Buffer.BlockCopy(result_bytes, i + 10, positionArray, 0, 16);
                Debug.Log(positionArray[0].ToString() + " " + positionArray[1].ToString());

                float   pos_x = panelWidth * ((positionArray[0] - 0.5f) * 1.3f + 0.5f);
                float   pos_y = panelWidth * (1 - positionArray[1]) - 200;
                float   pos_z = 100f;
                Vector3 pos   = Camera.main.ScreenToWorldPoint(new Vector3(pos_x, pos_y, pos_z));
                positions[i / 26] = pos;
                qs[i / 26]        = new Vector3(-90, 0, 0);
                freqs[i / 26]     = startFreq + (i / 26) * freqResolution;
                labels[i / 26]    = label;
            }

            if (textUpdater != null)
            {
                textUpdater.setTargetLabelMap(labels);
            }
            stimulusManager.InitialTargets(positions, qs, freqs, labels);
            stimulusManager.GazeShift();
            targetTime = 0.5f;
            state      = 1;
            return;
        }

        /*
         * var floatArray = new float[(read_length) / 4];
         * System.Buffer.BlockCopy(result_bytes, 0, floatArray, 0, read_length);
         *
         * float[] result = floatArray;
         * if (result.Length < 4)
         * {
         *  Debug.Log("No detected object " + result_bytes[0].ToString());
         *  state = 0;
         *  targetTime = 0;
         *  return;
         * }
         *
         * float panelWidth = canvasRectTransform.rect.width;// * canvasRectTransform.localScale.x;
         * float panelHeight = canvasRectTransform.rect.height;// * canvasRectTransform.localScale.y;
         *
         * Vector3[] positions = new Vector3[(int)result.Length / 4];
         * Quaternion[] qs = new Quaternion[(int)result.Length / 4];
         * float[] freqs = new float[(int)result.Length / 4];
         *
         * for (int i = 0; i < result.Length; i += 4)
         * {
         *  Debug.Log("Object " + (i / 4).ToString() + ": x = " + result[i] + ", y = " + result[i + 1]);
         *  float pos_x = panelWidth * ((result[i] - 0.5f) * 1.3f + 0.5f);
         *  float pos_y = panelWidth * (1 - result[i + 1]) - 200;
         *  float pos_z = 100f;
         *  Vector3 pos = Camera.main.ScreenToWorldPoint(new Vector3(pos_x, pos_y, pos_z));
         *  positions[i / 4] = pos;
         *  qs[i / 4] = Quaternion.Euler(-90, 0, 0);
         *  freqs[i / 4] = startFreq + (i / 4) * freqResolution;
         * }
         * stimulusManager.InitialTargets(positions, qs, freqs);
         * stimulusManager.StopStimulating();
         * targetTime = 0.5f;
         * state = 1;
         * //photoCaptureObject.Dispose();
         */
    }