Ejemplo n.º 1
0
        public void Id2RowColTest()
        {
            ExtentRectangle rTest1 = new ExtentRectangle(5, 6, -1, 1, 100, 50);

            CollectionAssert.AreEqual(rTest1.Id2RowCol(52), new int[2] {
                2, 3
            });
            CollectionAssert.AreEqual(rTest1.Id2RowCol(0), new int[2] {
                1, 1
            });
            CollectionAssert.AreEqual(rTest1.Id2RowCol(1), new int[2] {
                1, 2
            });
            CollectionAssert.AreEqual(rTest1.Id2RowCol(100), new int[2] {
                3, 1
            });
            CollectionAssert.AreEqual(rTest1.Id2RowCol(4999), new int[2] {
                100, 50
            });
        }
Ejemplo n.º 2
0
        protected override void ChunkOp(List <T[]> data, List <T[]> outBuffers)
        {
            /** Don't forget the numbering scheme:
             *  0  1  2  or   0  1  2  3  4
             *  3  4  5       5  6  7  8  9
             *  6  7  8       10 11 12 13 14
             *                15 16 17 18 19
             *                20 21 22 23 24
             */
            // Initialize the Window properly
            WindowExtent.Left = ChunkExtent.Left - ChunkExtent.CellWidth;
            WindowExtent.Top  = ChunkExtent.Top - ChunkExtent.CellHeight;

            // First time around we need to set up the cache properly and force the look-ahead forward
            if (_chunkCache.Count == 0)
            {
                firstTime(data);
            }
            // When we get to the end of the file we need to pad with nodata values at the bottom
            //else if (ChunkExtent.Top > OriginalOpBottom)
            else if ((ChunkExtent.Top * ChunkExtent.CellHeight) >= (OriginalOpBottom * ChunkExtent.CellHeight))
            {
                IdxIncrement();
                _chunkCache[Row2CacheId(BufferLength)] = NoDataChunkList();
            }
            else
            {
                // Put our data into the right place in the rolling cache
                IdxIncrement();
                _chunkCache[Row2CacheId(BufferLength)] = data.Clone <T[]>();
            }

            // Loop over the cells in the Chunk (line)
            for (int id = 0; id < data[0].GetLength(0); id++)
            {
                bool containsNodata = false;
                // Now loop over cells in the window
                for (int wId = 0; wId < BufferCellNum; wId++)
                {
                    // Get the rowcol translation of this window id
                    int[] winRowCol = WindowExtent.Id2RowCol(wId);
                    // The row of the window tells us which cache to use
                    int cacheNum = Row2CacheId(winRowCol[0]);
                    // This is the column ID of the cache column in window coordinates
                    int wid2cid = id + (winRowCol[1] - 1) - BufferCells;
                    // Now loop over all the data values (number of rasters)
                    for (int dId = 0; dId < data.Count; dId++)
                    {
                        // Edge cases to the left and right of the chunk data become nodata
                        // (top and bottom are handled by pre-filling the cache)
                        if (wid2cid < 0 || wid2cid >= ChunkExtent.Cols)
                        {
                            dWindow[dId][wId] = inNodataVals[dId];
                        }
                        else
                        {
                            dWindow[dId][wId] = _chunkCache[cacheNum][dId][wid2cid];
                        }

                        // This is done to save us checking later. We can decide whether to use
                        // This information or not.
                        if (dWindow[dId][wId].Equals(inNodataVals[dId]))
                        {
                            containsNodata = true;
                        }
                    }
                }
                // DEBUG TEST
                //dWindow[0].Make2DArray(BufferLength, BufferLength).DebugPrintGrid(OpNodataVal);
#if DEBUG
                num_calcs++;
#endif
                WindowOp(dWindow, outBuffers, id, containsNodata);
                // Move the window by one cell to the right
                WindowExtent.Left += ChunkExtent.CellWidth;
            }
        }