Commit d17cea011eab997bebc73761fa16e037e483db26
1 parent
dbecc12e
Exists in
watershed_improvements_bkp
Created a class to store watershed configs
Showing
1 changed file
with
15 additions
and
2 deletions
Show diff stats
invesalius/data/styles.py
| @@ -34,6 +34,8 @@ from scipy.misc import imsave | @@ -34,6 +34,8 @@ from scipy.misc import imsave | ||
| 34 | from skimage.morphology import watershed | 34 | from skimage.morphology import watershed |
| 35 | from skimage import filter | 35 | from skimage import filter |
| 36 | 36 | ||
| 37 | +import utils | ||
| 38 | + | ||
| 37 | ORIENTATIONS = { | 39 | ORIENTATIONS = { |
| 38 | "AXIAL": const.AXIAL, | 40 | "AXIAL": const.AXIAL, |
| 39 | "CORONAL": const.CORONAL, | 41 | "CORONAL": const.CORONAL, |
| @@ -734,6 +736,16 @@ class EditorInteractorStyle(DefaultInteractorStyle): | @@ -734,6 +736,16 @@ class EditorInteractorStyle(DefaultInteractorStyle): | ||
| 734 | return x, y, z | 736 | return x, y, z |
| 735 | 737 | ||
| 736 | 738 | ||
| 739 | +class WatershedConfig(object): | ||
| 740 | + __metaclass__= utils.Singleton | ||
| 741 | + def __init__(self): | ||
| 742 | + self.operation = BRUSH_FOREGROUND | ||
| 743 | + Publisher.subscribe(self.set_operation, 'Set watershed operation') | ||
| 744 | + | ||
| 745 | + def set_operation(self, pubsub_evt): | ||
| 746 | + self.operation = WATERSHED_OPERATIONS[pubsub_evt.data] | ||
| 747 | + | ||
| 748 | + | ||
| 737 | class WaterShedInteractorStyle(DefaultInteractorStyle): | 749 | class WaterShedInteractorStyle(DefaultInteractorStyle): |
| 738 | def __init__(self, viewer): | 750 | def __init__(self, viewer): |
| 739 | DefaultInteractorStyle.__init__(self, viewer) | 751 | DefaultInteractorStyle.__init__(self, viewer) |
| @@ -745,6 +757,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | @@ -745,6 +757,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | ||
| 745 | self.operation = BRUSH_FOREGROUND | 757 | self.operation = BRUSH_FOREGROUND |
| 746 | 758 | ||
| 747 | self.mg_size = 3 | 759 | self.mg_size = 3 |
| 760 | + self.config = WatershedConfig() | ||
| 748 | 761 | ||
| 749 | self.picker = vtk.vtkWorldPointPicker() | 762 | self.picker = vtk.vtkWorldPointPicker() |
| 750 | 763 | ||
| @@ -869,7 +882,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | @@ -869,7 +882,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | ||
| 869 | if position < 0: | 882 | if position < 0: |
| 870 | position = viewer.calculate_matrix_position(coord) | 883 | position = viewer.calculate_matrix_position(coord) |
| 871 | 884 | ||
| 872 | - operation = self.operation | 885 | + operation = self.config.operation |
| 873 | 886 | ||
| 874 | if operation == BRUSH_FOREGROUND: | 887 | if operation == BRUSH_FOREGROUND: |
| 875 | if iren.GetControlKey(): | 888 | if iren.GetControlKey(): |
| @@ -937,7 +950,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | @@ -937,7 +950,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | ||
| 937 | if position < 0: | 950 | if position < 0: |
| 938 | position = viewer.calculate_matrix_position(coord) | 951 | position = viewer.calculate_matrix_position(coord) |
| 939 | 952 | ||
| 940 | - operation = self.operation | 953 | + operation = self.config.operation |
| 941 | 954 | ||
| 942 | if operation == BRUSH_FOREGROUND: | 955 | if operation == BRUSH_FOREGROUND: |
| 943 | if iren.GetControlKey(): | 956 | if iren.GetControlKey(): |