From b7161bec0ac5c703ba6ecfca2255e06cd2d394a8 Mon Sep 17 00:00:00 2001 From: Luigi Petrucco Date: Mon, 9 Dec 2019 12:02:36 +0100 Subject: [PATCH 1/2] made windmill CenteredBackground child --- stytra/stimulation/stimuli/visual.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stytra/stimulation/stimuli/visual.py b/stytra/stimulation/stimuli/visual.py index 554daf7c..b2140ad2 100644 --- a/stytra/stimulation/stimuli/visual.py +++ b/stytra/stimulation/stimuli/visual.py @@ -698,7 +698,7 @@ def z_func_windmill(x, y, arms): ) * (y >= 0).astype(int) -class WindmillStimulus(BackgroundStimulus): +class WindmillStimulus(CenteredBackgroundStimulus): """ Class for drawing a rotating windmill (radial wedges in alternating colors). For moving gratings use subclass @@ -763,7 +763,7 @@ def __init__(self, *args, **kwargs): self.dynamic_parameters.append("theta") -class HighResWindmillStimulus(BackgroundStimulus): +class HighResWindmillStimulus(CenteredBackgroundStimulus): """Class for drawing a rotating windmill with sharp edges. Instead of rotating an image, this class use a painter to draw triangles of the windmill at every timestep. From 2f35fa0f69e14f11230a4ae3d6b5d81441f47b3a Mon Sep 17 00:00:00 2001 From: Vilim Stih Date: Tue, 10 Dec 2019 21:12:48 +0100 Subject: [PATCH 2/2] Fixed tile range calculation --- stytra/stimulation/stimuli/visual.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/stytra/stimulation/stimuli/visual.py b/stytra/stimulation/stimuli/visual.py index b2140ad2..3a44a2cf 100644 --- a/stytra/stimulation/stimuli/visual.py +++ b/stytra/stimulation/stimuli/visual.py @@ -271,12 +271,6 @@ def get_unit_dims(self, w, h): def get_transform(self, w, h, x, y): return QTransform().rotate(self.theta * 180 / np.pi).translate(x, y) - @staticmethod - def negceil(x): - """ negative ceiling function (e.g -0.2 gets rounded to -1, while 0.2 gets rounded to 1) - """ - return int(-np.ceil(-x) if x < 0 else np.ceil(x)) - def get_tile_ranges(self, imw, imh, w, h, tr: QTransform): """ Calculates the number of tiles depending on the transform. @@ -304,13 +298,14 @@ def get_tile_ranges(self, imw, imh, w, h, tr: QTransform): [tr.inverted()[0].map(*cp) for cp in corner_points] ) - # calculate the rectangle covering the trnasformed display surface + # calculate the rectangle covering the transformed display surface min_x, min_y = np.min(points_transformed, 0) max_x, max_y = np.max(points_transformed, 0) # count which tiles need to be drawn - x_start, x_end = (self.negceil(x / imw) for x in [min_x, max_x]) - y_start, y_end = (self.negceil(y / imh) for y in [min_y, max_y]) + x_start, x_end = (int(np.floor(min_x / imw)), int(np.ceil(max_x / imw))) + y_start, y_end = (int(np.floor(min_y / imh)), int(np.ceil(max_y / imh))) + return range(x_start, x_end + 1), range(y_start, y_end + 1) def paint(self, p, w, h):