Skip to content

Commit

Permalink
Adds constants to WindowSlider class.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Horton committed Oct 13, 2023
1 parent 41999cf commit 01b95e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
16 changes: 9 additions & 7 deletions src/View/mainpage/WindowingSlider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions test/test_view_structures_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"])
Expand Down Expand Up @@ -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"])
Expand Down

0 comments on commit 01b95e2

Please sign in to comment.