Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="other"></param>
        public Grid2d(Grid2d other)
        {
            _dx = other._dx;
            _dy = other._dy;

            _tx = other._tx;
            _ty = other._ty;

            _txInv = other._txInv;
            _tyInv = other._tyInv;

            _nx  = other._nx;
            _ny  = other._ny;
            _nxy = other._nxy;

            _wrapX = other._wrapX;
            _wrapY = other._wrapY;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calculates the L1 (Manhattan) geodesic distance from the given sources.
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="sources"></param>
        /// <param name="result"></param>
        /// <param name="exclude"></param>
        public static void CalculateL1(Grid2d grid, IEnumerable <int> sources, double[] result, IEnumerable <int> exclude = null)
        {
            // impl ref
            // http://www.numerical-tours.com/matlab/fastmarching_0_implementing/

            (var nx, var ny) = grid.Count;
            (var dx, var dy) = Vector2d.Abs(grid.Scale);

            var queue = new Queue <int>();

            result.SetRange(double.PositiveInfinity, grid.CountXY);

            // enqueue sources
            foreach (int i in sources)
            {
                result[i] = 0.0;
                queue.Enqueue(i);
            }

            // exclude
            if (exclude != null)
            {
                foreach (int i in exclude)
                {
                    result[i] = 0.0;
                }
            }

            // breadth first search from sources
            while (queue.Count > 0)
            {
                int i0 = queue.Dequeue();
                var d0 = result[i0];

                (int x0, int y0) = grid.ToGridSpace(i0);

                // -x
                if (x0 > 0)
                {
                    TryUpdate(d0 + dx, i0 - 1);
                }

                // +x
                if (x0 < nx - 1)
                {
                    TryUpdate(d0 + dx, i0 + 1);
                }

                // -y
                if (y0 > 0)
                {
                    TryUpdate(d0 + dy, i0 - nx);
                }

                // +y
                if (y0 < ny - 1)
                {
                    TryUpdate(d0 + dy, i0 + nx);
                }

                // add to queue if less than current min
                void TryUpdate(double distance, int index)
                {
                    if (distance < result[index])
                    {
                        result[index] = distance;
                        queue.Enqueue(index);
                    }
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 public GridField2dDouble(Grid2d other)
     : base(other)
 {
 }
Exemplo n.º 4
0
 /// <inheritdoc />
 public override GridField2d <double> Create(Grid2d grid)
 {
     return(new GridField2dDouble(grid));
 }
Exemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 public GridField2dVector2d(Grid2d other)
     : base(other)
 {
 }
Exemplo n.º 6
0
 /// <inheritdoc />
 public override GridField2d <Vector2d> Create(Grid2d grid)
 {
     return(new GridField2dVector2d(grid));
 }
Exemplo n.º 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="grid"></param>
 /// <returns></returns>
 public abstract GridField2d <T> Create(Grid2d grid);