Skip to content

Commit

Permalink
Simplify vertex math
Browse files Browse the repository at this point in the history
  • Loading branch information
domstoppable committed Sep 6, 2024
1 parent 7b98809 commit 61b3e2d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
7 changes: 1 addition & 6 deletions psychopy_eyetracker_pupil_labs/pupil_labs/neon/eyetracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ def _poll(self):
frame, gaze = frame_and_gaze
surface_map = self._gaze_mapper.process_frame(frame, gaze)
for surface_gaze in surface_map.mapped_gaze[self._screen_surface.uid]:

gaze_in_pix = [
surface_gaze.x * self._window_size[0],
surface_gaze.y * self._window_size[1],
Expand Down Expand Up @@ -365,11 +364,7 @@ def _add_gaze_sample(self, surface_gaze, gaze_datum, logged_time):
self._latest_gaze_position = surface_gaze

def register_surface(self, tag_verts, window_size):
corrected_verts = {}
for tag_id_str, verts in tag_verts.items():
corrected_verts[int(tag_id_str)] = [
(vert[0] + window_size[0] / 2, vert[1] + window_size[1] / 2) for vert in verts
]
corrected_verts = {int(tag_id): verts for tag_id, verts in tag_verts.items()}

self._gaze_mapper.clear_surfaces()
self._screen_surface = self._gaze_mapper.add_surface(
Expand Down
11 changes: 4 additions & 7 deletions psychopy_eyetracker_pupil_labs/pupil_labs/stimuli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def __init__(self, marker_id=0, contrast=1.0, *args, **kwargs):

@property
def marker_verts(self):
win_size_pix = convertToPix(np.array([2, 2]), [0, 0], 'norm', self.win).astype(int)

vertices_in_pixels = self._vertices.pix
size_with_margin = (
abs(vertices_in_pixels[1][0] - vertices_in_pixels[0][0]),
Expand All @@ -32,8 +34,8 @@ def marker_verts(self):
top_left_pos = vertices_in_pixels[2]

top_left = (
top_left_pos[0] + padding,
top_left_pos[1] - padding
top_left_pos[0] + padding + win_size_pix[0] / 2,
top_left_pos[1] - padding + win_size_pix[1] / 2
)
bottom_right = (
top_left[0] + size_without_margin[0],
Expand Down Expand Up @@ -84,11 +86,6 @@ def __init__(self, h_count=4, v_count=3, marker_ids=None, marker_size=0.125, mar
top_left = [v + marker_padding for v in top_left]
bottom_right = [v - marker_padding for v in bottom_right]

top_left[0] -= win_size_pix[0] / 2
top_left[1] -= win_size_pix[1] / 2
bottom_right[0] -= win_size_pix[0] / 2
bottom_right[1] -= win_size_pix[1] / 2

self.marker_verts[str(marker_id)] = (
(top_left[0], bottom_right[1]),
bottom_right,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "psychopy-eyetracker-pupil-labs"
version = "0.3.1"
version = "0.3.2"
description = "Extension package for PsychoPy which adds support for Pupil Labs eyetrackers."
readme = "README.md"
requires-python = ">= 3.7"
Expand Down

0 comments on commit 61b3e2d

Please sign in to comment.