/// <summary> /// /// </summary> /// <param name="other"></param> public Grid3d(Grid3d other) { _dx = other._dx; _dy = other._dy; _dz = other._dz; _tx = other._tx; _ty = other._ty; _tz = other._tz; _txInv = other._txInv; _tyInv = other._tyInv; _tzInv = other._tzInv; _nx = other._nx; _ny = other._ny; _nz = other._nz; _nxy = other._nxy; _nxyz = other._nxyz; _wrapX = other._wrapX; _wrapY = other._wrapY; _wrapZ = other._wrapZ; }
/// <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(Grid3d 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, var nz) = grid.Count; var nxy = grid.CountXY; (var dx, var dy, var dz) = Vector3d.Abs(grid.Scale); var queue = new Queue <int>(); result.SetRange(double.PositiveInfinity, grid.CountXYZ); // 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, int z0) = 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); } // -z if (z0 > 0) { TryUpdate(d0 + dz, i0 - nxy); } // +z if (z0 < nz - 1) { TryUpdate(d0 + dz, i0 + nxy); } // add to queue if less than current min void TryUpdate(double distance, int index) { if (distance < result[index]) { result[index] = distance; queue.Enqueue(index); } } } }
/// <summary> /// /// </summary> /// <param name="grid"></param> /// <returns></returns> public abstract GridField3d <T> Create(Grid3d grid);
/// <summary> /// /// </summary> /// <param name="other"></param> public GridField3dVector3d(Grid3d other) : base(other) { }
/// <inheritdoc /> public override GridField3d <Vector3d> Create(Grid3d grid) { return(new GridField3dVector3d(grid)); }
/// <summary> /// /// </summary> /// <param name="other"></param> public GridField3dMatrix3d(Grid3d other) : base(other) { }
/// <inheritdoc /> public override GridField3d <Matrix3d> Create(Grid3d grid) { return(new GridField3dMatrix3d(grid)); }
/// <summary> /// /// </summary> /// <param name="other"></param> public GridField3dDouble(Grid3d other) : base(other) { }
/// <inheritdoc /> public override GridField3d <double> Create(Grid3d grid) { return(new GridField3dDouble(grid)); }