Skip to content
Snippets Groups Projects
Commit 94954ac3 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Mouse cursor location is correctly translated between screen and world coordinates

parent d863a2a1
No related branches found
No related tags found
No related merge requests found
...@@ -119,8 +119,8 @@ class OrthoPanel(wx.Panel, props.HasProperties): ...@@ -119,8 +119,8 @@ class OrthoPanel(wx.Panel, props.HasProperties):
y = self.ycanvas.zpos y = self.ycanvas.zpos
z = self.zcanvas.zpos z = self.zcanvas.zpos
mx = mx * (source.xmax - source.xmin) / float(w) + source.xmin mx = source.canvasToWorldX(mx)
my = my * (source.ymax - source.ymin) / float(h) + source.ymin my = source.canvasToWorldY(my)
if source == self.xcanvas: y, z = mx, my if source == self.xcanvas: y, z = mx, my
elif source == self.ycanvas: x, z = mx, my elif source == self.ycanvas: x, z = mx, my
......
...@@ -435,22 +435,43 @@ class SliceCanvas(wxgl.GLCanvas): ...@@ -435,22 +435,43 @@ class SliceCanvas(wxgl.GLCanvas):
self._ypos = ypos self._ypos = ypos
@property
def canvasXpos(self):
pass
@canvasXpos.setter def canvasToWorldX(self, xpos):
def canvasXpos(self): """
pass Given a pixel x coordinate on this canvas, translates it
into the real world coordinates of the displayed slice.
"""
@property realWidth = float(self.xmax - self.xmin)
def canvasYpos(self): sliceStart = float(self._canvasBBox[0])
pass sliceWidth = float(self._canvasBBox[2])
# Translate the xpos from the canvas to
# the slice bounding box, then translate
# the xpos from the slice bounding box
# to real world coordinates
xpos = xpos - sliceStart
xpos = self.xmin + (xpos / sliceWidth) * realWidth
return xpos
def canvasToWorldY(self, ypos):
"""
Given a pixel y coordinate on this canvas, translates it
into the real world coordinates of the displayed slice.
"""
realHeight = float(self.ymax - self.ymin)
sliceStart = float(self._canvasBBox[1])
sliceHeight = float(self._canvasBBox[3])
ypos = ypos - sliceStart
ypos = self.ymin + (ypos / sliceHeight) * realHeight
@canvasYpos.setter return ypos
def canvasYpos(self):
pass
def __init__(self, parent, imageList, zax=0, context=None): def __init__(self, parent, imageList, zax=0, context=None):
""" """
Creates a canvas object. The OpenGL data buffers are set up the Creates a canvas object. The OpenGL data buffers are set up the
...@@ -699,7 +720,7 @@ class SliceCanvas(wxgl.GLCanvas): ...@@ -699,7 +720,7 @@ class SliceCanvas(wxgl.GLCanvas):
if height != size.height: y = (size.height - height) / 2 if height != size.height: y = (size.height - height) / 2
self._canvasBBox = [x, y, width, height] self._canvasBBox = [x, y, width, height]
return width, height return width, height
...@@ -879,12 +900,17 @@ class SliceCanvas(wxgl.GLCanvas): ...@@ -879,12 +900,17 @@ class SliceCanvas(wxgl.GLCanvas):
xverts = np.zeros((2, 3)) xverts = np.zeros((2, 3))
yverts = np.zeros((2, 3)) yverts = np.zeros((2, 3))
xverts[:, self.xax] = self.xpos # add a little padding to the lines if they are
# on the boundary, so they don't get cropped
if self.xpos == self.xmin: xverts[:, self.xax] = self.xpos + 0.5
else: xverts[:, self.xax] = self.xpos
if self.ypos == self.ymin: yverts[:, self.yax] = self.ypos + 0.5
else: yverts[:, self.yax] = self.ypos
xverts[:, self.yax] = [self.ymin, self.ymax] xverts[:, self.yax] = [self.ymin, self.ymax]
xverts[:, self.zax] = self.zpos + 1 xverts[:, self.zax] = self.zpos + 1
yverts[:, self.xax] = [self.xmin, self.xmax] yverts[:, self.xax] = [self.xmin, self.xmax]
yverts[:, self.yax] = self.ypos yverts[:, self.zax] = self.zpos + 1
yverts[:, self.zax] = self.zpos + 1
gl.glBegin(gl.GL_LINES) gl.glBegin(gl.GL_LINES)
gl.glColor3f(0, 1, 0) gl.glColor3f(0, 1, 0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment