Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 88 additions & 3 deletions painter/src/graphics_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ def __init__(self, parent):
self.outline_pixmap_holder = None
self.cursor_pixmap = None
self.mouse_down = False
self.last_ax_x = 0
self.last_ax_y = 0
self.last_sag_x = 0
self.last_sag_y = 0



def keyReleaseEvent(self, event):
if event.key() == QtCore.Qt.Key_Alt:
Expand Down Expand Up @@ -109,6 +115,29 @@ def update_axial_slice_pos_indicator(self):
for v in self.parent.parent.viewers:
if v.mode == 'sagittal':
slice_nav = self.parent.parent.axial_viewer.slice_nav
y1 = 0
y2 = self.parent.parent.annot_data.shape[2]
x1 = slice_nav.slice_idx
x1 += 0.5
x2 = x1
if hasattr(v.scene, 'line'):
v.scene.line.setLine(x1, y1, x2, y2)
else:
# add line if it doesn't exist
v.scene.line = QtWidgets.QGraphicsLineItem(x1, y1, x2, y2)
v.scene.line.setPen(QtGui.QPen(QtGui.QColor(255, 60, 60), 1.5,
QtCore.Qt.DotLine))
v.scene.addItem(v.scene.line)
v.scene.line.setVisible(True)
self.updateCurserPosView()



def update_sagittal_slice_pos_indicator(self):
""" update the position of the axial slice indicator in the sagittal view """
for v in self.parent.parent.viewers:
if v.mode == 'axial':
slice_nav = self.parent.parent.sagittal_viewer.slice_nav
x1 = 0.0
x2 = self.parent.parent.annot_data.shape[2]
y1 = slice_nav.max_slice_idx - slice_nav.slice_idx
Expand All @@ -119,10 +148,11 @@ def update_axial_slice_pos_indicator(self):
else:
# add line if it doesn't exist
v.scene.line = QtWidgets.QGraphicsLineItem(x1, y1, x2, y2)
v.scene.line.setPen(QtGui.QPen(QtGui.QColor(255, 60, 60), 0.2,
QtCore.Qt.DashLine))
v.scene.line.setPen(QtGui.QPen(QtGui.QColor(255, 60, 60), 1.0,
QtCore.Qt.DotLine))
v.scene.addItem(v.scene.line)
v.scene.line.setVisible(True)
self.updateCurserPosView()

# FIXME: should we remove this commented out function?
# def flood_fill(self, x, y):
Expand Down Expand Up @@ -156,7 +186,6 @@ def update_axial_slice_pos_indicator(self):
# ]
# q_image = qimage2ndarray.array2qimage(np_rgba)
# return QtGui.QPixmap.fromImage(q_image)

def mousePressEvent(self, event):
super().mousePressEvent(event)
modifiers = QtWidgets.QApplication.keyboardModifiers()
Expand Down Expand Up @@ -317,6 +346,12 @@ def mouseMoveEvent(self, event):

pos = event.scenePos()
x, y = pos.x(), pos.y()
if self.parent.mode == 'axial':
self.last_ax_x = x
self.last_ax_y = y
elif self.parent.mode == 'sagittal':
self.last_sag_x = x
self.last_sag_y = y

if modifiers == QtCore.Qt.ControlModifier:
# if control key is pressed then don't do anything with the graphics scene
Expand Down Expand Up @@ -353,3 +388,53 @@ def mouseMoveEvent(self, event):

self.last_x = x
self.last_y = y
self.updateCurserPosView()

def updateCurserPosView(self):
#show the cursor position in the opposite viewer
for v in self.parent.parent.viewers:
if v.mode == 'sagittal':
slice_nav = self.parent.parent.axial_viewer.slice_nav
y1 = 0
y2 = self.parent.parent.annot_data.shape[2]
x1 = slice_nav.slice_idx
x1 += 0.5
x2 = x1
y_pos = min(max(y1, self.last_ax_x), y2)
self.last_ax_x = y_pos
if hasattr(v.scene, 'cursorPos'):
if y_pos != 0:
v.scene.cursorPos.setVisible(True)
v.scene.cursorPos.setLine(x1-4, y_pos, x1+4, y_pos)
else:
v.scene.cursorPos.setVisible(False)
else:
v.scene.cursorPos = QtWidgets.QGraphicsLineItem(x1-4, y_pos, x1+4, y_pos)

v.scene.cursorPos.setPen(QtGui.QPen(QtGui.QColor(255, 60, 60), 1.5,
QtCore.Qt.SolidLine))
v.scene.addItem(v.scene.cursorPos)
v.scene.cursorPos.setVisible(True)
if v.mode == 'axial':
slice_nav = self.parent.parent.sagittal_viewer.slice_nav
x1 = 0.0
x2 = self.parent.parent.annot_data.shape[2]
y1 = slice_nav.max_slice_idx - slice_nav.slice_idx
y1 += 0.5
y2 = y1
x_pos = min(max(x1, self.last_sag_y), x2)
self.last_sag_y = x_pos
if hasattr(v.scene, 'cursorPos'):
if x_pos != 0:
v.scene.cursorPos.setVisible(True)
v.scene.cursorPos.setLine(x_pos, y1-4, x_pos, y1+4)
else:
v.scene.cursorPos.setVisible(False)
else:
v.scene.cursorPos = QtWidgets.QGraphicsLineItem(x_pos, y1-4, x_pos, y1+4)

v.scene.cursorPos.setPen(QtGui.QPen(QtGui.QColor(255, 60, 60), 1.5,
QtCore.Qt.SolidLine))
v.scene.addItem(v.scene.cursorPos)
v.scene.cursorPos.setVisible(True)

1 change: 1 addition & 0 deletions painter/src/im_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def update_slice_index(self):
self.update_outline()

self.scene.update_axial_slice_pos_indicator()
self.scene.update_sagittal_slice_pos_indicator()

def keyPressEvent(self, event):
# if control key is pressed then hide the paint brush as the user wants to pan now.
Expand Down