Skip to content

Commit

Permalink
Merge pull request #8 from ch-sa/mac-retina-fix
Browse files Browse the repository at this point in the history
Fix coordinate problem for retina displays
  • Loading branch information
ch-sa authored Apr 20, 2021
2 parents 704d5b3 + 48c8b52 commit 50d12da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions labelCloud/utils/oglhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
Color4f = Tuple[float, float, float, float] # type alias for type hinting
PointList = List[List[float]]

DEVICE_PIXEL_RATIO = None # is set once and for every window resize (retina display fix)


def draw_points(points: PointList, color: Color4f = (0, 1, 1, 1), point_size: int = 10) -> None:
GL.glColor4d(*color)
Expand Down Expand Up @@ -96,6 +98,9 @@ def get_pick_ray(x: float, y: float, modelview, projection) -> Tuple[List[float]
:param projection: projection matrix
:return: two points of the pick ray from the closest and furthest frustum
"""
x *= DEVICE_PIXEL_RATIO
y *= DEVICE_PIXEL_RATIO

viewport = GL.glGetIntegerv(GL.GL_VIEWPORT)
real_y = viewport[3] - y # adjust for down-facing y positions

Expand Down
6 changes: 6 additions & 0 deletions labelCloud/view/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@

# Main widget for presenting the point cloud
class GLWidget(QtOpenGL.QGLWidget):

def __init__(self, parent=None):
self.parent = parent
QtOpenGL.QGLWidget.__init__(self, parent)
self.setMouseTracking(True) # mouseMoveEvent is called also without button pressed

self.modelview = None
self.projection = None
self.DEVICE_PIXEL_RATIO = self.devicePixelRatioF() # 1 = normal; 2 = retina display
oglhelper.DEVICE_PIXEL_RATIO = self.DEVICE_PIXEL_RATIO # set for helper functions

self.pcd_controller = None
self.bbox_controller = None
Expand Down Expand Up @@ -111,6 +114,9 @@ def paintGL(self):

# Translates the 2D cursor position from screen plane into 3D world space coordinates
def get_world_coords(self, x: int, y: int, z: float = None, correction: bool = False):
x *= self.DEVICE_PIXEL_RATIO # For fixing mac retina bug
y *= self.DEVICE_PIXEL_RATIO

viewport = GL.glGetIntegerv(GL.GL_VIEWPORT) # Stored projection matrices are taken from loop
real_y = viewport[3] - y # adjust for down-facing y positions

Expand Down

0 comments on commit 50d12da

Please sign in to comment.