Beispiel #1
0
        }//End Write_Vertical

        #endregion

        #region Array - Grid Handling

        /// <summary>
        /// Converts a region of a grid into a 2D array of float values
        /// </summary>
        /// <param name="mwSourceGrid">The grid to read</param>
        /// <param name="ICallBack">A MapWinGIS.ICallback for status messages</param>
        /// <returns>float[][] the values from the grid</returns>
        public float[][] GetArrayFromWindow(MapWinGIS.Grid mwSourceGrid, MapWinGIS.ICallback ICallBack)
        {
            if (mwSourceGrid == null)
            {
                if (ICallBack != null)
                {
                    ICallBack.Error("Error", "SourceGrid cannot be null.");
                }
                throw new ArgumentException("SourceGrid cannot be null.");
            }

            int numRows = this.Rectangle.Height;
            int numCols = this.Rectangle.Width;

            // Populate the Array by directly reading values from the grid
            float[][] SourceArray = new float[numRows][];
            float[]   Temp        = new float[numRows * numCols];

            // Read from the ocx once, rather than calling several times
            if (ICallBack != null)
            {
                ICallBack.Progress("Status", 0, " Loading Values");
            }
            mwSourceGrid.GetFloatWindow(this.Rectangle.Y, this.Rectangle.Bottom - 1, this.Rectangle.X, this.Rectangle.Right - 1, ref Temp[0]);
            if (ICallBack != null)
            {
                ICallBack.Progress("Status", 0, "Copying Values");
            }
            for (int row = 0; row < numRows; row++)
            {
                SourceArray[row] = new float[numCols];
                //
                for (int col = 0; col < numCols; col++)
                {
                    // copy the values into a 2D style array because it improves
                    // handling speeds for some reason
                    SourceArray[row][col] = Temp[row * numCols + col];
                }
            }
            if (ICallBack != null)
            {
                ICallBack.Progress("Status", 0, "Finished copying values from grid.");
            }
            return(SourceArray);
        }// End GetArrayFromWindow
Beispiel #2
0
        }// End GetArrayFromWindow

        /// <summary>
        /// Returns jagged array where the borders are read from the destination file but the central
        /// portion is set to be the maximum float value.
        /// </summary>
        /// <param name="mwSourceGrid">A MapWinGIS.Grid to read the frame borders that are on the very outside of the image</param>
        /// <param name="mwDestGrid">A MapWinGIS.Grid to read the frame borders on the interior edges already processed </param>
        /// <param name="ICallBack">A MapWinGIS.ICallback for messages (optional)</param>
        /// <returns>A float[][] array representing the destination values for an entire frame</returns>
        public float[][] GetBorders(MapWinGIS.Grid mwSourceGrid, MapWinGIS.Grid mwDestGrid, MapWinGIS.ICallback ICallBack)
        {
            if (mwSourceGrid == null || mwDestGrid == null)
            {
                if (ICallBack != null)
                {
                    ICallBack.Error("Error", "SourceGrid cannot be null.");
                }
                throw new ArgumentException("SourceGrid cannot be null.");
            }

            int numRows = this.Rectangle.Height;
            int numCols = this.Rectangle.Width;

            // Populate the Array by directly reading values from the grid
            float[][] SourceArray = new float[numRows][];


            // Read from the ocx once, rather than calling several times



            // Initialize the array to max values
            for (int row = 0; row < numRows; row++)
            {
                SourceArray[row] = new float[numCols];
                for (int col = 0; col < numCols; col++)
                {
                    SourceArray[row][col] = float.MaxValue;
                }
            }

            // If we need a dependency in a given direction, read it from the file.
            if (Y == 0)
            {
                mwSourceGrid.GetFloatWindow(this.Rectangle.Y, this.Rectangle.Y, this.Rectangle.X, this.Rectangle.Right - 1, ref SourceArray[0][0]);
            }
            else if (Parent.First_Time(X, Y - 1) == false)
            {
                mwDestGrid.GetFloatWindow(this.Rectangle.Y, this.Rectangle.Y, this.Rectangle.X, this.Rectangle.Right - 1, ref SourceArray[0][0]);
            }

            if (Y == Parent.NumFramesTall - 1)
            {
                mwSourceGrid.GetFloatWindow(this.Rectangle.Bottom - 1, this.Rectangle.Bottom - 1, this.Rectangle.X, this.Rectangle.Right - 1, ref SourceArray[numRows - 1][0]);
            }
            else if (Parent.First_Time(X, Y + 1) == false)
            {
                mwDestGrid.GetFloatWindow(this.Rectangle.Bottom - 1, this.Rectangle.Bottom - 1, this.Rectangle.X, this.Rectangle.Right - 1, ref SourceArray[numRows - 1][0]);
            }

            if (X == 0)
            {
                float[] Temp = new float[numRows];
                mwSourceGrid.GetFloatWindow(this.Rectangle.Y, this.Rectangle.Bottom - 1, this.Rectangle.X, this.Rectangle.X, ref Temp[0]);
                for (int row = 0; row < numRows; row++)
                {
                    SourceArray[row][0] = Temp[row];
                }
            }
            else if (Parent.First_Time(X - 1, Y) == false)
            {
                float[] Temp = new float[numRows];
                mwDestGrid.GetFloatWindow(this.Rectangle.Y, this.Rectangle.Bottom - 1, this.Rectangle.X, this.Rectangle.X, ref Temp[0]);
                for (int row = 0; row < numRows; row++)
                {
                    SourceArray[row][0] = Temp[row];
                }
            }

            if (X == Parent.NumFramesWide - 1)
            {
                float[] Temp = new float[numRows];
                mwSourceGrid.GetFloatWindow(this.Rectangle.Y, this.Rectangle.Bottom - 1, this.Rectangle.Right - 1, this.Rectangle.Right - 1, ref Temp[0]);
                for (int row = 0; row < numRows; row++)
                {
                    SourceArray[row][numCols - 1] = Temp[row];
                }
            }
            else if (Parent.First_Time(X + 1, Y) == false)
            {
                float[] Temp = new float[numRows];
                mwDestGrid.GetFloatWindow(this.Rectangle.Y, this.Rectangle.Bottom - 1, this.Rectangle.Right - 1, this.Rectangle.Right - 1, ref Temp[0]);
                for (int row = 0; row < numRows; row++)
                {
                    SourceArray[row][numCols - 1] = Temp[row];
                }
            }
            if (ICallBack != null)
            {
                ICallBack.Progress("Status", 0, "Finished copying values from grid.");
            }
            return(SourceArray);
        }