Isn't it simple enough to make three bounds checks to essentially do the same thing you did with the zero padding? You can even make it a function
is_in_bounds(x, y, z) is_in_bounds(x, y, z)Also, it's really slow and wasteful to be doing bounds-checking for each voxel of an image that is almost completely not a boundary, whereas you can't avoid checking if each voxel is lit. :-)