Skip to content

Commit

Permalink
Custom Windowing Slider (didymo#295)
Browse files Browse the repository at this point in the history
* merged Phil's xr-rtstruct.py and readxr.py to my OpenPatientWindow.py and ImageLoading.py changes.
RTSTRUCTs can be generated, and XR files with RTSTRUCTs can be opened, however they are not added automatically yet.
Additionally, the XR display needs adjustement.

* XR files now render inverted.
Temp RTSTRUCTS are now applied to XR files.
Removed some testing code from and renamed xr-rtstruct.py -> xrRtstruct.py.
IM000001 sample file can be opened, but IM000002-IM000004 cause issues.

* Allows images with uneven dimensions to be opened. Most CT files have equal dimensions, but CR files do not, requiring a change.
Made some requested changes.

* Add files via upload

* Revert "Add files via upload"

This reverts commit 6b39071.

* Add files via upload

* Contributions to the GUI by Phil.

* Requested changes to draft PR.
Slider now updates image correctly, albeit slow.

* Adds constants to WindowSlider class.

* Slider middle drag added.
Hopefully fixed tests.

* Fix the tests.

* Tests again.

---------

Co-authored-by: Daniel Horton <danielhorton4001>
  • Loading branch information
danielhorton4001 authored Oct 19, 2023
1 parent 31d3386 commit b11d334
Show file tree
Hide file tree
Showing 5 changed files with 393 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/Controller/ActionHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,10 @@ def one_view_handler(self):
self.is_four_view = False

self.__main_page.dicom_view.setCurrentWidget(
self.__main_page.dicom_single_view)
self.__main_page.dicom_single_view_widget)
self.__main_page.dicom_single_view.update_view()
self.__main_page.dicom_single_view_layout.addWidget(
self.__main_page.windowing_slider, 0, 0)

if hasattr(self.__main_page, 'image_fusion_view'):
self.has_image_registration_four = False
Expand All @@ -392,8 +394,10 @@ def four_views_handler(self):
self.is_four_view = True

self.__main_page.dicom_view.setCurrentWidget(
self.__main_page.dicom_four_views)
self.__main_page.dicom_four_views_slider)
self.__main_page.dicom_axial_view.update_view()
self.__main_page.dicom_four_views_slider_layout.addWidget(
self.__main_page.windowing_slider, 0, 0)

if hasattr(self.__main_page, 'image_fusion_view'):
self.has_image_registration_four = True
Expand Down
29 changes: 27 additions & 2 deletions src/Model/Windowing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
from src.Model.ImageFusion import get_fused_window


windowing_slider = None


def windowing_model(text, init):
"""
Function triggered when a window is selected from the menu.
:param text: The name of the window selected.
:param init: list of bool to determine which views are chosen
"""
patient_dict_container = PatientDictContainer()
moving_dict_container = MovingDictContainer()
pt_ct_dict_container = PTCTDictContainer()

# Get the values for window and level from the dict
windowing_limits = patient_dict_container.get("dict_windowing")[text]
Expand All @@ -22,6 +23,21 @@ def windowing_model(text, init):
window = windowing_limits[0]
level = windowing_limits[1]

windowing_model_direct(level, window, init)


def windowing_model_direct(level, window, init):
"""
Function triggered when a window is selected from the menu,
or when the windowing slider bars are adjusted
:param level: The desired level
:param window: The desired window
:param init: list of bool to determine which views are chosen
"""
patient_dict_container = PatientDictContainer()
moving_dict_container = MovingDictContainer()
pt_ct_dict_container = PTCTDictContainer()

# Update the dictionary of pixmaps with the update window and
# level values
if init[0]:
Expand Down Expand Up @@ -72,3 +88,12 @@ def windowing_model(text, init):
patient_dict_container.set("color_coronal", fusion_coronal)
patient_dict_container.set("color_sagittal", fusion_sagittal)
moving_dict_container.set("tfm", tfm)

# Update Slider
if windowing_slider is not None:
windowing_slider.set_bars_from_window(window, level)


def set_windowing_slider(slider):
global windowing_slider
windowing_slider = slider
24 changes: 21 additions & 3 deletions src/View/mainpage/MainPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from src.View.mainpage.DicomAxialView import DicomAxialView
from src.View.mainpage.DicomCoronalView import DicomCoronalView
from src.View.mainpage.DicomSagittalView import DicomSagittalView
from src.View.mainpage.WindowingSlider import WindowingSlider
from src.View.mainpage.IsodoseTab import IsodoseTab
from src.View.mainpage.MenuBar import MenuBar
from src.View.mainpage.DicomView3D import DicomView3D
Expand Down Expand Up @@ -102,6 +103,8 @@ def setup_actions(self):
self.toolbar = Toolbar(self.action_handler)
self.main_window_instance.addToolBar(
QtCore.Qt.TopToolBarArea, self.toolbar)
self.windowing_slider.set_action_handler(
self.action_handler)
self.main_window_instance.setWindowTitle("OnkoDICOM")

def setup_central_widget(self):
Expand Down Expand Up @@ -162,6 +165,7 @@ def setup_central_widget(self):
roi_color=roi_color_dict, iso_color=iso_color_dict,
cut_line_color=QtGui.QColor(0, 0, 255))
self.three_dimension_view = DicomView3D()
self.windowing_slider = WindowingSlider()

# Rescale the size of the scenes inside the 3-slice views
self.dicom_axial_view.zoom = INITIAL_FOUR_VIEW_ZOOM
Expand All @@ -173,18 +177,32 @@ def setup_central_widget(self):

self.dicom_four_views = QWidget()
self.dicom_four_views_layout = QGridLayout()

for i in range(2):
self.dicom_four_views_layout.setColumnStretch(i, 1)
self.dicom_four_views_layout.setRowStretch(i, 1)
self.dicom_four_views_layout.addWidget(self.dicom_axial_view, 0, 0)
self.dicom_four_views_layout.addWidget(self.dicom_sagittal_view, 0, 1)
self.dicom_four_views_layout.addWidget(self.dicom_coronal_view, 1, 0)
self.dicom_four_views_layout.addWidget(self.three_dimension_view, 1, 1)

self.dicom_four_views.setLayout(self.dicom_four_views_layout)

self.dicom_view.addWidget(self.dicom_four_views)
self.dicom_view.addWidget(self.dicom_single_view)
self.dicom_view.setCurrentWidget(self.dicom_single_view)
self.dicom_four_views_slider = QWidget()
self.dicom_four_views_slider_layout = QGridLayout()
self.dicom_four_views_slider_layout.addWidget(self.dicom_four_views, 0, 1)

self.dicom_four_views_slider.setLayout(self.dicom_four_views_slider_layout)

self.dicom_single_view_widget = QWidget()
self.dicom_single_view_layout = QGridLayout()
self.dicom_single_view_layout.addWidget(self.windowing_slider, 0, 0)
self.dicom_single_view_layout.addWidget(self.dicom_single_view, 0, 1)
self.dicom_single_view_widget.setLayout(self.dicom_single_view_layout)

self.dicom_view.addWidget(self.dicom_four_views_slider)
self.dicom_view.addWidget(self.dicom_single_view_widget)
self.dicom_view.setCurrentWidget(self.dicom_single_view_widget)

# Add DICOM View to right panel as a tab
self.right_panel.addTab(self.dicom_view, "DICOM View")
Expand Down
Loading

0 comments on commit b11d334

Please sign in to comment.