From 01b95e269ff76e4abb8a01ce3cf32bcf4bebc060 Mon Sep 17 00:00:00 2001 From: Daniel Horton Date: Fri, 13 Oct 2023 00:30:37 -0400 Subject: [PATCH] Adds constants to WindowSlider class. --- src/View/mainpage/WindowingSlider.py | 16 +++++++++------- test/test_view_structures_tab.py | 8 ++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/View/mainpage/WindowingSlider.py b/src/View/mainpage/WindowingSlider.py index acace08e..d63fad46 100644 --- a/src/View/mainpage/WindowingSlider.py +++ b/src/View/mainpage/WindowingSlider.py @@ -32,6 +32,10 @@ class WindowingSlider(QWidget): MAX_CLICK_DIST = 5 # Minimum rendering height for bottom bar MIN_BOTTOM_INDEX = 4 + # Window/Level consts + MAX_PIXEL_VALUE = 4096 + LEVEL_OFFSET = 1000 + SINGLETON = None def __init__(self, width=50): @@ -139,22 +143,20 @@ def height_to_index(self, pos): def window_to_index(self, val): """ Converts a window value to a slider index - :param val: a 0-2000 value + :param val: a value """ - normalized_val = val / 4096 - print(normalized_val) + normalized_val = val / WindowingSlider.MAX_PIXEL_VALUE index = ceil(self.slider_density * (1 - normalized_val)) - 1 - print(index) return index def index_to_window(self, index): """ Converts a slider index to a window value - :param index: a 0-2000 value + :param index: a value """ percent = index / self.slider_density - val = round((1 - percent) * 4096) + val = round((1 - percent) * WindowingSlider.MAX_PIXEL_VALUE) return val def set_bars_from_window(self, window, level): @@ -164,7 +166,7 @@ def set_bars_from_window(self, window, level): :param window: the window value of the preset :param level: the level value of the preset """ - level = level + 1000 + level = level + WindowingSlider.LEVEL_OFFSET self.update_bar( self.window_to_index(level - window * 0.5), top_bar=True) self.update_bar( diff --git a/test/test_view_structures_tab.py b/test/test_view_structures_tab.py index a86bae8c..ab87e49d 100644 --- a/test/test_view_structures_tab.py +++ b/test/test_view_structures_tab.py @@ -75,7 +75,7 @@ def __init__(self): self.main_window = MainWindow() self.main_window.show() - self.dicom_view = self.main_window.dicom_single_view + self.dicom_view = self.main_window.dicom_single_view_widget self.new_polygons = {} slider_id = self.dicom_view.slider.value() self.curr_slice = self.dicom_view.patient_dict_container.get("dict_uid")[slider_id] @@ -109,10 +109,10 @@ def test_structure_tab_check_checkboxes(test_object): test_object.new_polygons[name][test_object.curr_slice] = polygons # Get the actual dict_polygons_axial dictionary - view_polygons = test_object.main_window.dicom_single_view.patient_dict_container.get("dict_polygons_axial") + view_polygons = test_object.main_window.dicom_single_view_widget.patient_dict_container.get("dict_polygons_axial") # Get the currently selected ROIs - selected_rois = test_object.main_window.dicom_single_view.patient_dict_container.get("selected_rois") + selected_rois = test_object.main_window.dicom_single_view_widget.patient_dict_container.get("selected_rois") selected_roi_names = [] for selected_roi in selected_rois: selected_roi_names.append(test_object.rois[selected_roi]["name"]) @@ -153,7 +153,7 @@ def test_structure_tab_uncheck_checkboxes(test_object): del test_object.new_polygons[name] # Get the actual selected ROIs - selected_rois = test_object.main_window.dicom_single_view.patient_dict_container.get("selected_rois") + selected_rois = test_object.main_window.dicom_single_view_widget.patient_dict_container.get("selected_rois") selected_roi_names = [] for selected_roi in selected_rois: selected_roi_names.append(test_object.rois[selected_roi]["name"])