Exemple #1
0
    private void SampleSingle()
    {
        int idx  = xyz.Count % targetUV.Length;
        int pass = xyz.Count / targetUV.Length;

        // For debug purposes
        {
            Vector3 noise = new Vector3(
                UnityEngine.Random.Range(-noiseFactor, noiseFactor),
                UnityEngine.Random.Range(-noiseFactor, noiseFactor),
                UnityEngine.Random.Range(-noiseFactor, noiseFactor));
            sumNoise += noise.magnitude;
            Vector3 pos = SourceCamera.ViewportToWorldPoint(
                new Vector3(0, 0, 20 + depth * pass)
                + (Vector3)targetUV[idx])
                          + noise;
            DummyNoise = (sumNoise / xyz.Count);
            AddSample(targetUV[idx], pos);
        }
    }
Exemple #2
0
    private void OnDrawGizmos()
    {
        if (SourceCamera == null)
        {
            SourceCamera = GetComponent <Camera>();
        }

        Gizmos.color = Color.gray;

        if (targetUV.Length > 0)
        {
            float d = 20;
            Gizmos.color = target.IsTracked() ? Color.white : Color.red;
            int     currentIdx    = xyz.Count % targetUV.Length;
            Vector2 currentTarget = targetUV[currentIdx];
            Vector3 point00       = SourceCamera.ViewportToWorldPoint(new Vector3(0, currentTarget.y, d));
            Vector3 point01       = SourceCamera.ViewportToWorldPoint(new Vector3(1, currentTarget.y, d));
            Vector3 point10       = SourceCamera.ViewportToWorldPoint(new Vector3(currentTarget.x, 0, d));
            Vector3 point11       = SourceCamera.ViewportToWorldPoint(new Vector3(currentTarget.x, 1, d));
            Gizmos.DrawLine(point00, point01);
            Gizmos.DrawLine(point10, point11);
        }
    }
Exemple #3
0
    // Update is called once per frame
    void LateUpdate()
    {
        if (fake)
        {
            int pass = xyz.Count / targetUV.Length;

            Vector2 __uv    = currentUV();
            Vector3 fakeXYZ = SourceCamera.ViewportToWorldPoint(new Vector3(__uv.x, __uv.y, 40 + 10 * pass)) + new Vector3(Random.Range(-noise, noise), Random.Range(-noise, noise), Random.Range(-noise, noise));
            target.transform.LookAt(SourceCamera.transform.position + new Vector3(Random.Range(-noise, noise), Random.Range(-noise, noise), Random.Range(-noise, noise)));
            target.transform.position = fakeXYZ;
        }
        if (update)
        {
            reset   |= Input.GetKeyDown(resetKey);
            sample  |= Input.GetKeyDown(sampleKey);
            compute |= Input.GetKeyDown(computeKey);
        }

        if (reset)
        {
            Debug.Log("Reset");
            Clear();
            reset = false;
        }
        else if (sample)
        {
            Debug.Log("Sample");
            Sample();
            sample = false;
        }
        if (compute)
        {
            Debug.Log("Compute");
            result  = ComputeCalibration(SourceCamera.pixelWidth, SourceCamera.pixelHeight, near, far);
            compute = false;
        }
    }
Exemple #4
0
    //Gizmos.DrawLine()


    void OnDrawGizmosSelected()
    {
        if (targetUV.Length == samplingWidth * samplingHeight)
        {
            if (subsampling)
            {
                SubSample();
                for (int x = 0; x < samplingWidth - 1; ++x)
                {
                    for (int y = 0; y < samplingHeight - 1; ++y)
                    {
                        int idx00 = (y) + (x) * samplingHeight;
                        int idx10 = (y) + (x + 1) * samplingHeight;
                        int idx01 = (y + 1) + (x) * samplingHeight;
                        int idx11 = (y + 1) + (x + 1) * samplingHeight;


                        Vector3 p00 = (Vector3)targetUV[idx00];
                        Vector3 p10 = (Vector3)targetUV[idx10];
                        Vector3 p01 = (Vector3)targetUV[idx01];
                        Vector3 p11 = (Vector3)targetUV[idx11];

                        Gizmos.color = Color.gray;
                        Vector3 p00w = SourceCamera.ViewportToWorldPoint(new Vector3(0, 0, 20) + (Vector3)p00);
                        Vector3 p10w = SourceCamera.ViewportToWorldPoint(new Vector3(0, 0, 20) + (Vector3)p10);
                        Vector3 p01w = SourceCamera.ViewportToWorldPoint(new Vector3(0, 0, 20) + (Vector3)p01);
                        Vector3 p11w = SourceCamera.ViewportToWorldPoint(new Vector3(0, 0, 20) + (Vector3)p11);

                        Gizmos.DrawLine(p00w, p10w);
                        Gizmos.DrawLine(p00w, p01w);
                        Gizmos.DrawLine(p11w, p10w);
                        Gizmos.DrawLine(p11w, p01w);
                    }
                }
                for (int idx = 0; idx < subsampledXYZ.Count; ++idx)
                {
                    // Gizmos.color = Color.white;
                    Gizmos.color = new Color(subsampledUV[idx].x, subsampledUV[idx].y, 0);
                    Gizmos.DrawLine(SourceCamera.ViewportToWorldPoint(new Vector3(0, 0, 20) + (Vector3)subsampledUV[idx]), subsampledXYZ[idx]);
                    Gizmos.DrawSphere(subsampledXYZ[idx], 0.125f);
                }
            }
            else
            {
                for (int current = 0; current < xyz.Count; ++current)
                {
                    try
                    {
                        Gizmos.color = new Color(uv[current].x, uv[current].y, 0);
                        Gizmos.DrawWireSphere(xyz[current], 0.1f);

                        Gizmos.color = new Color(uv[current].x, uv[current].y, 0, 0.5f);
                        Gizmos.DrawLine(transform.position, xyz[current]);
                    }
                    catch (System.Exception)
                    {
                        Debug.Log("" + current + "/" + xyz.Count);
                    }
                }
            }
        }
        OnDrawGizmos();
    }