Commit 0b7e4b6275fe81817a4d17debb85fa3e2b39e02d

Authored by Thiago Franco de Moraes
1 parent bbbe83f1

watershed now have its own cursor object

invesalius/data/styles.py
... ... @@ -27,6 +27,7 @@ from wx.lib.pubsub import pub as Publisher
27 27  
28 28 import constants as const
29 29 import converters
  30 +import cursor_actors as ca
30 31 import numpy as np
31 32  
32 33 from scipy import ndimage
... ... @@ -741,6 +742,8 @@ class WatershedConfig(object):
741 742 def __init__(self):
742 743 self.operation = BRUSH_FOREGROUND
743 744 self.use_ww_wl = True
  745 + self.cursor_type = const.BRUSH_CIRCLE
  746 + self.cursor_size = const.BRUSH_SIZE
744 747  
745 748 Publisher.subscribe(self.set_operation, 'Set watershed operation')
746 749 Publisher.subscribe(self.set_use_ww_wl, 'Set use ww wl')
... ... @@ -781,6 +784,10 @@ class WaterShedInteractorStyle(DefaultInteractorStyle):
781 784  
782 785 Publisher.subscribe(self.expand_watershed, 'Expand watershed to 3D ' + self.orientation)
783 786 Publisher.subscribe(self.set_operation, 'Set watershed operation')
  787 + Publisher.subscribe(self.set_bsize, 'Set watershed brush size')
  788 + Publisher.subscribe(self.set_bformat, 'Set watershed brush format')
  789 +
  790 + self._set_cursor()
784 791  
785 792 def SetUp(self):
786 793 mask = self.viewer.slice_.current_mask.matrix
... ... @@ -810,9 +817,37 @@ class WaterShedInteractorStyle(DefaultInteractorStyle):
810 817 os.remove(self.temp_file)
811 818 print "deleting", self.temp_file
812 819  
  820 + def _set_cursor(self):
  821 + if self.config.cursor_type == const.BRUSH_SQUARE:
  822 + cursor = ca.CursorRectangle()
  823 + elif self.config.cursor_type == const.BRUSH_CIRCLE:
  824 + cursor = ca.CursorCircle()
  825 +
  826 + cursor.SetOrientation(self.orientation)
  827 + n = self.viewer.slice_data.number
  828 + coordinates = {"SAGITAL": [n, 0, 0],
  829 + "CORONAL": [0, n, 0],
  830 + "AXIAL": [0, 0, n]}
  831 + cursor.SetPosition(coordinates[self.orientation])
  832 + spacing = self.viewer.slice_.spacing
  833 + cursor.SetSpacing(spacing)
  834 + cursor.SetColour(self.viewer._brush_cursor_colour)
  835 + cursor.SetSize(self.config.cursor_size)
  836 + self.viewer.slice_data.SetCursor(cursor)
  837 + self.viewer.interactor.Render()
  838 +
813 839 def set_operation(self, pubsub_evt):
814 840 self.operation = WATERSHED_OPERATIONS[pubsub_evt.data]
815 841  
  842 + def set_bsize(self, pubsub_evt):
  843 + size = pubsub_evt.data
  844 + self.config.cursor_size = size
  845 + self.viewer.slice_data.cursor.SetSize(size)
  846 +
  847 + def set_bformat(self, pubsub_evt):
  848 + self.config.cursor_type = pubsub_evt.data
  849 + self._set_cursor()
  850 +
816 851 def OnEnterInteractor(self, obj, evt):
817 852 if (self.viewer.slice_.buffer_slices[self.orientation].mask is None):
818 853 return
... ...
invesalius/gui/task_slice.py
... ... @@ -839,14 +839,14 @@ class WatershedTool(EditionTools):
839 839  
840 840 self.btn_brush_format.SetBitmap(bitmap[evt.GetId()])
841 841  
842   - Publisher.sendMessage('Set brush format', brush[evt.GetId()])
  842 + Publisher.sendMessage('Set watershed brush format', brush[evt.GetId()])
843 843  
844 844 def OnBrushSize(self, evt):
845 845 """ """
846 846 # FIXME: Using wx.EVT_SPINCTRL in MacOS it doesnt capture changes only
847 847 # in the text ctrl - so we are capturing only changes on text
848 848 # Strangelly this is being called twice
849   - Publisher.sendMessage('Set edition brush size',self.spin.GetValue())
  849 + Publisher.sendMessage('Set watershed brush size',self.spin.GetValue())
850 850  
851 851 def OnComboBrushOp(self, evt):
852 852 brush_op = self.combo_brush_op.GetValue()
... ...