Exemplo n.º 1
0
        /// <summary>
        /// Detects and returns edges in a map
        /// </summary>
        public ValueMap DetectEdges(float threshold)
        {
            ValueMap firstPass = CreateInstance <ValueMap>();

            firstPass.Initialize(Width, Height);

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    firstPass[x, y] = 0;

                    for (int i = x - 1; i <= x + 1; i++)
                    {
                        for (int j = y - 1; j <= y + 1; j++)
                        {
                            if (IsInsideBounds(i, j))
                            {
                                if (Mathf.Abs(this[x, y] - this[i, j]) > threshold)
                                {
                                    firstPass[x, y] = 1;
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            ValueMap secondPass = CreateInstance <ValueMap>();

            secondPass.Initialize(Width, Height);

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    if (firstPass.CountItemsInRegion(new Vector2Int(x - 1, y - 1), new Vector2Int(x + 1, y + 1), 1) > 8)
                    {
                        secondPass[x, y] = 0;
                    }
                    else
                    {
                        secondPass[x, y] = firstPass[x, y];
                    }
                }
            }

            return(secondPass);
        }