Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (_Sensor == null)
        {
            return;
        }

        _MultiManager = MultiSourceManager.GetComponent <MultiSourceManager>();
        if (_MultiManager == null)
        {
            return;
        }

        //Generates a new point cloud every 30 fps
        if (_MultiManager.GetDepthData() != null)
        {
            CreatePointCloud(_MultiManager.GetDepthData(), _MultiManager.GetColorTexture());
        }

        //DebugScript(pointCloud);
        if (pCloudReady && !structureReady)
        {
            generateStructure();
            structure.transform.Rotate(new Vector3(-1 * rotate, 0, 180));
        }
        else if (pCloudReady && structureReady)
        {
            RefreshData();
            //takeDepthSnap();
        }

        if (recordMovie)
        {
            if (!started)
            {
                startTime = Time.time;
                started   = true;
                if (fileName.Equals(""))
                {
                    fileName = "myMovie";
                }

                myRecorder = new Recorder(fileName, H, W, skip);
            }

            recordFrame();
        }

        if (structure != null)
        {
            //structure.transform.position = new Vector3(0, 100, -50);
            structure.transform.localScale = new Vector3(50, 50, 50);
        }
    }
Example #2
0
    void Update()
    {
        if (_Sensor == null)
        {
            return;
        }

        float yVal = Input.GetAxis("Horizontal");
        float xVal = -Input.GetAxis("Vertical");

        transform.Rotate(
            (xVal * Time.deltaTime * _Speed),
            (yVal * Time.deltaTime * _Speed),
            0,
            Space.Self);

        if (MultiSourceManager == null)
        {
            return;
        }

        _MultiManager = MultiSourceManager.GetComponent <MultiSourceManager>();
        if (_MultiManager == null)
        {
            return;
        }

        gameObject.GetComponent <Renderer>().material.mainTexture = _MultiManager.GetColorTexture();

        RefreshData(_MultiManager.GetDepthData(),
                    _MultiManager.ColorWidth,
                    _MultiManager.ColorHeight);
    }
Example #3
0
    void Update()
    {
        if (_Sensor == null)
        {
            return;
        }
        if (MultiSourceManager == null)
        {
            return;
        }
        if (_MultiManager == null)
        {
            return;
        }

        ushort[] rawdata = _MultiManager.GetDepthData();

        _Mapper.MapDepthFrameToCameraSpace(rawdata, cameraSpacePoints);

        for (int i = 0; i < cameraSpacePoints.Length; i++)
        {
            particles[i].position   = new Vector3(cameraSpacePoints[i].X * scale, cameraSpacePoints[i].Y * scale, cameraSpacePoints[i].Z * scale);
            particles[i].startColor = color;
            particles[i].startSize  = size;
            //if (rawdata[i] == 0) particles[i].startSize = 0;
        }

        _particleSystem.SetParticles(particles, particles.Length);
    }
Example #4
0
    private List <ValidPoint> DepthToColor()
    {
        // Points to return
        List <ValidPoint> validPoints = new List <ValidPoint>();

        // Get Data
        mDepthData = mMultiSource.GetDepthData();

        // Map
        mMapper.MapDepthFrameToCameraSpace(mDepthData, mCameraSpacePoints);
        mMapper.MapDepthFrameToColorSpace(mDepthData, mColorSpacePoints);


        // Filter
        for (int i = 0; i < mDepthResolution.x; i++)
        {
            for (int j = 0; j < mDepthResolution.y / 8; j++)
            {
                // Sample index
                int sampleIndex = (j * mDepthResolution.x) + i;
                sampleIndex *= 8;

                // Cutoff tests
                if (mCameraSpacePoints[sampleIndex].X < mLeftCutOff)
                {
                    continue;
                }

                if (mCameraSpacePoints[sampleIndex].X > mRightCutOff)
                {
                    continue;
                }

                if (mCameraSpacePoints[sampleIndex].Y > mTopCutOff)
                {
                    continue;
                }

                if (mCameraSpacePoints[sampleIndex].Y < mBottomCutOff)
                {
                    continue;
                }

                // Create point
                ValidPoint newPoint = new ValidPoint(mColorSpacePoints[sampleIndex], mCameraSpacePoints[sampleIndex].Z);

                // Depth test
                if (mCameraSpacePoints[sampleIndex].Z >= mWallDepth)
                {
                    newPoint.mWithinWallDepth = true;
                }

                // Add
                validPoints.Add(newPoint);
            }
        }

        return(validPoints);
    }
Example #5
0
    private List <ValidPoint> DepthToColour()
    {
        //Get Depth Data
        mDepthData = mMultiSource.GetDepthData();

        //Map Depth Data
        mMapper.MapDepthFrameToCameraSpace(mDepthData, mCameraSpacePoints);
        mMapper.MapDepthFrameToColorSpace(mDepthData, mColorSpacePoints);

        //Points to return
        List <ValidPoint> validPoints = new List <ValidPoint>();

        // Filter
        for (int i = 0; i < mDepthResolution.x / 8; i++)
        {
            //Divide by 8 to avoid index out of bounds
            for (int j = 0; j < mDepthResolution.y / 8; j++)
            {
                //downsample all of the points to help it run better
                //go through one dimensional array of camera points
                int sampleIndex = (j * mDepthResolution.x) + i;
                //Skip over 8 values between each point
                sampleIndex *= 8;

                //Cut off tests
                if (mCameraSpacePoints[sampleIndex].X < mLeftCutOff)
                {
                    continue;
                }
                if (mCameraSpacePoints[sampleIndex].X > mRightCutOff)
                {
                    continue;
                }
                if (mCameraSpacePoints[sampleIndex].Y > mTopCutOff)
                {
                    continue;
                }
                if (mCameraSpacePoints[sampleIndex].Y < mBottomCutOff)
                {
                    continue;
                }

                //Create a new valid point
                ValidPoint newPoint = new ValidPoint(mColorSpacePoints[sampleIndex], mCameraSpacePoints[sampleIndex].Z);

                //Depth Test
                if (mCameraSpacePoints[sampleIndex].Z >= mWallDepth)
                {
                    newPoint.mWithinWallDepth = true;
                }

                //Add out new pont to valid points
                validPoints.Add(newPoint);
            }
        }

        return(validPoints);
    }
Example #6
0
    private List <ValidPoint> DepthToColor()
    {
        List <ValidPoint> ValidPoints = new List <ValidPoint>();

        //Get depth
        mDepthData = mMultiSource.GetDepthData();

        mMapper.MapDepthFrameToCameraSpace(mDepthData, mCameraSapcePoints);
        mMapper.MapDepthFrameToColorSpace(mDepthData, mColorSpacePoints);

        //Filter
        for (int i = 0; i < mDepthResolution.x / 8; i++)
        {
            for (int j = 0; j < mDepthResolution.y / 8; j++)
            {
                int sampleIndex = (j * mDepthResolution.x) + i;
                sampleIndex *= 8;

                //CutoffTests
                if (mCameraSapcePoints[sampleIndex].X < mLeftCutOff)
                {
                    continue;
                }
                if (mCameraSapcePoints[sampleIndex].X > mRigthCutOff)
                {
                    continue;
                }
                if (mCameraSapcePoints[sampleIndex].Y > mTopCutOff)
                {
                    continue;
                }
                if (mCameraSapcePoints[sampleIndex].Y < mBottomCutOff)
                {
                    continue;
                }

                ValidPoint newPoint = new ValidPoint(mColorSpacePoints[sampleIndex], mCameraSapcePoints[sampleIndex].Z);

                if (mCameraSapcePoints[sampleIndex].Z >= mWallDepth)
                {
                    newPoint.mWithinWallDepth = true;
                }

                ValidPoints.Add(newPoint);
            }
        }
        return(ValidPoints);
    }
Example #7
0
    void Update()
    {
        if (_MultiManager == null)
        {
            return;
        }

        ushort[] depthData = _MultiManager.GetDepthData();

        if (depthData == null)
        {
            return;
        }
        Message.Instance.SendDepthData(depthData);
        Message.Instance.SendDataSize(depthData.Length);
    }
Example #8
0
    void Update()
    {
        if (_Sensor == null)
        {
            return;
        }

        if (Input.GetButtonDown("Fire1"))
        {
            if (ViewMode == DepthViewMode.MultiSourceReader)
            {
                ViewMode = DepthViewMode.SeparateSourceReaders;
            }
            else
            {
                ViewMode = DepthViewMode.MultiSourceReader;
            }
        }

        float yVal = Input.GetAxis("Horizontal");
        float xVal = -Input.GetAxis("Vertical");

        transform.Rotate(
            (xVal * Time.deltaTime * _Speed),
            (yVal * Time.deltaTime * _Speed),
            0,
            Space.Self);


        if (MultiSourceManager == null)
        {
            return;
        }

        _MultiManager = MultiSourceManager.GetComponent <MultiSourceManager>();
        if (_MultiManager == null)
        {
            return;
        }

        gameObject.GetComponent <Renderer>().material.mainTexture = _MultiManager.GetColorTexture();

        RefreshData(_MultiManager.GetDepthData(),
                    _MultiManager.ColorWidth,
                    _MultiManager.ColorHeight);
    }
    private void Update()
    {
        ControllingTriggerRange();

        _depthData = _multiManager.GetDepthData();

        if (Input.GetKeyDown(KeyCode.Space))
        {
            _wallDepth = DetectingWallDepth();
        }

        if (_wallDepth != null)
        {
            _depthData = FittingDepthDataIntoTriggerRange();

            _triggerPoints = MakeTriggerPoints();
        }
    }
Example #10
0
    public void Update()
    {
        if (freeze)
        {
            return;
        }
        if (_Sensor == null)
        {
            return;
        }

        frameTimeLeft -= Time.deltaTime;
        if (frameTimeLeft > 0.0f)
        {
            return;
        }
        frameTimeLeft += 1.0f / frameRate;


        if (MultiSourceManager == null)
        {
            return;
        }

        _MultiManager = MultiSourceManager.GetComponent <MultiSourceManager>();
        if (_MultiManager == null)
        {
            return;
        }

        if (!_MultiManager.isFresh)
        {
            return;
        }

        //gameObject.GetComponent<Renderer>().material.mainTexture = _MultiManager.GetColorTexture();

        RefreshData(_MultiManager.GetDepthData(),
                    _MultiManager.GetColorData());

        _MultiManager.isFresh = false;
    }
    private void Update()
    {
        mDepthData    = mMultiSource.GetDepthData();
        oldt          = mMultiSource.GetColorTexture();
        mdepthtexture = createtexture();
        //Debug.Log(mDepthData[81795]);

        /*if (check())
         * {
         * //Debug.Log(mDepthData[81795]);
         *  sphere.GetComponent<Renderer>().material = m2;
         *  //Debug.Log("Enter");
         * }
         * else
         * {
         *  sphere.GetComponent<Renderer>().material = m1;
         *  //Debug.Log(mDepthData[81795]);
         *  //Debug.Log(mDepthData[arraySize / 2]);
         *  //Debug.Log("Exit");
         * }*/
    }
Example #12
0
        void Update()
        {
            // Back to main menu
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                UnityEngine.SceneManagement.SceneManager.LoadScene("MainMenu");
            }

            _multiManager = KinectSource.GetComponent <MultiSourceManager>();

            if (_sensor == null || KinectSource == null || _multiManager == null)
            {
                return;
            }

            var depthData = _multiManager.GetDepthData();

            ColorSpacePoint[] colorSpacePoints = new ColorSpacePoint[depthData.Length];
            _mapper.MapDepthFrameToColorSpace(depthData, colorSpacePoints);

            _kinectMesh.LoadDepthData(depthData, _multiManager.GetColorTexture(), colorSpacePoints, _multiManager.ColorWidth, _multiManager.ColorHeight);
        }
Example #13
0
    void Update()
    {
        if (_Sensor == null)
        {
            return;
        }

        if (_MultiManager == null)
        {
            return;
        }


        ushort[] rawdata = _MultiManager.GetDepthData();

        _Mapper.MapDepthFrameToColorSpace(rawdata, _colorSpacePoints);
        _Mapper.MapDepthFrameToCameraSpace(rawdata, _cameraSpacePoints);

        for (int i = 0; i < _cameraSpacePoints.Length; i++)
        {
            vertices[i] = new Vector3(_cameraSpacePoints[i].X, _cameraSpacePoints[i].Y, _cameraSpacePoints[i].Z);
            Colors[i]   = Color.white;
        }
    }
Example #14
0
    // Update is called once per frame
    void Update()
    {
        if (depthManager == null)
        {
            return;
        }

        distances = depthManager.GetDepthData();
        image     = depthManager.GetColorTexture();

        //Debug.Log(image.format);

        /*
         * Image<Gray, byte> depthImage = new Image<Gray, byte>(640, 480);
         * byte[] depthPixelData = new byte[512 * 424];
         * for(int i = 0; i < distances.Length; i++)
         * {
         *  depthPixelData[i] = (byte) (distances[i] / 31.37);
         * }
         * depthImage.Bytes = depthPixelData;
         *
         * Debug.Log(depthImage);
         */
    }
Example #15
0
    void Update()
    {
        if (_Sensor == null)
        {
            return;
        }
        if (MultiSourceManager == null)
        {
            return;
        }
        if (_MultiManager == null)
        {
            return;
        }

        ushort[] rawdata = _MultiManager.GetDepthData();

        _Mapper.MapDepthFrameToCameraSpace(rawdata, cameraSpacePoints);

        for (int i = 0; i < cameraSpacePoints.Length; i++)
        {
            points[i] = new Vector3(cameraSpacePoints[i].X * scale, cameraSpacePoints[i].Y * scale, cameraSpacePoints[i].Z * scale);
        }
    }
Example #16
0
    void Update()
    {
        if (_Sensor == null)
        {
            return;
        }

        if (MultiSourceManager == null)
        {
            return;
        }

        _MultiManager = MultiSourceManager.GetComponent <MultiSourceManager>();
        if (_MultiManager == null)
        {
            return;
        }

        gameObject.GetComponent <Renderer>().material.mainTexture = _MultiManager.GetColorTexture();

        RefreshData(_MultiManager.GetDepthData(),
                    _MultiManager.ColorWidth,
                    _MultiManager.ColorHeight);
    }
Example #17
0
    /* Based on Kinect Coordinate Mapping Basics
     *  Modified by John Densoyers-Stewart
     *  2018-03-28
     */

    void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
    {
        particles.Clear();

        if (MultiSourceManager == null)
        {
            return;
        }

        if (_MultiManager == null)
        {
            return;
        }

        int bodyCount = _Sensor.BodyFrameSource.BodyCount;

        depthFrameData = _MultiManager.GetDepthData();
        bodyIndexData  = _MultiManager.GetBodyIndexData();


        _Mapper.MapDepthFrameToCameraSpace(depthFrameData, cameraSpacePoints);
        _Mapper.MapDepthFrameToColorSpace(depthFrameData, colorSpacePoints);


        if (createParticles)
        {
            for (int x = 0; x < depthWidth; x += downsample)
            {
                for (int y = 0; y < depthHeight; y += downsample)
                {
                    int i = x + (depthWidth * y);
                    CameraSpacePoint p = cameraSpacePoints[i];

                    if (!float.IsNegativeInfinity(p.X) && !float.IsNegativeInfinity(p.Y) && !float.IsNegativeInfinity(p.Z))
                    {
                        if (bodiesOnly)
                        {
                            if (bodyIndexData[i] < bodyCount)
                            {
                                //need to combine this with the other color stuff below to make it work?

                                /*
                                 * ColorSpacePoint colorPoint = colorSpacePoints[i];
                                 *
                                 * byte r = 0;
                                 * byte g = 0;
                                 * byte b = 0;
                                 * byte a = 0;
                                 *
                                 * int colorX = (int)System.Math.Floor(colorPoint.X + 0.5);
                                 * int colorY = (int)System.Math.Floor(colorPoint.Y + 0.5);
                                 *
                                 * if ((colorX >= 0) && (colorX < colorWidth) && (colorY >= 0) && (colorY < colorHeight))
                                 * {
                                 *  int colorIndex = ((colorY * colorWidth) + colorX) * bytesPerPixel;
                                 *  b = colorFrameData[colorIndex++];
                                 *  g = colorFrameData[colorIndex++];
                                 *  r = colorFrameData[colorIndex++];
                                 *  a = colorFrameData[colorIndex++];
                                 * }*/

                                Vector3 particlePos = GetVector3FromCameraSpacePoint(p);

                                if (Vector3.SqrMagnitude(particlePos - transform.InverseTransformPoint(vrHeadset.position)) > headRadiusSquare)
                                {
                                    //particleArray[i].position = particlePos;
                                    //particleArray[i].startColor = color;
                                    //particleArray[i].startSize = size;
                                    //particleArray[i].startLifetime = 1.0f;
                                    ParticleSystem.Particle particle = new ParticleSystem.Particle();
                                    particle.position   = particlePos;
                                    particle.startColor = color; // new Color32(r,g,b,a);
                                    particle.startSize  = size;
                                    particles.Add(particle);
                                }
                            }
                        }
                        else if (noBodies)
                        {
                            if (bodyIndexData[i] > bodyCount)
                            {
                                Vector3 particlePos = GetVector3FromCameraSpacePoint(p);

                                if (Vector3.SqrMagnitude(particlePos - transform.InverseTransformPoint(vrHeadset.position)) > headRadiusSquare)
                                {
                                    //particleArray[i].position = particlePos;
                                    //particleArray[i].startColor = color;
                                    //particleArray[i].startSize = size;

                                    ParticleSystem.Particle particle = new ParticleSystem.Particle();
                                    particle.position   = particlePos;
                                    particle.startColor = color;
                                    particle.startSize  = size;
                                    particles.Add(particle);
                                }
                            }
                        }
                        else
                        {
                            Vector3 particlePos = GetVector3FromCameraSpacePoint(p);

                            if (Vector3.SqrMagnitude(particlePos - transform.InverseTransformPoint(vrHeadset.position)) > headRadiusSquare)
                            {
                                //particleArray[i].position = particlePos;
                                //Debug.Log(particleArray[i].position);
                                //particleArray[i].startColor = color;
                                //particleArray[i].startSize = size;

                                ParticleSystem.Particle particle = new ParticleSystem.Particle();
                                particle.position   = particlePos;
                                particle.startColor = color;
                                particle.startSize  = size;
                                particles.Add(particle);
                            }
                        }
                    }
                }

                /*
                 * float colorMappedToDepthX = colorSpacePoints[colorIndex].X;
                 * float colorMappedToDepthY = colorSpacePoints[colorIndex].Y;
                 *
                 * CameraSpacePoint p = cameraSpacePoints[colorIndex];
                 *
                 * if (!float.IsNegativeInfinity(colorMappedToDepthX) && !float.IsNegativeInfinity(colorMappedToDepthY))
                 * {
                 * int depthX = (int)(colorMappedToDepthX + 0.5f);
                 * int depthY = (int)(colorMappedToDepthY + 0.5f);
                 *
                 * // If the point is not valid, there is no body index there.
                 * if ((depthX >= 0) && (depthX < depthWidth) && (depthY >= 0) && (depthY < depthHeight))
                 * {
                 *     int depthIndex = (depthY * depthWidth) + depthX;
                 *
                 *     //if (bodyIndexData[depthIndex] < bodyCount)
                 *     //{
                 *     if (!float.IsNegativeInfinity(p.X) && !float.IsNegativeInfinity(p.Y) && !float.IsNegativeInfinity(p.Z))
                 *     {
                 *         ParticleSystem.Particle particle = new ParticleSystem.Particle();
                 *         particle.position = new Vector3(-p.X, p.Y, p.Z) * scale;
                 *         particle.startColor = color;
                 *         particle.startSize = size;
                 *         particles.Add(particle);
                 *         //}
                 *     }
                 * }
                 * }*/
            }



            //Debug.Log(_particleSystem.particleCount);


            //particleSystemTimer = Time.time;
            //_particleSystem.SetParticles(particleArray, particleArray.Length);

            if (particles.Count > 0)
            {
                //_particleSystem.SetParticles(particleArray, particleArray.Length);
                _particleSystem.SetParticles(particles.ToArray(), particles.Count);
                particleSystemTimer = Time.time;
            }
        }

        /*if (createMesh)
         * {
         *  KinectMesh.GetComponent<Renderer>().material.mainTexture = _MultiManager.GetColorTexture();
         *
         *  RefreshData(_MultiManager.GetDepthData(), _MultiManager.ColorWidth, _MultiManager.ColorHeight);
         * }*/
    }
Example #18
0
    void Update()
    {
        if (_Sensor == null)
        {
            return;
        }

        /*if (Input.GetButtonDown("Fire1"))
         * {
         *
         *  if (ViewMode == DepthViewMode.MultiSourceReader)
         *  {
         *      ViewMode = DepthViewMode.SeparateSourceReaders;
         *  }
         *  else
         *  {
         *      ViewMode = DepthViewMode.MultiSourceReader;
         *  }
         * }
         *
         * float yVal = Input.GetAxis("Horizontal");
         * float xVal = -Input.GetAxis("Vertical");
         *
         * transform.Rotate(
         *  (xVal * Time.deltaTime * _Speed),
         *  (yVal * Time.deltaTime * _Speed),
         *  0,
         *  Space.Self);*/

        if (ViewMode == DepthViewMode.SeparateSourceReaders)
        {
            if (ColorSourceManager == null)
            {
                return;
            }

            _ColorManager = ColorSourceManager.GetComponent <ColorSourceManager>();
            if (_ColorManager == null)
            {
                return;
            }

            if (DepthSourceManager == null)
            {
                return;
            }

            _DepthManager = DepthSourceManager.GetComponent <DepthSourceManager>();
            if (_DepthManager == null)
            {
                return;
            }

            gameObject.GetComponent <Renderer>().material.mainTexture = _ColorManager.GetColorTexture();
            RefreshData(_DepthManager.GetData(),    //デプスマネージャーからushortのデプスデータ取ってきてる
                        _ColorManager.ColorWidth,
                        _ColorManager.ColorHeight);
        }
        else
        {
            if (MultiSourceManager == null)
            {
                return;
            }

            _MultiManager = MultiSourceManager.GetComponent <MultiSourceManager>();
            if (_MultiManager == null)
            {
                return;
            }

            gameObject.GetComponent <Renderer>().material.mainTexture = _MultiManager.GetColorTexture();

            RefreshData(_MultiManager.GetDepthData(),    //デプスマネージャーからushortのデプスデータ取ってきてる
                        _MultiManager.ColorWidth,
                        _MultiManager.ColorHeight);
        }

        for (int i = 0; i < detectedx.Count; i++)  //複数手判定
        {
            if (hand1x.Count == 0)
            {
                hand1x.Add(detectedx[i]);
                hand1y.Add(detectedy[i]);
            }
            else
            {
                if (Mathf.Abs(detectedx[i] - hand1x[0]) + Mathf.Abs(detectedy[i] - hand1y[0]) < avilabledistance)   //計算量短縮のために二乗を使わないで距離判定
                {
                    hand1x.Add(detectedx[i]);
                    hand1y.Add(detectedy[i]);
                }
                else
                {
                    if (hand2x.Count == 0)
                    {
                        hand2x.Add(detectedx[i]);
                        hand2y.Add(detectedy[i]);
                    }
                    else
                    {
                        if (Mathf.Abs(detectedx[i] - hand2x[0]) + Mathf.Abs(detectedy[i] - hand2y[0]) < avilabledistance)
                        {
                            hand2x.Add(detectedx[i]);
                            hand2y.Add(detectedy[i]);
                        }
                        else
                        {
                            if (hand3x.Count == 0)
                            {
                                hand3x.Add(detectedx[i]);
                                hand3y.Add(detectedy[i]);
                            }
                            else
                            {
                                if (Mathf.Abs(detectedx[i] - hand3x[0]) + Mathf.Abs(detectedy[i] - hand3y[0]) < avilabledistance)
                                {
                                    hand3x.Add(detectedx[i]);
                                    hand3y.Add(detectedy[i]);
                                }
                                else
                                {
                                    if (hand4x.Count == 0)
                                    {
                                        hand4x.Add(detectedx[i]);
                                        hand4y.Add(detectedy[i]);
                                    }
                                    else
                                    {
                                        if (Mathf.Abs(detectedx[i] - hand4x[0]) + Mathf.Abs(detectedy[i] - hand4y[0]) < avilabledistance)
                                        {
                                            hand4x.Add(detectedx[i]);
                                            hand4y.Add(detectedy[i]);
                                        }
                                        else
                                        {
                                            if (hand5x.Count == 0)
                                            {
                                                hand5x.Add(detectedx[i]);
                                                hand5y.Add(detectedy[i]);
                                            }
                                            else
                                            {
                                                if (Mathf.Abs(detectedx[i] - hand5x[0]) + Mathf.Abs(detectedy[i] - hand5y[0]) < avilabledistance)
                                                {
                                                    hand5x.Add(detectedx[i]);
                                                    hand5y.Add(detectedy[i]);
                                                }
                                                else
                                                {
                                                    if (hand6x.Count == 0)
                                                    {
                                                        hand6x.Add(detectedx[i]);
                                                        hand6y.Add(detectedy[i]);
                                                    }
                                                    else
                                                    {
                                                        if (Mathf.Abs(detectedx[i] - hand6x[0]) + Mathf.Abs(detectedy[i] - hand6y[0]) < avilabledistance)
                                                        {
                                                            hand6x.Add(detectedx[i]);
                                                            hand6y.Add(detectedy[i]);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        hand1ave();
        hand2ave();
        hand3ave();
        hand4ave();
        hand5ave();
        hand6ave();

        detectedx.Clear();
        detectedy.Clear();
        hand1x.Clear();
        hand1y.Clear();
        hand2x.Clear();
        hand2y.Clear();
        hand3x.Clear();
        hand3y.Clear();
        hand4x.Clear();
        hand4y.Clear();
        hand5x.Clear();
        hand5y.Clear();
        hand6x.Clear();
        hand6y.Clear();
    }
    // Update is called once per frame
    void Update()
    {
        //Debug.Log("new");
        if (depthManager == null)
        {
            return;
        }

        distances = depthManager.GetDepthData();
        int aktDist = distances[4000];

        /*
         * for(int i = 0; i < distances.Length; i++)
         * {
         *  if(distances[i] < 800 || distances[i] > 1400)
         *  {
         *      distances[i] = 10000;
         *  }
         * }
         */

        //int maxValue;
        //int maxIndex;

        // maxValue = (int) distances.Min();
        // maxIndex = (int) distances.ToList().IndexOf(distances.Min());

        int height = 424;
        int width  = 512;

        float minValue = 10000;
        int   xCoord   = 0;
        int   yCoord   = 0;
        int   index    = 0;

        for (int x = 50; x < width - 50; x++)
        {
            for (int y = 50; y < height - 50; y++)
            {
                if ((minValue > distances[y * width + x]) && (distances[y * width + x] != 0))
                {
                    minValue = distances[y * width + x];
                    index    = y * width + x;
                    xCoord   = x;
                    yCoord   = y;
                    timer    = 0;
                }
            }
        }


        if (!foundHand)
        {
            int[] test     = findPlayerHand(distances, index, minValue, width);
            int   aktHandX = test[0];
            int   aktHandY = test[1];
            int   aktIndex = test[2];

            if (aktHandX != 1 && aktHandY != 0)
            {
                int distanceToLastX = aktHandX - findHandX;
                int distanceToLastY = aktHandY - findHandY;

                if (distanceToLastX >= -10 && distanceToLastX <= 10 && distanceToLastY >= -10 && distanceToLastY <= 10)
                {
                    findHandCounter++;
                    Debug.Log(aktHandX + "," + aktHandY);
                    //Debug.Log("counter up");
                }
            }

            if (findHandCounter >= 25)
            {
                Debug.Log("Found HAND!");
                Debug.Log(findHandX + "," + findHandY);
                findHandIndex = aktIndex;
                foundHand     = true;
                rend.enabled  = true;
            }

            findHandX = aktHandX;
            findHandY = aktHandY;
        }

        /*
         * if(foundHand)
         * {
         *  int[] test2 = trackPlayerHand(distances, findHandIndex, width);
         *
         *  int widthTracking = 512;
         *  float minValueTracking = 10000;
         *  int indexTracking = 0;
         *
         *  for (int i = 0; i < distances.Length; i++)
         *  {
         *      if(!test2.Contains(distances[i]))
         *      {
         *          distances[i] = 10001;
         *      } else
         *      {
         *          if(minValueTracking > distances[i] && distances[i] != 0)
         *          {
         *              minValueTracking = distances[i];
         *              indexTracking = i;
         *              xCoord = indexTracking%widthTracking;
         *              yCoord = indexTracking/widthTracking;
         *              timer = 0;
         *              findHandIndex = indexTracking;
         *          }
         *      }
         *  }
         * }
         *
         * if(xCoord != 0 && yCoord != 0)
         * {
         *  allowMoving = true;
         * } else
         * {
         *  allowMoving = false;
         * }
         *
         */
        xCoord = xCoord - 256;
        yCoord = (yCoord - 212) * 2;

        //Debug.Log("(x,y)= " + xCoord + "," + yCoord);

        if (xCoord < -230)
        {
            xCoord = -230;
        }

        if (xCoord > 230)
        {
            xCoord = 230;
        }

        if (yCoord < -350)
        {
            yCoord = -350;
        }

        if (yCoord > 350)
        {
            yCoord = 350;
        }

        //y-Coord
        // int yCoord = (int)(maxIndex / width);

        //x-Coord
        // int xCoord = (int)(maxIndex % width);
        // Debug.Log("(x,y)= " + xCoord + "," + yCoord);
        //Debug.Log("y= " + yCoord);
        int xCoordOffset = 0;
        int yCoordOffset = 0;

        xCoordOffset = (xCoord - lastXcoord);
        yCoordOffset = (yCoord - lastYcoord);
        //Debug.Log("xOffset = " + xCoordOffset);
        //Debug.Log("yOffset = " + yCoordOffset);

        if (distances == null)
        {
            return;
        }

        /*
         * bool thresholdBottomBool = false;
         * bool thresholdTopBool = false;
         *
         * //Check if Offset is big enough - Rauschunterdrückung
         * if (xCoordOffset > thresholdBottom || xCoordOffset < (thresholdBottom * -1) || yCoordOffset > thresholdBottom || yCoordOffset < (thresholdBottom * -1))
         * {
         *  thresholdBottomBool = true;
         * }
         *
         * //Check if Offest is not too large
         * if ((xCoordOffset < thresholdTop && (xCoordOffset > (thresholdTop * -1))) && (yCoordOffset < thresholdTop && (yCoordOffset > (thresholdTop * -1))))
         * {
         *  thresholdTopBool = true;
         * }
         *
         * //if is in between thresholds
         * if (thresholdTopBool && thresholdBottomBool)
         * {
         *  lastXcoord = xCoord;
         *  lastYcoord = yCoord;
         *  //Debug.Log(xCoordOffset + " xOffset");
         *  Debug.Log(yCoordOffset + " yOffset");
         *  timer = 0;
         *  //Debug.Log("Timer reset");
         * }
         */


        /*
         * int offset = (lastDist - aktDist) * 2;
         * if(offset > 400)
         * {
         *  offset = 500;
         * }
         *
         * lastDist = aktDist;
         */
        //Debug.Log(offset);

        if (allowMoving)
        {
            Vector3 oldPos = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z);
            Vector3 newPos = new Vector3(xCoord, gameObject.transform.position.y, yCoord);
            //Debug.Log("newPos: x=" + newPos.x + " z=" + newPos.z);
            timer += Time.deltaTime;
            transform.position = Vector3.Lerp(oldPos, newPos, timer / latency);
        }

        /*
         * //Vector3 newPos = new Vector3(gameObject.transform.position.x + xCoordOffset, 0, gameObject.transform.position.z + yCoordOffset);
         * float newZCoord = gameObject.transform.position.z + (xCoordOffset * 2);
         * if(newZCoord > 310 || newZCoord < -310)
         * {
         *  if(newZCoord >= 0)
         *  {
         *      newZCoord = 310;
         *  }
         *  else
         *  {
         *      newZCoord = -310;
         *  }
         *  //Debug.Log("yOffset FIX!");
         * }
         */
        /*
         * if (thresholdTopBool && thresholdBottomBool)
         * {
         *  //gameObject.transform.position = Vector3.Lerp(oldPos, newPos, latency * Time.deltaTime);
         *  //gameObject.transform.position = Vector3.Lerp(oldPos, newPos, 2);
         *  //gameObject.transform.position = Vector3.MoveTowards(oldPos, newPos, latency * Time.deltaTime);
         *  //gameObject.transform.position = newPos;
         *  timer += Time.deltaTime;
         *  Debug.Log("Lerping");
         *  //Debug.Log(Time.deltaTime + " delta");
         *  //Debug.Log(timer + " timer");
         *  transform.position = Vector3.Lerp(oldPos, newPos, timer / latency);
         * }
         */
    }
Example #20
0
    void Update()
    {
        if (_Sensor == null)
        {
            return;
        }
        if (MultiSourceManager == null)
        {
            return;
        }

        _MultiManager = MultiSourceManager.GetComponent <MultiSourceManager>();

        if (_MultiManager == null)
        {
            return;
        }

        depthFrameData = _MultiManager.GetDepthData();

        _Mapper.MapDepthFrameToCameraSpace(depthFrameData, cameraSpacePoints);
        //_Mapper.MapDepthFrameToColorSpace(depthFrameData, colorSpacePoints);


        int particleCount = 0;

        for (int y = 0; y < depthHeight; y += 2)
        {
            for (int x = 0; x < depthWidth; x += 2)
            {
                int depthIndex     = (y * depthWidth) + x;
                CameraSpacePoint p = cameraSpacePoints[depthIndex];

                /*ColorSpacePoint colorPoint = colorSpacePoints[depthIndex];
                 *
                 * byte r = 0;
                 * byte g = 0;
                 * byte b = 0;
                 * byte a = 0;
                 *
                 * int colorX = (int)System.Math.Floor(colorPoint.X + 0.5);
                 * int colorY = (int)System.Math.Floor(colorPoint.Y + 0.5);
                 *
                 * if ((colorX >= 0) && (colorX < colorWidth) && (colorY >= 0) && (colorY < colorHeight))
                 * {
                 *  int colorIndex = ((colorY * colorWidth) + colorX) * bytesPerPixel;
                 *  int displayIndex = depthIndex * bytesPerPixel;
                 *  b = colorFrameData[colorIndex++];
                 *  g = colorFrameData[colorIndex++];
                 *  r = colorFrameData[colorIndex++];
                 *  a = colorFrameData[colorIndex++];
                 * }*/

                if (!(double.IsInfinity(p.X)) && !(double.IsInfinity(p.Y)) && !(double.IsInfinity(p.Z)))
                {
                    //if (p.X < 3.0 && p.Y < 3.0 && p.Z < 3.0)
                    //{
                    particles[particleCount].position = new Vector3(p.X * scale, p.Y * scale, p.Z * scale);
                    //particles[particleCount].startColor = new Color(r / 255F, g / 255F, b / 255F, a / 255F);
                    particles[particleCount].startColor = color;
                    particles[particleCount].startSize  = size;
                    particleCount++;
                    //}
                }
            }

            _particleSystem = gameObject.GetComponent <ParticleSystem>();
            _particleSystem.SetParticles(particles, particles.Length);
        }

        StartCoroutine("Delay");
    }
    void Update()
    {
        if (MultiSourceManager == null)
        {
            return;
        }

        _MultiManager = MultiSourceManager.GetComponent <MultiSourceManager>();
        if (_MultiManager == null)
        {
            return;
        }

        if (DepthSourceView == null)
        {
            return;
        }

        _SourceView = DepthSourceView.GetComponent <DepthSourceView>();
        if (_SourceView == null)
        {
            return;
        }

        if (_MultiManager.isReaderClosed())
        {
            return;
        }

        _DepthData = _MultiManager.GetDepthData();
        if (_DepthData == null)
        {
            return;
        }


        _ColorSpace = _SourceView.GetColorSpace();
        if (_ColorSpace == null)
        {
            return;
        }

        _ColorData = _MultiManager.GetColorData();
        if (_ColorData == null)
        {
            return;
        }

        _ColorTexture = _MultiManager.GetColorTexture();
        if (_ColorTexture == null)
        {
            return;
        }

        ColorWidth = _MultiManager.ColorWidth;
        if (ColorWidth == 0)
        {
            return;
        }

        ColorHeight = _MultiManager.ColorHeight;
        if (ColorHeight == 0)
        {
            return;
        }

        //CustomMessages2.Instance.SendGeneralData(_MultiManager.ColorWidth, _MultiManager.ColorHeight);

        //CustomMessages2.Instance.SendWidth(_MultiManager.ColorWidth);
        //CustomMessages2.Instance.SendHeight(_MultiManager.ColorHeight);
        //Debug.Log("_DepthData.Length:" + _DepthData.Length);
        //CustomMessages2.Instance.Send(MsgTag.LENGTH, _DepthData.Length);
        //CustomMessages2.Instance.Send(MsgTag.COLOR_WIDTH, ColorWidth);
        //CustomMessages2.Instance.Send(MsgTag.COLOR_HEIGHT, ColorHeight);
        //Debug.Log("_colorspace.Length in sender is/...........:" + _ColorSpace.Length);

        //if (Time.fixedTime >= timeToGo)
        //Debug.Log("counter before if is: " + Counter);
        if (Counter % 60 == 0)
        {
            //Debug.Log("counter in if is: " + Counter);
            CustomMessages2.Instance.SendDepthData(MsgTag.DEPTH, _DepthData);
            CustomMessages2.Instance.SendColorData(MsgTag.COLOR, _ColorData);
            CustomMessages2.Instance.SendColorSpace(MsgTag.COLORSPACE, _ColorSpace);
            //timeToGo = Time.fixedTime + 0.01f;


            //Thread.Sleep(500);


            //Debug.Log("_Daepthdata in sender is" + _DepthData);

            /*
             * Debug.Log("DSPWidth: " + _MultiManager.DSPWidth);
             * Debug.Log("DSPHeight: " + _MultiManager.DSPHeight);*/

            //CustomMessagesPointCloud.Instance.SendColorData(_ColorData);
        }
        Counter++;
    }
    void Update()
    {
        if (_Sensor == null)
        {
            return;
        }
        //點擊滑鼠右鍵切換單組資源配置或是多組資源配置。
        if (Input.GetButtonDown("Fire1"))
        {
            if (ViewMode == DepthViewMode.MultiSourceReader)
            {
                ViewMode = DepthViewMode.SeparateSourceReaders;
            }
            else
            {
                ViewMode = DepthViewMode.MultiSourceReader;
            }
        }
        //使用上下左右鍵旋轉Mesh物件。
        float yVal = Input.GetAxis("Horizontal");
        float xVal = -Input.GetAxis("Vertical");

        transform.Rotate(
            (xVal * Time.deltaTime * _Speed),
            (yVal * Time.deltaTime * _Speed),
            0,
            Space.Self);
        //如果切換到了單組資源配置的執行工作。
        if (ViewMode == DepthViewMode.SeparateSourceReaders)
        {
            if (ColorSourceManager == null)
            {
                return;
            }

            _ColorManager = ColorSourceManager.GetComponent <ColorSourceManager>();
            if (_ColorManager == null)
            {
                return;
            }

            if (DepthSourceManager == null)
            {
                return;
            }

            _DepthManager = DepthSourceManager.GetComponent <DepthSourceManager>();
            if (_DepthManager == null)
            {
                return;
            }

            gameObject.renderer.material.mainTexture = _ColorManager.GetColorTexture();
            RefreshData(_DepthManager.GetData(),
                        _ColorManager.ColorWidth,
                        _ColorManager.ColorHeight);
        }
        else        //如果切換到了多組資源配置的執行工作。
        {
            if (MultiSourceManager == null)
            {
                return;
            }

            _MultiManager = MultiSourceManager.GetComponent <MultiSourceManager>();
            if (_MultiManager == null)
            {
                return;
            }

            gameObject.renderer.material.mainTexture = _MultiManager.GetColorTexture();

            RefreshData(_MultiManager.GetDepthData(),
                        _MultiManager.ColorWidth,
                        _MultiManager.ColorHeight);
        }
    }
    void Update()
    {
        if (_Sensor == null)
        {
            return;
        }
        //點擊滑鼠右鍵切換單組資源配置或是多組資源配置。
        if (Input.GetButtonDown("Fire1"))
        {
            if(ViewMode == DepthViewMode.MultiSourceReader)
            {
                ViewMode = DepthViewMode.SeparateSourceReaders;
            }
            else
            {
                ViewMode = DepthViewMode.MultiSourceReader;
            }
        }
        //使用上下左右鍵旋轉Mesh物件。
        float yVal = Input.GetAxis("Horizontal");
        float xVal = -Input.GetAxis("Vertical");

        transform.Rotate(
            (xVal * Time.deltaTime * _Speed),
            (yVal * Time.deltaTime * _Speed),
            0,
            Space.Self);
        //如果切換到了單組資源配置的執行工作。
        if (ViewMode == DepthViewMode.SeparateSourceReaders)
        {
            if (ColorSourceManager == null)
            {
                return;
            }

            _ColorManager = ColorSourceManager.GetComponent<ColorSourceManager>();
            if (_ColorManager == null)
            {
                return;
            }

            if (DepthSourceManager == null)
            {
                return;
            }

            _DepthManager = DepthSourceManager.GetComponent<DepthSourceManager>();
            if (_DepthManager == null)
            {
                return;
            }

            gameObject.renderer.material.mainTexture = _ColorManager.GetColorTexture();
            RefreshData(_DepthManager.GetData(),
                _ColorManager.ColorWidth,
                _ColorManager.ColorHeight);
        }
        else//如果切換到了多組資源配置的執行工作。
        {
            if (MultiSourceManager == null)
            {
                return;
            }

            _MultiManager = MultiSourceManager.GetComponent<MultiSourceManager>();
            if (_MultiManager == null)
            {
                return;
            }

            gameObject.renderer.material.mainTexture = _MultiManager.GetColorTexture();

            RefreshData(_MultiManager.GetDepthData(),
                        _MultiManager.ColorWidth,
                        _MultiManager.ColorHeight);
        }
    }
Example #24
0
    void Update()
    {
        if (_Sensor == null)
        {
            return;
        }



        if (Input.GetButtonDown("Fire1"))
        {
            if (updateTerrain == true)
            {
                updateTerrain = false;
            }
            else
            {
                updateTerrain = true;
            }
        }
//
//
//
//            if(ViewMode == DepthViewMode.MultiSourceReader)
//            {
//                ViewMode = DepthViewMode.SeparateSourceReaders;
//            }
//            else
//            {
//                ViewMode = DepthViewMode.MultiSourceReader;
//            }
//        }

        float yVal = Input.GetAxis("Horizontal");
        float xVal = -Input.GetAxis("Vertical");

        //transform.Rotate (xVal, yVal, 0.0f);

        if (updateTerrain == true)
        {
            if (ViewMode == DepthViewMode.SeparateSourceReaders)
            {
                if (ColorSourceManager == null)
                {
                    return;
                }

                _ColorManager = ColorSourceManager.GetComponent <ColorSourceManager>();
                if (_ColorManager == null)
                {
                    return;
                }

                if (DepthSourceManager == null)
                {
                    return;
                }

                _DepthManager = DepthSourceManager.GetComponent <DepthSourceManager>();
                if (_DepthManager == null)
                {
                    return;
                }

                gameObject.GetComponent <Renderer>().material.mainTexture = _ColorManager.GetColorTexture();
                RefreshData(_DepthManager.GetData(),
                            _ColorManager.ColorWidth,
                            _ColorManager.ColorHeight);
            }
            else
            {
                if (MultiSourceManager == null)
                {
                    return;
                }

                _MultiManager = MultiSourceManager.GetComponent <MultiSourceManager>();
                if (_MultiManager == null)
                {
                    return;
                }

                gameObject.GetComponent <Renderer>().material.mainTexture = _MultiManager.GetColorTexture();

                RefreshData(_MultiManager.GetDepthData(),
                            _MultiManager.ColorWidth,
                            _MultiManager.ColorHeight);
            }
        }
        UpdateTransform();
    }