This is the function that manages the whole calculation.
For a particular row, we want to create all the horizontal sums for each cell in that row, and store those sums in the appropriate "line".
For a particular row, we want to create all the horizontal sums for each cell in that row, and store those sums in the appropriate "line".
At the start (where the kernel goes off the left side of the raster) line(0) will be the sum of the first (radius + 1) cells, line(1) will be the sum of the first (radius + 2) cells, and so on. By the middle of the raster each sum will involve diameter cells, and then at the right we will taper back to down (radius + 1) cells.
For a particular row, sum all the available "row sums" and record the results in the out.
For a particular row, sum all the available "row sums" and record the results in the out. After we've called sumall() on all rows, the calculation will be complete.
Initialize a particular line to zeros.
Initialize a particular line to zeros. We need to do this once we're on the "right edge" of the raster and don't have new data to use.
This class encompasses an attempt to create a fast sequential focal mean operation, using whatever tricks we can to eke out some speed.
We require the raster to contain array data, which we will look up via apply instead of get. The kernel is a square, and the length of a side is twice the radius plus one. Thus, radius=1 means a 3x3 square kernel (9 cells), and radius=3 means a 7x7 square kernel (49 cells).