示例#1
0
 public bool crossesPlane(PointCluster points)
 {
     foreach (DepthPoint pt in points.points)
     {
         if (crossesPlane(pt)) return true;
     }
     return false;
 }
示例#2
0
 public bool crossesPlane(PointCluster points)
 {
     foreach (DepthPoint pt in points.points)
     {
         if (crossesPlane(pt))
         {
             return(true);
         }
     }
     return(false);
 }
示例#3
0
 public static BoundingRectangle CreateBoundingRectangle(PointCluster points)
 {
     Cube cube = CreateBoundingCube(points);
     BoundingRectangle result = new BoundingRectangle();
     for (int i = 0; i < 4; i++)
     {
         for (int j = 0; j < 2; j++)
         {
             result.vertices[i, j] = cube.vertices[i, j];
         }
     }
     return result;
 }
示例#4
0
        public static BoundingRectangle CreateBoundingRectangle(PointCluster points)
        {
            Cube cube = CreateBoundingCube(points);
            BoundingRectangle result = new BoundingRectangle();

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    result.vertices[i, j] = cube.vertices[i, j];
                }
            }
            return(result);
        }
示例#5
0
 /// <summary>
 /// NOT a flood fill, standin for testing
 /// </summary>
 /// <param name="depthData"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="mmCutoff"></param>
 /// <returns></returns>
 public static PointCluster FloodFill(DepthImagePixel[] depthData, int x, int y, int width, int height, int mmCutoff)
 {
     HashSet<DepthPoint> resultPoints = new HashSet<DepthPoint>();
     for (int i = 0; i < depthData.Length; i++)
     {
         if (resultPoints.Count > MAX_PIXELS)
             break;
         if (depthData[i].Depth > 400 && depthData[i].Depth < 4000 && depthData[i].Depth < 1000)
         {
             int xIdx = i % width;
             int yIdx = i / width;
             resultPoints.Add(new DepthPoint(xIdx, yIdx, depthData[i].Depth));
         }
     }
     PointCluster result = new PointCluster(resultPoints);
     //Console.WriteLine("Before pruning: " + result.points.Count);
     result.Prune();
     return result;
 }
示例#6
0
        internal void GiveFrame(DepthImageFrame depthFrame, PointCluster floodFill)
        {
            short[] imagePixelData = new short[depthFrame.PixelDataLength];
            depthFrame.CopyPixelDataTo(imagePixelData);

            float RenderWidth  = 640.0f;
            float RenderHeight = 480.0f;

            Bitmap bmap = new System.Drawing.Bitmap(depthFrame.Width, depthFrame.Height, System.Drawing.Imaging.PixelFormat.Format16bppRgb555);

            System.Drawing.Imaging.BitmapData bmapdata = bmap.LockBits(new System.Drawing.Rectangle(0, 0, depthFrame.Width
                                                                                                    , depthFrame.Height), ImageLockMode.WriteOnly, bmap.PixelFormat);
            IntPtr ptr = bmapdata.Scan0;

            System.Runtime.InteropServices.Marshal.Copy(imagePixelData, 0, ptr, depthFrame.Width * depthFrame.Height);
            bmap.UnlockBits(bmapdata);

            /*System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmap);
             * this.myImageBox.Source =
             * System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
             *  bmap.GetHbitmap(),
             *  IntPtr.Zero,
             *  System.Windows.Int32Rect.Empty,
             *  BitmapSizeOptions.FromWidthAndHeight((int)this.myImageBox.Width, (int)this.myImageBox.Height));*/

            using (DrawingContext lfdc = drawingGroup.Open())//this.liveFeedbackGroup.Open())
            {
                lfdc.DrawImage(System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                                   bmap.GetHbitmap(),
                                   IntPtr.Zero,
                                   System.Windows.Int32Rect.Empty,
                                   BitmapSizeOptions.FromWidthAndHeight((int)RenderWidth, (int)RenderHeight)),
                               //BitmapSizeOptions.FromWidthAndHeight((int)this.myImageBox.ActualWidth, (int)this.myImageBox.ActualHeight)),
                               new Rect(0.0, 0.0, RenderWidth, RenderHeight));

                foreach (DepthPoint point in floodFill.points)
                {
                    lfdc.DrawRoundedRectangle(System.Windows.Media.Brushes.Red, null, new Rect(point.x, point.y, 3, 3), null, 1, null, 1, null);
                }
            }
        }
        internal void GiveFrame(DepthImageFrame depthFrame, PointCluster floodFill)
        {
            short[] imagePixelData = new short[depthFrame.PixelDataLength];
            depthFrame.CopyPixelDataTo(imagePixelData);

            float RenderWidth = 640.0f;
            float RenderHeight = 480.0f;

            Bitmap bmap = new System.Drawing.Bitmap(depthFrame.Width, depthFrame.Height, System.Drawing.Imaging.PixelFormat.Format16bppRgb555);
            System.Drawing.Imaging.BitmapData bmapdata = bmap.LockBits(new System.Drawing.Rectangle(0, 0, depthFrame.Width
                , depthFrame.Height), ImageLockMode.WriteOnly, bmap.PixelFormat);
            IntPtr ptr = bmapdata.Scan0;
            System.Runtime.InteropServices.Marshal.Copy(imagePixelData, 0, ptr, depthFrame.Width * depthFrame.Height);
            bmap.UnlockBits(bmapdata);
            /*System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmap);
            this.myImageBox.Source =
            System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                bmap.GetHbitmap(),
                IntPtr.Zero,
                System.Windows.Int32Rect.Empty,
                BitmapSizeOptions.FromWidthAndHeight((int)this.myImageBox.Width, (int)this.myImageBox.Height));*/

            using (DrawingContext lfdc = drawingGroup.Open())//this.liveFeedbackGroup.Open())
            {
                lfdc.DrawImage(System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                    bmap.GetHbitmap(),
                    IntPtr.Zero,
                    System.Windows.Int32Rect.Empty,
                    BitmapSizeOptions.FromWidthAndHeight((int)RenderWidth, (int)RenderHeight)),
                    //BitmapSizeOptions.FromWidthAndHeight((int)this.myImageBox.ActualWidth, (int)this.myImageBox.ActualHeight)),
                    new Rect(0.0, 0.0, RenderWidth, RenderHeight));

                foreach (DepthPoint point in floodFill.points)
                {
                    lfdc.DrawRoundedRectangle(System.Windows.Media.Brushes.Red, null, new Rect(point.x, point.y, 3, 3), null, 1, null, 1, null);
                }
            }
        }
示例#8
0
        /// <summary>
        /// NOT a flood fill, standin for testing
        /// </summary>
        /// <param name="depthData"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="mmCutoff"></param>
        /// <returns></returns>
        public static PointCluster FloodFill(DepthImagePixel[] depthData, int x, int y, int width, int height, int mmCutoff)
        {
            HashSet <DepthPoint> resultPoints = new HashSet <DepthPoint>();

            for (int i = 0; i < depthData.Length; i++)
            {
                if (resultPoints.Count > MAX_PIXELS)
                {
                    break;
                }
                if (depthData[i].Depth > 400 && depthData[i].Depth < 4000 && depthData[i].Depth < 1000)
                {
                    int xIdx = i % width;
                    int yIdx = i / width;
                    resultPoints.Add(new DepthPoint(xIdx, yIdx, depthData[i].Depth));
                }
            }
            PointCluster result = new PointCluster(resultPoints);

            //Console.WriteLine("Before pruning: " + result.points.Count);
            result.Prune();
            return(result);
        }
        /// <summary>
        /// Start Siavash
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SensorDepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
        {
            using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
            {
                if (depthFrame != null)
                {
                    this.maxDepth = depthFrame.MaxDepth;
                    this.minDepth = depthFrame.MinDepth;
                    this.closestPoint.Depth = Convert.ToInt16(this.maxDepth);

                    if (this.imagePixelData == null || this.imadeData == null)
                    {
                        this.imadeData = new short[depthFrame.PixelDataLength];
                        this.imagePixelData = new DepthImagePixel[depthFrame.PixelDataLength];
                    }

                    depthFrame.CopyDepthImagePixelDataTo(imagePixelData);
                    depthFrame.CopyPixelDataTo(imadeData);

                    // This cutoff allows us to control how often the closest point is calculated (it doesn't necessarily need to be calculated every frame)
                    closestPointCounter %= CLOSEST_POINT_COUNTER_CUTOFF;
                    if (closestPointCounter == 0)
                    {
                        findTheClosestPoint(depthFrame.PixelDataLength, depthFrame.Width, depthFrame.Height);
                    }
                    closestPointCounter++;

                    // Flood fill from this point then send a point to the distributor

                    // If the nearest point hasn't broken the plane, then don't bother doing anything with it

                    // The array index is computed as x + y*width,
                    // So x = idx % width
                    // y = (idx - x)/width
                    int xIdx = this.pixelIndex % depthFrame.Width;
                    int yIdx = this.pixelIndex / depthFrame.Width;

                    myPointCluster = ThreeDAuth.Util.FloodFill2(imagePixelData, xIdx, yIdx, depthFrame.Width, depthFrame.Height - 1, DEPTH_CUTOFF);
                    ThreeDAuth.DepthPoint centroid = myPointCluster.Centroid;

                    // send centroid to filter and draw if valid
                    int counter = 0;
                    while (myPointCluster.points.Count < 50 && counter < 20)
                    {
                        imagePixelData[pixelIndex].Depth = short.MaxValue;
                        counter++;

                        findTheClosestPoint(depthFrame.PixelDataLength, depthFrame.Width, depthFrame.Height);
                        xIdx = this.pixelIndex % depthFrame.Width;
                        yIdx = this.pixelIndex / depthFrame.Width;

                        myPointCluster = ThreeDAuth.Util.FloodFill2(imagePixelData, xIdx, yIdx, depthFrame.Width, depthFrame.Height - 1, DEPTH_CUTOFF);
                        centroid = myPointCluster.Centroid;
                    }
                    if (counter < 20)
                    {
                        using (DrawingContext dc = this.liveFeedbackGroup.Open())
                        {
                            drawHands(dc, centroid, positionMotionFilter.IsValidPoint(centroid), depthFrame);
                        }
                    }
                    //showDepthView(depthFrame, depthFrame.Width, depthFrame.Height,centroid);
                    //pDistributor.GivePoint(centroid);

                    //Console.WriteLine("Centroid: " + centroid);
                    //ThreeDAuth.PointDistributor.SGivePoint(centroid);
                }
            }
        }
示例#10
0
        /// <summary>
        /// DO NOT REMOVE
        /// </summary>
        /// <param name="depthData"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="mmCutoff"></param>
        /// <returns></returns>
        public static PointCluster FloodFill2(DepthImagePixel[] depthData, int x, int y, int width, int height)
        {
            // Queue of tuples storing <newX, newY, previousDepth>
            int mmCutoff = HandTrackingOptionSet.FloodFillDepth;
            Queue<Tuple<int, int, DepthImagePixel>> explorePoints = new Queue<Tuple<int, int, DepthImagePixel>>();
            HashSet<Tuple<int, int>> exploredPoints = new HashSet<Tuple<int,int>>();
            HashSet<DepthPoint> resultPoints = new HashSet<DepthPoint>();

            int jumpdistance = 2;

            // Filtering on points
            // throw out anything closer than 400 and farther than 4000?

            explorePoints.Enqueue(new Tuple<int, int, DepthImagePixel>(x, y, depthData[x + y * width]));
            exploredPoints.Add(new Tuple<int, int>(x, y));
            float baseDepth = depthData[x + y * width].Depth;
            //Console.WriteLine("Base Depth: " + baseDepth);
            while (explorePoints.Count > 0 && resultPoints.Count < MAX_PIXELS)
            {
                Tuple<int, int, DepthImagePixel> currentPoint = explorePoints.Dequeue();
                DepthImagePixel currentDepth = depthData[currentPoint.Item1 + currentPoint.Item2 * width];
                if (//Math.Abs(currentDepth.Depth - currentPoint.Item3.Depth) < mmCutoff &&
                    Math.Abs(currentDepth.Depth - baseDepth) < mmCutoff &&
                    Math.Abs(currentPoint.Item1 - x) < PIXEL_WIDTH_EPSILON && Math.Abs(currentPoint.Item2 - y) < PIXEL_HEIGHT_EPSILON)
                {
                    resultPoints.Add(new DepthPoint(currentPoint.Item1, currentPoint.Item2, currentDepth.Depth));

                    // Add the neighboring points to be explored

                    Tuple<int, int, DepthImagePixel> leftNeighbor = new Tuple<int, int, DepthImagePixel>(currentPoint.Item1 - jumpdistance, currentPoint.Item2, currentDepth);
                    Tuple<int, int, DepthImagePixel> rightNeighbor = new Tuple<int, int, DepthImagePixel>(currentPoint.Item1 + jumpdistance, currentPoint.Item2, currentDepth);
                    Tuple<int, int, DepthImagePixel> topNeighbor = new Tuple<int, int, DepthImagePixel>(currentPoint.Item1, currentPoint.Item2 + jumpdistance, currentDepth);
                    Tuple<int, int, DepthImagePixel> bottomNeighbor = new Tuple<int, int, DepthImagePixel>(currentPoint.Item1, currentPoint.Item2 - jumpdistance, currentDepth);

                    Tuple<int, int> leftNeighborPoint = new Tuple<int, int>(currentPoint.Item1 - jumpdistance, currentPoint.Item2);
                    Tuple<int, int> rightNeighborPoint = new Tuple<int, int>(currentPoint.Item1 + jumpdistance, currentPoint.Item2);
                    Tuple<int, int> topNeighborPoint = new Tuple<int, int>(currentPoint.Item1, currentPoint.Item2 + jumpdistance);
                    Tuple<int, int> bottomNeighborPoint = new Tuple<int, int>(currentPoint.Item1, currentPoint.Item2 - jumpdistance);

                    /*
                    Tuple<int, int, DepthImagePixel> leftNeighbor = new Tuple<int, int, DepthImagePixel>(currentPoint.Item1 - 1, currentPoint.Item2, currentDepth);
                    Tuple<int, int, DepthImagePixel> rightNeighbor = new Tuple<int, int, DepthImagePixel>(currentPoint.Item1 + 1, currentPoint.Item2, currentDepth);
                    Tuple<int, int, DepthImagePixel> topNeighbor = new Tuple<int, int, DepthImagePixel>(currentPoint.Item1, currentPoint.Item2 + 1, currentDepth);
                    Tuple<int, int, DepthImagePixel> bottomNeighbor = new Tuple<int, int, DepthImagePixel>(currentPoint.Item1, currentPoint.Item2 - 1, currentDepth);

                    Tuple<int, int> leftNeighborPoint = new Tuple<int, int>(currentPoint.Item1 - 1, currentPoint.Item2);
                    Tuple<int, int> rightNeighborPoint = new Tuple<int, int>(currentPoint.Item1 + 1, currentPoint.Item2);
                    Tuple<int, int> topNeighborPoint = new Tuple<int, int>(currentPoint.Item1, currentPoint.Item2 + 1);
                    Tuple<int, int> bottomNeighborPoint = new Tuple<int, int>(currentPoint.Item1, currentPoint.Item2 - 1);
                    */
                    if (leftNeighbor.Item1 >= 0 && !exploredPoints.Contains(leftNeighborPoint))
                    {
                        exploredPoints.Add(leftNeighborPoint);
                        explorePoints.Enqueue(leftNeighbor);
                    }
                    if (rightNeighbor.Item1 < width && !exploredPoints.Contains(rightNeighborPoint))
                    {
                        exploredPoints.Add(rightNeighborPoint);
                        explorePoints.Enqueue(rightNeighbor);
                    }
                    if (topNeighbor.Item2 < height && !exploredPoints.Contains(topNeighborPoint))
                    {
                        exploredPoints.Add(topNeighborPoint);
                        explorePoints.Enqueue(topNeighbor);
                    }
                    if (bottomNeighbor.Item2 >= 0 && !exploredPoints.Contains(bottomNeighborPoint))
                    {
                        exploredPoints.Add(bottomNeighborPoint);
                        explorePoints.Enqueue(bottomNeighbor);
                    }
                }
            }
            PointCluster result = new PointCluster(resultPoints);
            result.Prune();
            //exploredPoints.Clear();
            //explorePoints.Clear();
            return result;
        }
示例#11
0
        public static Cube CreateBoundingCube(PointCluster points)
        {
            // Start all the vertices out at the first point then grow them accordingly
            Cube boundingCube = new Cube();
            bool initialized = false;
            foreach (DepthPoint point in points.points)
            {
                if (!initialized)
                {
                    initialized = true;
                    for (int i = 0; i < 8; i++)
                    {
                        boundingCube.vertices[i, 0] = point.x;
                        boundingCube.vertices[i, 1] = point.y;
                        boundingCube.vertices[i, 2] = point.depth;
                    }
                }
                else
                {
                    if (point.x < boundingCube.vertices[0, 0])
                    {
                        boundingCube.vertices[0, 0] = point.x;
                        boundingCube.vertices[3, 0] = point.x;
                        boundingCube.vertices[4, 0] = point.x;
                        boundingCube.vertices[7, 0] = point.x;
                    }
                    else if (point.x > boundingCube.vertices[1, 0])
                    {
                        boundingCube.vertices[1, 0] = point.x;
                        boundingCube.vertices[2, 0] = point.x;
                        boundingCube.vertices[5, 0] = point.x;
                        boundingCube.vertices[6, 0] = point.x;
                    }

                    if (point.y < boundingCube.vertices[2, 1])
                    {
                        boundingCube.vertices[2, 1] = point.y;
                        boundingCube.vertices[3, 1] = point.y;
                        boundingCube.vertices[6, 1] = point.y;
                        boundingCube.vertices[7, 1] = point.y;
                    }
                    else if (point.y > boundingCube.vertices[0, 1])
                    {
                        boundingCube.vertices[0, 1] = point.y;
                        boundingCube.vertices[1, 1] = point.y;
                        boundingCube.vertices[4, 1] = point.y;
                        boundingCube.vertices[5, 1] = point.y;
                    }

                    if (point.depth < boundingCube.vertices[0, 2])
                    {
                        boundingCube.vertices[1, 2] = point.depth;
                        boundingCube.vertices[2, 2] = point.depth;
                        boundingCube.vertices[3, 2] = point.depth;
                        boundingCube.vertices[4, 2] = point.depth;
                    }

                    if (point.depth > boundingCube.vertices[4, 2])
                    {
                        boundingCube.vertices[4, 2] = point.depth;
                        boundingCube.vertices[5, 2] = point.depth;
                        boundingCube.vertices[6, 2] = point.depth;
                        boundingCube.vertices[7, 2] = point.depth;
                    }
                }
            }

            return boundingCube;
        }
示例#12
0
        /// <summary>
        /// DO NOT REMOVE
        /// </summary>
        /// <param name="depthData"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="mmCutoff"></param>
        /// <returns></returns>
        public static PointCluster FloodFill2(DepthImagePixel[] depthData, int x, int y, int width, int height)
        {
            // Queue of tuples storing <newX, newY, previousDepth>
            int mmCutoff = HandTrackingOptionSet.FloodFillDepth;
            Queue <Tuple <int, int, DepthImagePixel> > explorePoints = new Queue <Tuple <int, int, DepthImagePixel> >();
            HashSet <Tuple <int, int> > exploredPoints = new HashSet <Tuple <int, int> >();
            HashSet <DepthPoint>        resultPoints   = new HashSet <DepthPoint>();

            int jumpdistance = 2;

            // Filtering on points
            // throw out anything closer than 400 and farther than 4000?

            explorePoints.Enqueue(new Tuple <int, int, DepthImagePixel>(x, y, depthData[x + y * width]));
            exploredPoints.Add(new Tuple <int, int>(x, y));
            float baseDepth = depthData[x + y * width].Depth;

            //Console.WriteLine("Base Depth: " + baseDepth);
            while (explorePoints.Count > 0 && resultPoints.Count < MAX_PIXELS)
            {
                Tuple <int, int, DepthImagePixel> currentPoint = explorePoints.Dequeue();
                DepthImagePixel currentDepth = depthData[currentPoint.Item1 + currentPoint.Item2 * width];
                if (//Math.Abs(currentDepth.Depth - currentPoint.Item3.Depth) < mmCutoff &&
                    Math.Abs(currentDepth.Depth - baseDepth) < mmCutoff &&
                    Math.Abs(currentPoint.Item1 - x) < PIXEL_WIDTH_EPSILON && Math.Abs(currentPoint.Item2 - y) < PIXEL_HEIGHT_EPSILON)
                {
                    resultPoints.Add(new DepthPoint(currentPoint.Item1, currentPoint.Item2, currentDepth.Depth));

                    // Add the neighboring points to be explored

                    Tuple <int, int, DepthImagePixel> leftNeighbor   = new Tuple <int, int, DepthImagePixel>(currentPoint.Item1 - jumpdistance, currentPoint.Item2, currentDepth);
                    Tuple <int, int, DepthImagePixel> rightNeighbor  = new Tuple <int, int, DepthImagePixel>(currentPoint.Item1 + jumpdistance, currentPoint.Item2, currentDepth);
                    Tuple <int, int, DepthImagePixel> topNeighbor    = new Tuple <int, int, DepthImagePixel>(currentPoint.Item1, currentPoint.Item2 + jumpdistance, currentDepth);
                    Tuple <int, int, DepthImagePixel> bottomNeighbor = new Tuple <int, int, DepthImagePixel>(currentPoint.Item1, currentPoint.Item2 - jumpdistance, currentDepth);

                    Tuple <int, int> leftNeighborPoint   = new Tuple <int, int>(currentPoint.Item1 - jumpdistance, currentPoint.Item2);
                    Tuple <int, int> rightNeighborPoint  = new Tuple <int, int>(currentPoint.Item1 + jumpdistance, currentPoint.Item2);
                    Tuple <int, int> topNeighborPoint    = new Tuple <int, int>(currentPoint.Item1, currentPoint.Item2 + jumpdistance);
                    Tuple <int, int> bottomNeighborPoint = new Tuple <int, int>(currentPoint.Item1, currentPoint.Item2 - jumpdistance);

                    /*
                     * Tuple<int, int, DepthImagePixel> leftNeighbor = new Tuple<int, int, DepthImagePixel>(currentPoint.Item1 - 1, currentPoint.Item2, currentDepth);
                     * Tuple<int, int, DepthImagePixel> rightNeighbor = new Tuple<int, int, DepthImagePixel>(currentPoint.Item1 + 1, currentPoint.Item2, currentDepth);
                     * Tuple<int, int, DepthImagePixel> topNeighbor = new Tuple<int, int, DepthImagePixel>(currentPoint.Item1, currentPoint.Item2 + 1, currentDepth);
                     * Tuple<int, int, DepthImagePixel> bottomNeighbor = new Tuple<int, int, DepthImagePixel>(currentPoint.Item1, currentPoint.Item2 - 1, currentDepth);
                     *
                     * Tuple<int, int> leftNeighborPoint = new Tuple<int, int>(currentPoint.Item1 - 1, currentPoint.Item2);
                     * Tuple<int, int> rightNeighborPoint = new Tuple<int, int>(currentPoint.Item1 + 1, currentPoint.Item2);
                     * Tuple<int, int> topNeighborPoint = new Tuple<int, int>(currentPoint.Item1, currentPoint.Item2 + 1);
                     * Tuple<int, int> bottomNeighborPoint = new Tuple<int, int>(currentPoint.Item1, currentPoint.Item2 - 1);
                     */
                    if (leftNeighbor.Item1 >= 0 && !exploredPoints.Contains(leftNeighborPoint))
                    {
                        exploredPoints.Add(leftNeighborPoint);
                        explorePoints.Enqueue(leftNeighbor);
                    }
                    if (rightNeighbor.Item1 < width && !exploredPoints.Contains(rightNeighborPoint))
                    {
                        exploredPoints.Add(rightNeighborPoint);
                        explorePoints.Enqueue(rightNeighbor);
                    }
                    if (topNeighbor.Item2 < height && !exploredPoints.Contains(topNeighborPoint))
                    {
                        exploredPoints.Add(topNeighborPoint);
                        explorePoints.Enqueue(topNeighbor);
                    }
                    if (bottomNeighbor.Item2 >= 0 && !exploredPoints.Contains(bottomNeighborPoint))
                    {
                        exploredPoints.Add(bottomNeighborPoint);
                        explorePoints.Enqueue(bottomNeighbor);
                    }
                }
            }
            PointCluster result = new PointCluster(resultPoints);

            result.Prune();
            //exploredPoints.Clear();
            //explorePoints.Clear();
            return(result);
        }
示例#13
0
        public static Cube CreateBoundingCube(PointCluster points)
        {
            // Start all the vertices out at the first point then grow them accordingly
            Cube boundingCube = new Cube();
            bool initialized  = false;

            foreach (DepthPoint point in points.points)
            {
                if (!initialized)
                {
                    initialized = true;
                    for (int i = 0; i < 8; i++)
                    {
                        boundingCube.vertices[i, 0] = point.x;
                        boundingCube.vertices[i, 1] = point.y;
                        boundingCube.vertices[i, 2] = point.depth;
                    }
                }
                else
                {
                    if (point.x < boundingCube.vertices[0, 0])
                    {
                        boundingCube.vertices[0, 0] = point.x;
                        boundingCube.vertices[3, 0] = point.x;
                        boundingCube.vertices[4, 0] = point.x;
                        boundingCube.vertices[7, 0] = point.x;
                    }
                    else if (point.x > boundingCube.vertices[1, 0])
                    {
                        boundingCube.vertices[1, 0] = point.x;
                        boundingCube.vertices[2, 0] = point.x;
                        boundingCube.vertices[5, 0] = point.x;
                        boundingCube.vertices[6, 0] = point.x;
                    }

                    if (point.y < boundingCube.vertices[2, 1])
                    {
                        boundingCube.vertices[2, 1] = point.y;
                        boundingCube.vertices[3, 1] = point.y;
                        boundingCube.vertices[6, 1] = point.y;
                        boundingCube.vertices[7, 1] = point.y;
                    }
                    else if (point.y > boundingCube.vertices[0, 1])
                    {
                        boundingCube.vertices[0, 1] = point.y;
                        boundingCube.vertices[1, 1] = point.y;
                        boundingCube.vertices[4, 1] = point.y;
                        boundingCube.vertices[5, 1] = point.y;
                    }

                    if (point.depth < boundingCube.vertices[0, 2])
                    {
                        boundingCube.vertices[1, 2] = point.depth;
                        boundingCube.vertices[2, 2] = point.depth;
                        boundingCube.vertices[3, 2] = point.depth;
                        boundingCube.vertices[4, 2] = point.depth;
                    }

                    if (point.depth > boundingCube.vertices[4, 2])
                    {
                        boundingCube.vertices[4, 2] = point.depth;
                        boundingCube.vertices[5, 2] = point.depth;
                        boundingCube.vertices[6, 2] = point.depth;
                        boundingCube.vertices[7, 2] = point.depth;
                    }
                }
            }

            return(boundingCube);
        }