Skip to content

Commit

Permalink
Requested changes to draft PR.
Browse files Browse the repository at this point in the history
Slider now updates image correctly, albeit slow.
  • Loading branch information
Daniel Horton committed Oct 13, 2023
1 parent 9bae801 commit 41999cf
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 19 deletions.
14 changes: 7 additions & 7 deletions src/Model/Windowing.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ def windowing_model(text, init):
window = windowing_limits[0]
level = windowing_limits[1]

windowing_model_direct(window, level, init)
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
"""
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()
Expand Down
2 changes: 2 additions & 0 deletions src/View/mainpage/MainPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,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
47 changes: 39 additions & 8 deletions src/View/mainpage/WindowingSlider.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ class WindowingSlider(QWidget):
def __init__(self, width=50):
"""
Initialise the slider
:pram width: the fixed width of the widget
:param width: the fixed width of the widget
"""

super().__init__()
self.action_handler = None
if WindowingSlider.SINGLETON is None:
WindowingSlider.SINGLETON = self
set_windowing_slider(self)
Expand Down Expand Up @@ -92,7 +93,7 @@ def __init__(self, width=50):

# Get the values for window and level from the dict
patient_dict_container = PatientDictContainer()
# print(patient_dict_container.get("dict_windowing")) # testing
print(patient_dict_container.get("dict_windowing")) # testing
windowing_limits = patient_dict_container.get("dict_windowing")['Normal']

# Set window and level to the new values
Expand All @@ -111,6 +112,14 @@ def __init__(self, width=50):
# Test
self.set_density_histogram(gen_random_histogram())

def set_action_handler(self, action_handler):
"""
Sets the action handler.
The action handler can call update_views()
:param action_handler: the action handler
"""
self.action_handler = action_handler

def resizeEvent(self, event):
self.histogram.setPlotArea(
QtCore.QRectF(0, 0, self.fixed_width, event.size().height()))
Expand All @@ -132,12 +141,22 @@ def window_to_index(self, val):
Converts a window value to a slider index
:param val: a 0-2000 value
"""
normalized_val = val / 2000
# print(normalized_val)
normalized_val = val / 4096
print(normalized_val)
index = ceil(self.slider_density * (1 - normalized_val)) - 1
# print(index)
print(index)
return index

def index_to_window(self, index):
"""
Converts a slider index to a window value
:param index: a 0-2000 value
"""

percent = index / self.slider_density
val = round((1 - percent) * 4096)
return val

def set_bars_from_window(self, window, level):
"""
Triggered when the user selects a windowing preset.
Expand Down Expand Up @@ -170,6 +189,10 @@ def update_bar(self, index, top_bar=True):
:param top_bar: whether to move the top or bottom bar
"""

# Clamp index to range
index = max(index, 0)
index = min(index, self.slider_density-1)

if top_bar:
self.slider_bars[self.top].setColor("white")
self.top = index
Expand Down Expand Up @@ -251,9 +274,17 @@ def mouse_release(self, event):
False,
False,
False]
level = 100
window = 100
# windowing_model_direct(level, window, send)

top_bar = self.index_to_window(self.top)
bottom_bar = self.index_to_window(self.bottom)

level = (top_bar + bottom_bar) * 0.5
window = 2 * (bottom_bar - level)
level = level - 1000

windowing_model_direct(level, window, send)
if self.action_handler is not None:
self.action_handler.update_views()

def update_bar_position(self, event):
if self.selected_bar == "middle":
Expand Down
8 changes: 4 additions & 4 deletions test/test_view_dicom_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def test_object():
def test_one_view_handling(qtbot, test_object, init_config):
test_object.main_window.show()
test_object.main_window.action_handler.action_one_view.trigger()
assert isinstance(test_object.main_window.dicom_single_view, DicomView) is True
assert test_object.main_window.dicom_view.currentWidget() == test_object.main_window.dicom_single_view
assert isinstance(test_object.main_window.dicom_single_view_widget, DicomView) is True
assert test_object.main_window.dicom_view.currentWidget() == test_object.main_window.dicom_single_view_widget


def test_one_view_zoom(qtbot, test_object, init_config):
Expand All @@ -95,8 +95,8 @@ def test_four_view_handling(qtbot, test_object, init_config):
assert isinstance(test_object.main_window.dicom_axial_view, DicomView) is True
assert isinstance(test_object.main_window.dicom_sagittal_view, DicomView) is True
assert isinstance(test_object.main_window.dicom_coronal_view, DicomView) is True
assert isinstance(test_object.main_window.dicom_four_views_layout, QGridLayout) is True
assert test_object.main_window.dicom_view.currentWidget() == test_object.main_window.dicom_four_views
assert isinstance(test_object.main_window.dicom_four_views_slider_layout, QGridLayout) is True
assert test_object.main_window.dicom_view.currentWidget() == test_object.main_window.dicom_four_views_slider
assert test_object.main_window.dicom_axial_view.pos().x(), test_object.main_window.dicom_axial_view.pos().y() == (
0, 0)
assert test_object.main_window.dicom_sagittal_view.pos().x(), \
Expand Down

0 comments on commit 41999cf

Please sign in to comment.