27 neighbor stencil transformation. For efficient finite difference operations. Applies a function to a moving
3 x 3 x 3 window. Does nothing if
rows() < 3 || columns() < 3 || slices() < 3.
B[k,i,j] = function.apply( A[k-1,i-1,j-1], A[k-1,i-1,j], A[k-1,i-1,j+1], A[k-1,i, j-1], A[k-1,i, j], A[k-1,i, j+1], A[k-1,i+1,j-1], A[k-1,i+1,j], A[k-1,i+1,j+1], A[k ,i-1,j-1], A[k ,i-1,j], A[k ,i-1,j+1], A[k ,i, j-1], A[k ,i, j], A[k ,i, j+1], A[k ,i+1,j-1], A[k ,i+1,j], A[k ,i+1,j+1], A[k+1,i-1,j-1], A[k+1,i-1,j], A[k+1,i-1,j+1], A[k+1,i, j-1], A[k+1,i, j], A[k+1,i, j+1], A[k+1,i+1,j-1], A[k+1,i+1,j], A[k+1,i+1,j+1] ) x x x - - x x x - - - - x o x - - x o x - - - - x x x - - x x x ... - x x x - - - - - - - - - x o x - - - - - - - - - x x x
Make sure that cells of
this and
B do not overlap. In case of overlapping views, behaviour is unspecified.
Example:
final double alpha = 0.25; final double beta = 0.75; cern.colt.function.Double27Function f = new cern.colt.function.Double27Function() { public final double apply( double a000, double a001, double a002, double a010, double a011, double a012, double a020, double a021, double a022, double a100, double a101, double a102, double a110, double a111, double a112, double a120, double a121, double a122, double a200, double a201, double a202, double a210, double a211, double a212, double a220, double a221, double a222) { return beta*a111 + alpha*(a000 + ... + a222); } }; A.zAssign27Neighbors(B,f);
@param B the matrix to hold the results.
@param function the function to be applied to the 27 cells.
@throws NullPointerException if
function==null.
@throws IllegalArgumentException if
rows() != B.rows() || columns() != B.columns() || slices() != B.slices() .