Skip to content

Commit

Permalink
Merge pull request #10 from TechnionComputationalMRILab/v4-qol-fixes
Browse files Browse the repository at this point in the history
various QoL fixes
  • Loading branch information
zemmyang authored Jul 7, 2022
2 parents 1bb0cf4 + 56bf11c commit 2e42061
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 20 deletions.
8 changes: 0 additions & 8 deletions MRICenterline/app/centerline/calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,10 @@ def __init__(self, all_points: List[np.array], image_data: ImageProperties,

self.Height = height

print(image_data.size)
print(image_data.nparray.shape)


print(all_points)

V_spacing = np.asarray(image_data.spacing)
V_dim = np.asarray(image_data.size)
self.V = np.reshape(np.transpose(image_data.nparray), V_dim)

print(self.V.shape)

self.x = np.linspace(-V_dim[0] * V_spacing[0] / 2, (V_dim[0]) * V_spacing[0] / 2, V_dim[0])
self.y = np.linspace(-V_dim[1] * V_spacing[1] / 2, (V_dim[1]) * V_spacing[1] / 2, V_dim[1])
self.z = np.linspace(-V_dim[2] * V_spacing[2] / 2, (V_dim[2]) * V_spacing[2] / 2, V_dim[2])
Expand Down
10 changes: 7 additions & 3 deletions MRICenterline/app/gui_data_handling/centerline_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from MRICenterline.app.points.point_array import PointArray
from MRICenterline.gui.vtk.line_actor import VerticalLine, VerticalLineArray

from MRICenterline import CFG
from MRICenterline import CFG, MSG

import logging
logging.getLogger(__name__)
Expand Down Expand Up @@ -62,8 +62,12 @@ def save(self):
print("save points")

def refresh_panel(self, angle_change=None, height_change=None):
self.calculate_centerline()
self.centerline_viewer.refresh_panel(angle_change, height_change)
try:
self.calculate_centerline()
self.centerline_viewer.refresh_panel(angle_change, height_change)
except Exception as e:
MSG.msg_box_warning(f'Error in calculating centerline: {e}')
logging.warning(f'Error in calculating centerline: {e}')

def pick(self, pick_coords):
point = Point(pick_coords, 0, None)
Expand Down
39 changes: 33 additions & 6 deletions MRICenterline/app/gui_data_handling/centerline_viewer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from vtkmodules.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
from vtkmodules.all import vtkImageActor, vtkImageReslice, vtkRenderer, vtkActor2D, vtkTextMapper, vtkTextProperty

from MRICenterline.gui.help.help_text import CenterlineInteractorHelpText
from MRICenterline.gui.vtk.IUCornerAnnotation import CornerLoc, IUCornerAnnotation
from MRICenterline.gui.vtk.text_actor import IUTextActor
from MRICenterline.gui.vtk.sequence_interactor_style import SequenceViewerInteractorStyle
from MRICenterline import CFG, CONST
Expand All @@ -25,8 +27,27 @@ def __init__(self,
self.panel_renderer = vtkRenderer()
self.removable_actor_list = []

self.height_text_actor = IUTextActor("Height: " + str(self.model.height), True, 0)
self.angle_text_actor = IUTextActor("Angle: " + str(self.model.angle), True, 1)
self.status_texts = {
"Height": self.model.height,
"Angle": self.model.angle,
}
self.status_text_actor = IUCornerAnnotation(CornerLoc.LOWER_LEFT)
self.help_text_actor = IUCornerAnnotation(CornerLoc.LOWER_RIGHT)

self.initialize_text()

# self.height_text_actor = IUTextActor("Height: " + str(self.model.height), True, 0)
# self.angle_text_actor = IUTextActor("Angle: " + str(self.model.angle), True, 1)

def initialize_text(self):
self.status_text_actor.SetInput(self.status_texts)
self.status_text_actor.SetColor(CFG.get_color('display', 'text-color'))

self.help_text_actor.SetInput(CenterlineInteractorHelpText.text_out)
self.help_text_actor.SetColor(CFG.get_color('display', 'help-text-color'))

self.panel_renderer.AddViewProp(self.status_text_actor)
self.panel_renderer.AddViewProp(self.help_text_actor)

def set_window_level(self):
self.panel_actor.GetProperty().SetColorWindow(self.model.window_value)
Expand Down Expand Up @@ -60,8 +81,8 @@ def initialize_panel(self):
self.connect_panel_actor()
self.set_window_level()

self.panel_renderer.AddActor(self.height_text_actor)
self.panel_renderer.AddActor(self.angle_text_actor)
# self.panel_renderer.AddActor(self.height_text_actor)
# self.panel_renderer.AddActor(self.angle_text_actor)

self.reslice.Update()
self.window.Render()
Expand Down Expand Up @@ -95,12 +116,18 @@ def refresh_panel(self, angle_change=None, height_change=None):
self.reslice.Update()

if angle_change:
self.angle_text_actor.SetInput("Angle: " + str(self.model.angle))
self.update_status_text("Angle", str(self.model.angle))
# self.angle_text_actor.SetInput("Angle: " + str(self.model.angle))
if height_change:
self.height_text_actor.SetInput("Height: " + str(self.model.height))
self.update_status_text("Height", str(self.model.height))
# self.height_text_actor.SetInput("Height: " + str(self.model.height))

self.window.Render()

def update_status_text(self, key, val):
self.status_texts[key] = val
self.status_text_actor.SetInput(self.status_texts)

def clear_removable_actors(self):
for actor in self.removable_actor_list:
self.panel_renderer.RemoveActor(actor)
Expand Down
4 changes: 1 addition & 3 deletions MRICenterline/gui/display/toolbar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import time
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QWidget, QGridLayout, QPushButton, QSpacerItem, QSizePolicy, QLabel
from PyQt5.QtWidgets import QWidget, QGridLayout, QPushButton
import qtawesome as qta

from MRICenterline.app.points.status import PickerStatus, PointStatus
Expand Down
9 changes: 9 additions & 0 deletions MRICenterline/gui/help/help_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ class InteractorHelpText:
text_length = len(text_array)
text_color = CFG.get_color('display', 'help-text-color')
text_out = "{}".format("\n".join(text_array))


class CenterlineInteractorHelpText:
text_array = ["HELP",
'Middle scroll wheel: change angle',
"Shift + Middle scroll wheel: change height"]
text_length = len(text_array)
text_color = CFG.get_color('display', 'help-text-color')
text_out = "{}".format("\n".join(text_array))
14 changes: 14 additions & 0 deletions MRICenterline/gui/window/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

from MRICenterline import CFG, CONST

import logging
logging.getLogger(__name__)


class IUMainWindow(QMainWindow):
widget_directory = dict()
Expand Down Expand Up @@ -35,3 +38,14 @@ def add_widget(self, widget: QWidget):
index = self.main_widget.addWidget(widget)
self.main_widget.setCurrentIndex(index)
self.widget_directory[index] = widget

def open_new_case(self):
if len(self.widget_directory) >= 2:
logging.info("New case button clicked")
self.main_widget.setCurrentIndex(0)
self.main_widget.removeWidget(self.widget_directory[1])

self.removeToolBar(self.toolbar)
self.addToolBar(IUToolbar(self))

self.setWindowTitle(CONST.WINDOW_NAME)
5 changes: 5 additions & 0 deletions MRICenterline/gui/window/Toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ def __init__(self, parent=None):

self.setMovable(False)

new_case_button = QPushButton(qta.icon('fa.gear'), "New Case")
new_case_button.setFlat(True)
self.addWidget(new_case_button)
new_case_button.clicked.connect(parent.open_new_case)

setting_button = QPushButton(qta.icon('fa.gear'), "Settings")
setting_button.setFlat(True)
self.addWidget(setting_button)
Expand Down

0 comments on commit 2e42061

Please sign in to comment.