Пример #1
0
    // Use this for initialization
    void Start()
    {
        _depthManager   = depthManager.GetComponent <DepthManager> ();
        _nodeController = nodeController.GetComponent <NodeController> ();
        _depthData      = _depthManager.GetData();

        // create an array of rows for the depth data
        orderedDepthData = createOrderedDepthData(_depthData);
        heightThreshold  = (ushort)7000;
    }
Пример #2
0
 //Add frame into the list of buffer frames ready to be smoothed
 private void AddFrame()
 {
     if (current < delay)
     {
         ushort[] data = new ushort[formatLength];
         data = _depthManager.GetData();
         //Buffer frames are not yet filled, no average is taken
         for (int i = 0; i < formatLength; i++)
         {
             buffer [current, i] = data [i];
         }
         current++;
     }
     else
     {
         //After the frame has been fill, new pop in is needed pop out is needed, average calculated
         //print ("reset!");
         //print(current);
         current = 0;
     }
 }
Пример #3
0
    // 526 by 412

    // Update is called once per frame
    void Update()
    {
        //place buffer
        if (currentFrame == finalFrame && snapShotTaken == true)
        {
            _depthData       = _depthManager.GetData();
            orderedDepthData = createOrderedDepthData(_depthData);
            smoothDepthData  = createSmoothDepthArray(orderedDepthData);
            currentFrame     = 0;

            for (int y = 0; y < smoothDepthData.Length; y++)
            {
                for (int x = 0; x < smoothDepthData[y].Length; x++)
                {
                    if (smoothDepthData[y][x] > (ushort)((ushort)snapShot[y][x] + (ushort)heightThreshold))
                    {
                        _nodeController.createNode(generateNodePosition(x, y));
                    }
                }
            }
            //print("stupidass " + (ushort)((ushort)7000 + (ushort)2000));
        }
        else
        {
            currentFrame++;
        }
        //print ("curr" + currentFrame + "snaptaken: " + snapShotTaken);



        // Used for generating level snapshot
        if (Input.GetKeyDown("s"))
        {
            _depthData = _depthManager.GetData();
            print("S has been pressed");
            orderedDepthData = createOrderedDepthData(_depthData);
            snapShot         = createSmoothDepthArray(orderedDepthData);
            snapShotTaken    = true;
            currentFrame     = 0;
        }

        if (Input.GetKeyDown("m"))
        {
            print("m key is pressed");

            if (_depthData != null)
            {
                print("depth data exists");
            }
            //Path where the file is written. root location is project root
            var path = ".\\testSmooth.txt";
            using (FileStream fs = new FileStream(path, FileMode.Truncate, FileAccess.Write))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    foreach (ushort[] array in snapShot)
                    {
                        foreach (ushort value in array)
                        {
                            sw.Write(Convert.ToString(value) + ",");
                        }
                    }
                }
            }
        }
    }