From 2e9b3796fbdf6489451a56bc47b7728008ed628e Mon Sep 17 00:00:00 2001 From: Angeleene Ang Date: Thu, 7 Jul 2022 10:35:52 +0300 Subject: [PATCH 1/2] centerline help text + catch errors on recalculating centerline --- MRICenterline/app/centerline/calculate.py | 8 ---- .../app/gui_data_handling/centerline_model.py | 10 +++-- .../gui_data_handling/centerline_viewer.py | 39 ++++++++++++++++--- MRICenterline/gui/help/help_text.py | 9 +++++ 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/MRICenterline/app/centerline/calculate.py b/MRICenterline/app/centerline/calculate.py index 8249208..4e1d251 100644 --- a/MRICenterline/app/centerline/calculate.py +++ b/MRICenterline/app/centerline/calculate.py @@ -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]) diff --git a/MRICenterline/app/gui_data_handling/centerline_model.py b/MRICenterline/app/gui_data_handling/centerline_model.py index 57389b7..059caf1 100644 --- a/MRICenterline/app/gui_data_handling/centerline_model.py +++ b/MRICenterline/app/gui_data_handling/centerline_model.py @@ -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__) @@ -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) diff --git a/MRICenterline/app/gui_data_handling/centerline_viewer.py b/MRICenterline/app/gui_data_handling/centerline_viewer.py index d311d64..ebb1ca4 100644 --- a/MRICenterline/app/gui_data_handling/centerline_viewer.py +++ b/MRICenterline/app/gui_data_handling/centerline_viewer.py @@ -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 @@ -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) @@ -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() @@ -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) diff --git a/MRICenterline/gui/help/help_text.py b/MRICenterline/gui/help/help_text.py index e92a994..2737d91 100644 --- a/MRICenterline/gui/help/help_text.py +++ b/MRICenterline/gui/help/help_text.py @@ -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)) From 56bf11cbf7d97efb3ee8a063fd99116d4d5a7987 Mon Sep 17 00:00:00 2001 From: Angeleene Ang Date: Thu, 7 Jul 2022 11:11:44 +0300 Subject: [PATCH 2/2] implemented new case button --- MRICenterline/gui/display/toolbar.py | 4 +--- MRICenterline/gui/window/MainWindow.py | 14 ++++++++++++++ MRICenterline/gui/window/Toolbar.py | 5 +++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/MRICenterline/gui/display/toolbar.py b/MRICenterline/gui/display/toolbar.py index 85af714..25b1626 100644 --- a/MRICenterline/gui/display/toolbar.py +++ b/MRICenterline/gui/display/toolbar.py @@ -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 diff --git a/MRICenterline/gui/window/MainWindow.py b/MRICenterline/gui/window/MainWindow.py index a48269f..3822771 100644 --- a/MRICenterline/gui/window/MainWindow.py +++ b/MRICenterline/gui/window/MainWindow.py @@ -6,6 +6,9 @@ from MRICenterline import CFG, CONST +import logging +logging.getLogger(__name__) + class IUMainWindow(QMainWindow): widget_directory = dict() @@ -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) diff --git a/MRICenterline/gui/window/Toolbar.py b/MRICenterline/gui/window/Toolbar.py index 8ae8373..3d37697 100644 --- a/MRICenterline/gui/window/Toolbar.py +++ b/MRICenterline/gui/window/Toolbar.py @@ -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)