Fixes bug where setBackgroundColor(...) crashes in the event of a channel mismatch.
Change list:
Makes default color [0], instead of [0,0,0].
Calling setBackgroundColor(..., color,...) no longer overwrites self.backgroundColor = color
Color [0] is repeated for any number of color channels (e.g. RGB = [0,0,0])
New implementation removes weird logic and is now 2.13x faster!
Test case test_setBackgroundColor(...) has been added
Note! Using setBackgroundColor(..., valid=None) results in the re-computation of valid using worldCoordinates(). This is VERY expensive and should be avoided.
N=1000
start = time.time()
for _ in range(N):
# Original Implementation
if mask.sum() > 0:
e.data[np.tile(mask[:,:,None], (1, 1, e.data.shape[2]))] = np.tile(e.backgroundColor, (mask.sum(),))
end = time.time()
dt = (end-start) / N
print(dt)
start = time.time()
for _ in range(N):
# New Implementation
self.data[np.invert(valid)] = backgroundColor
end = time.time()
dt = (end-start) / N
print(dt)
Fixes bug where
setBackgroundColor(...)
crashes in the event of a channel mismatch.Change list:
setBackgroundColor(..., color,...)
no longer overwritesself.backgroundColor = color
test_setBackgroundColor(...)
has been addedNote! Using
setBackgroundColor(..., valid=None)
results in the re-computation ofvalid
usingworldCoordinates()
. This is VERY expensive and should be avoided.Output