diff --git a/invesalius/data/floodfill.pyx b/invesalius/data/floodfill.pyx index 418e9d9..5a05986 100644 --- a/invesalius/data/floodfill.pyx +++ b/invesalius/data/floodfill.pyx @@ -90,7 +90,7 @@ def floodfill(np.ndarray[image_t, ndim=3] data, int i, int j, int k, int v, int @cython.boundscheck(False) # turn of bounds-checking for entire function @cython.wraparound(False) @cython.nonecheck(False) -def floodfill_threshold(np.ndarray[image_t, ndim=3] data, list seeds, int t0, int t1, int fill, vector[vector[int]] neighbor_iter, np.ndarray[mask_t, ndim=3] out): +def floodfill_threshold(np.ndarray[image_t, ndim=3] data, list seeds, int t0, int t1, int fill, np.ndarray[mask_t, ndim=3] strct, np.ndarray[mask_t, ndim=3] out): cdef int to_return = 0 if out is None: @@ -98,18 +98,27 @@ def floodfill_threshold(np.ndarray[image_t, ndim=3] data, list seeds, int t0, in to_return = 1 cdef int x, y, z - cdef int xd, yd, zd - cdef int w, h, d + cdef int dx, dy, dz + cdef int odx, ody, odz cdef int xo, yo, zo - cdef int i + cdef int i, j, k + cdef int offset_x, offset_y, offset_z - d = data.shape[0] - h = data.shape[1] - w = data.shape[2] + dz = data.shape[0] + dy = data.shape[1] + dx = data.shape[2] + + odz = strct.shape[0] + ody = strct.shape[1] + odx = strct.shape[2] cdef cdeque[coord] stack cdef coord c + offset_z = odz / 2 + offset_y = ody / 2 + offset_x = odx / 2 + for i, j, k in seeds: if data[k, j, i] >= t0 and data[k, j, i] <= t1: c.x = i @@ -129,17 +138,20 @@ def floodfill_threshold(np.ndarray[image_t, ndim=3] data, list seeds, int t0, in out[z, y, x] = fill - for i in xrange(neighbor_iter.size()): - xo = x + neighbor_iter[i][0] - yo = y + neighbor_iter[i][1] - zo = z + neighbor_iter[i][2] - - if 0 <= xo < w and 0 <= yo < h and 0 <= zo < d and out[zo, yo, xo] != fill and t0 <= data[zo, yo, xo] <= t1: - out[zo, yo, xo] = fill - c.x = xo - c.y = yo - c.z = zo - stack.push_back(c) + for k in xrange(odz): + for j in xrange(ody): + for i in xrange(odx): + if strct[k, j, i]: + xo = x + i - offset_x + yo = y + j - offset_y + zo = z + k - offset_z + + if 0 <= xo < dx and 0 <= yo < dy and 0 <= zo < dz and out[zo, yo, xo] != fill and t0 <= data[zo, yo, xo] <= t1: + out[zo, yo, xo] = fill + c.x = xo + c.y = yo + c.z = zo + stack.push_back(c) if to_return: return out diff --git a/invesalius/data/styles.py b/invesalius/data/styles.py index b808d61..e488642 100644 --- a/invesalius/data/styles.py +++ b/invesalius/data/styles.py @@ -1803,24 +1803,23 @@ class FloodFillMaskInteractorStyle(DefaultInteractorStyle): x, y, z = self.calcultate_scroll_position(position) - from_3d = True if self.config.target == "3D": - print "DOING 3D, manolo!" - neighbor_iter = ((-1, 0, 0), - (1, 0, 0), - (0, -1, 0), - (0, 1, 0), - (0, 0, -1), - (0, 0, 1)) + bstruct = generate_binary_structure(3, 1) self.viewer.slice_.do_threshold_to_all_slices() else: - neighbor_iter = ((-1, 0, 0), - (1, 0, 0), - (0, -1, 0), - (0, 1, 0)) + _bstruct = generate_binary_structure(2, 1) + if self.orientation == 'AXIAL': + bstruct = np.zeros((1, 3, 3), dtype='uint8') + bstruct[0] = _bstruct + elif self.orientation == 'CORONAL': + bstruct = np.zeros((3, 1, 3), dtype='uint8') + bstruct[:, 0, :] = _bstruct + elif self.orientation == 'SAGITAL': + bstruct = np.zeros((3, 3, 1), dtype='uint8') + bstruct[:, :, 0] = _bstruct mask = self.viewer.slice_.current_mask.matrix[1:, 1:, 1:] - cp_mask = mask.copy() + cp_mask = mask # neighbor_iter = [] # for i in xrange(-1, 2): @@ -1837,7 +1836,7 @@ class FloodFillMaskInteractorStyle(DefaultInteractorStyle): t1 = 1 fill = 254 - floodfill.floodfill_threshold(cp_mask, [[x, y, z]], t0, t1, fill, neighbor_iter, mask) + floodfill.floodfill_threshold(cp_mask, [[x, y, z]], t0, t1, fill, bstruct, mask) self.viewer.slice_.buffer_slices['AXIAL'].discard_mask() self.viewer.slice_.buffer_slices['CORONAL'].discard_mask() -- libgit2 0.21.2