Skip to content

Commit

Permalink
Update use of buffer in floodfill
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesmic committed Nov 7, 2023
1 parent d656cc8 commit 1e586b1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions defdap/_accelerated.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def flood_fill(seed, index, points_remaining, grains, boundary_x, boundary_y,
npoints += 1
edge.append((s, t))

return np.copy(added_coords[:npoints])
return added_coords[:npoints]


@njit
Expand Down Expand Up @@ -145,4 +145,4 @@ def flood_fill_dic(seed, index, points_remaining, grains, added_coords):
points_remaining[t, s] = False
npoints += 1

return np.copy(added_coords[:npoints])
return added_coords[:npoints]
9 changes: 4 additions & 5 deletions defdap/ebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,18 +882,17 @@ def find_grains(self, min_grain_size=10):
# Loop until all points (except boundaries) have been assigned
# to a grain or ignored
i = 0
added_coords_buffer = np.zeros((boundary_im_y.size, 2), dtype=np.intp)
coords_buffer = np.zeros((boundary_im_y.size, 2), dtype=np.intp)
while found_point >= 0:
# Flood fill first unknown point and return grain object
seed = np.unravel_index(next_point, self.shape)

grain = Grain(grain_index - 1, self, group_id)
grain.data.point = flood_fill(
(seed[1], seed[0]), grain_index,
points_left, grains,
boundary_im_x, boundary_im_y,
added_coords_buffer
(seed[1], seed[0]), grain_index, points_left, grains,
boundary_im_x, boundary_im_y, coords_buffer
)
coords_buffer = coords_buffer[len(grain.data.point):]

if len(grain) < min_grain_size:
# if grain size less than minimum, ignore grain and set
Expand Down
5 changes: 3 additions & 2 deletions defdap/hrdic.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ def find_grains(self, algorithm=None, min_grain_size=10):

# List of points where no grain has been set yet
points_left = grains == 0
added_coords_buffer = np.zeros((points_left.size, 2), dtype=np.intp)
coords_buffer = np.zeros((points_left.size, 2), dtype=np.intp)
total_points = points_left.sum()
found_point = 0
next_point = points_left.tobytes().find(b'\x01')
Expand All @@ -661,8 +661,9 @@ def find_grains(self, algorithm=None, min_grain_size=10):
grain = Grain(grain_index - 1, self, group_id)
grain.data.point = flood_fill_dic(
(seed[1], seed[0]), grain_index, points_left,
grains, added_coords_buffer
grains, coords_buffer
)
coords_buffer = coords_buffer[len(grain.data.point):]

if len(grain) < min_grain_size:
# if grain size less than minimum, ignore grain and set
Expand Down

0 comments on commit 1e586b1

Please sign in to comment.