Crop VoxelSpace object based on voxel i, j, k, index. If cropping index are missing, the function will automatically crop the voxel space by discarding outermost unsampled slices of voxels. A slice designates a layer with constant i (i-slice), j (j-slice) or k (k-slice). unsampled means that no pulse went through.

One may want to crop the voxel space on coordinates rather than grid index. To do so the voxel space must be first converted to an sf::sf object and use the sf::st_crop() function.

vxsp <- readVoxelSpace(system.file("extdata", "tls_sample.vox", package = "AMAPVox"))
vxsp@data[, c("x", "y"):=getPosition(vxsp)[, .(x, y)]]
library(sf)
vx.sf <- sf::st_as_sf(vxsp@data, coords=c("x", "y"))
vx.sf <- sf::st_crop(vx.sf, c(xmin = 4, ymin = 1, xmax = 5, ymax = 4))
sf::st_bbox(vx.sf)
vxsp@data <- sf::st_drop_geometry(vx.sf)

crop(vxsp, imin = 0, imax = Inf, jmin = 0, jmax = Inf, kmin = 0, kmax = Inf)

Arguments

vxsp

a VoxelSpace object.

imin

minimum i index of cropped area (inclusive)

imax

maximum i index of cropped area (inclusive)

jmin

minimum j index of cropped area (inclusive)

jmax

maximum j index of cropped area (inclusive)

kmin

minimum k index of cropped area (inclusive)

kmax

maximum k index of cropped area (inclusive)

Value

Cropped voxel space with updated i, j, k grid coordinates and updated header (min and max corner).

Examples

if (FALSE) {
vxsp <- readVoxelSpace(system.file("extdata", "tls_sample.vox", package = "AMAPVox"))
plot(crop(vxsp, imin = 1, imax = 5))
# introduce unsampled areas in voxel space
vxsp@data[i < 3, nbSampling:= 0]
# automatic cropping
plot(crop(vxsp))
}