From 8ad75f888c0a98235b34914ccc9df2c705277c89 Mon Sep 17 00:00:00 2001 From: Craig Warren Date: Fri, 15 Jul 2016 13:36:04 +0100 Subject: [PATCH] Added function to build voxels from a mask array. --- gprMax/geometry_primitives.pyx | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/gprMax/geometry_primitives.pyx b/gprMax/geometry_primitives.pyx index 821e0423..e4f3f74b 100644 --- a/gprMax/geometry_primitives.pyx +++ b/gprMax/geometry_primitives.pyx @@ -702,3 +702,36 @@ cpdef void build_voxels_from_array(int xs, int ys, int zs, int numexistmaterials numID += numexistmaterials build_voxel(i, j, k, numID, numID, numID, numID, False, solid, rigidE, rigidH, ID) + +cpdef void build_voxels_from_array_mask(int xs, int ys, int zs, int waternumID, int grassnumID, np.int8_t[:, :, ::1] mask, np.int16_t[:, :, ::1] data, np.uint32_t[:, :, ::1] solid, np.int8_t[:, :, :, ::1] rigidE, np.int8_t[:, :, :, ::1] rigidH, np.uint32_t[:, :, :, ::1] ID): + """Builds Yee voxels by reading integers from an array. + + Args: + xs, ys, zs (int): Cell coordinates of position of start of array in domain. + waternumID, grassnumID (int): Numeric ID of water and grass materials. + data (memoryview): Access to array containing numeric IDs of voxels to create. + mask (memoryview): Access to array containing a mask of voxels to create. + solid, rigidE, rigidH, ID (memoryviews): Access to solid, rigid and ID arrays. + """ + + cdef Py_ssize_t i, j, k + cdef int xf, yf, zf, numID, numIDx, numIDy, numIDz + + # Set upper bounds + xf = xs + data.shape[0] + yf = ys + data.shape[1] + zf = zs + data.shape[2] + + for i in range(xs, xf): + for j in range(ys, yf): + for k in range(zs, zf): + if mask[i - xs, j - ys, k - zs] == 1: + numID = numIDx = numIDy = numIDz = data[i - xs, j - ys, k - zs] + build_voxel(i, j, k, numID, numIDx, numIDy, numIDz, False, solid, rigidE, rigidH, ID) + elif mask[i - xs, j - ys, k - zs] == 2: + numID = numIDx = numIDy = numIDz = waternumID + build_voxel(i, j, k, numID, numIDx, numIDy, numIDz, False, solid, rigidE, rigidH, ID) + elif mask[i - xs, j - ys, k - zs] == 3: + numID = numIDx = numIDy = numIDz = grassnumID + build_voxel(i, j, k, numID, numIDx, numIDy, numIDz, False, solid, rigidE, rigidH, ID) +