Commit 4209ef5f21f309aca08e6b272dc7ee10f8672b84

Authored by Thiago Franco de Moraes
1 parent ad467829

Interface to control mip

Showing 1 changed file with 61 additions and 15 deletions   Show diff stats
invesalius/data/viewer_slice.py
... ... @@ -58,23 +58,48 @@ ORIENTATIONS = {
58 58  
59 59  
60 60 class ContourMIPConfig(wx.Panel):
61   - def __init__(self, prnt):
  61 + def __init__(self, prnt, orientation):
62 62 wx.Panel.__init__(self, prnt)
63   - self.mip_size_spin = wx.SpinCtrl(self, -1, min=1, max=120, initial=1)
  63 + self.mip_size_spin = wx.SpinCtrl(self, -1, min=1, max=240, initial=1)
64 64 self.border_spin = FS.FloatSpin(self, -1, min_val=0, max_val=10,
65 65 increment=0.01, value=0.1,
66 66 agwStyle=FS.FS_LEFT)
  67 + self.inverted = wx.CheckBox(self, -1, "inverted")
  68 +
  69 + txt_mip_size = wx.StaticText(self, -1, "MIP size", style=wx.ALIGN_CENTER_HORIZONTAL)
  70 + txt_mip_border = wx.StaticText(self, -1, "Border")
67 71  
68 72 sizer = wx.BoxSizer(wx.HORIZONTAL)
69   - sizer.Add(self.mip_size_spin, 1, wx.EXPAND)
70   - sizer.Add(self.border_spin, 1, wx.EXPAND)
  73 + sizer.Add(txt_mip_size, 0, wx.EXPAND | wx.ALL, 2)
  74 + sizer.Add(self.mip_size_spin, 0, wx.EXPAND)
  75 + sizer.Add(txt_mip_border, 0, wx.EXPAND)
  76 + sizer.Add(self.border_spin, 0, wx.EXPAND)
  77 + sizer.Add(self.inverted, 1, wx.EXPAND)
71 78 self.SetSizer(sizer)
72 79 sizer.Fit(self)
73 80  
74 81 self.Layout()
75 82 self.Update()
76 83 self.SetAutoLayout(1)
  84 +
  85 + self.orientation = orientation
  86 +
  87 + self.mip_size_spin.Bind(wx.EVT_SPINCTRL, self.OnSetMIPSize)
  88 + self.border_spin.Bind(wx.EVT_SPINCTRL, self.OnSetMIPBorder)
  89 + self.inverted.Bind(wx.EVT_CHECKBOX, self.OnCheckInverted)
77 90  
  91 + def OnSetMIPSize(self, evt):
  92 + val = self.mip_size_spin.GetValue()
  93 + Publisher.sendMessage('Set MIP size %s' % self.orientation, val)
  94 +
  95 + def OnSetMIPBorder(self, evt):
  96 + val = self.border_spin.GetValue()
  97 + Publisher.sendMessage('Set MIP border %s' % self.orientation, val)
  98 +
  99 + def OnCheckInverted(self, evt):
  100 + val = self.inverted.GetValue()
  101 + Publisher.sendMessage('Set MIP Invert %s' % self.orientation, val)
  102 +
78 103  
79 104 class Viewer(wx.Panel):
80 105  
... ... @@ -90,6 +115,7 @@ class Viewer(wx.Panel):
90 115 self.right_pressed = 0
91 116  
92 117 self._number_slices = 10
  118 + self._mip_inverted = False
93 119  
94 120 self.spined_image = False #Use to control to spin
95 121 self.paned_image = False
... ... @@ -110,11 +136,11 @@ class Viewer(wx.Panel):
110 136 self.actors_by_slice_number = {}
111 137 self.renderers_by_slice_number = {}
112 138  
113   - self.__init_gui()
114   -
115 139 self.orientation = orientation
116 140 self.slice_number = 0
117 141  
  142 + self.__init_gui()
  143 +
118 144 self._brush_cursor_op = const.DEFAULT_BRUSH_OP
119 145 self._brush_cursor_size = const.BRUSH_SIZE
120 146 self._brush_cursor_colour = const.BRUSH_COLOUR
... ... @@ -139,7 +165,7 @@ class Viewer(wx.Panel):
139 165 scroll = wx.ScrollBar(self, -1, style=wx.SB_VERTICAL)
140 166 self.scroll = scroll
141 167  
142   - self.mip_ctrls = ContourMIPConfig(self)
  168 + self.mip_ctrls = ContourMIPConfig(self, self.orientation)
143 169  
144 170 sizer = wx.BoxSizer(wx.HORIZONTAL)
145 171 sizer.Add(self.interactor, 1, wx.EXPAND|wx.GROW)
... ... @@ -675,6 +701,12 @@ class Viewer(wx.Panel):
675 701 Publisher.subscribe(self.ReloadActualSlice, 'Reload actual slice')
676 702 Publisher.subscribe(self.OnUpdateScroll, 'Update scroll')
677 703  
  704 +
  705 + # MIP
  706 + Publisher.subscribe(self.OnSetMIPSize, 'Set MIP size %s' % self.orientation)
  707 + Publisher.subscribe(self.OnSetMIPBorder, 'Set MIP border %s' % self.orientation)
  708 + Publisher.subscribe(self.OnSetMIPInvert, 'Set MIP Invert %s' % self.orientation)
  709 +
678 710 def SetDefaultCursor(self, pusub_evt):
679 711 self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
680 712  
... ... @@ -771,9 +803,6 @@ class Viewer(wx.Panel):
771 803 self.interactor.Bind(wx.EVT_RIGHT_UP, self.OnContextMenu)
772 804 self.interactor.Bind(wx.EVT_SIZE, self.OnSize)
773 805  
774   - self.mip_ctrls.mip_size_spin.Bind(wx.EVT_SPINCTRL, self.OnSetMIPSize)
775   - self.mip_ctrls.border_spin.Bind(wx.EVT_SPINCTRL, self.OnSetMIPBorder)
776   -
777 806 def LoadImagedata(self, pubsub_evt):
778 807 imagedata, mask_dict = pubsub_evt.data
779 808 self.SetInput(imagedata, mask_dict)
... ... @@ -1098,6 +1127,15 @@ class Viewer(wx.Panel):
1098 1127  
1099 1128 elif evt.GetKeyCode() in projections:
1100 1129 print "PROJECTION MANOLO!"
  1130 + if evt.GetKeyCode() != wx.WXK_NUMPAD0 and self.slice_._type_projection == const.PROJECTION_NORMAL:
  1131 + self.mip_ctrls.Show()
  1132 + self.GetSizer().Add(self.mip_ctrls, 0, wx.EXPAND|wx.GROW|wx.ALL, 2)
  1133 + self.Layout()
  1134 + elif evt.GetKeyCode() == wx.WXK_NUMPAD0 and self.slice_._type_projection != const.PROJECTION_NORMAL:
  1135 + self.mip_ctrls.Hide()
  1136 + self.GetSizer().Remove(self.mip_ctrls)
  1137 + self.Layout()
  1138 +
1101 1139 self.slice_.SetTypeProjection(projections[evt.GetKeyCode()])
1102 1140 self.ReloadActualSlice()
1103 1141  
... ... @@ -1137,21 +1175,29 @@ class Viewer(wx.Panel):
1137 1175 self.slice_data.SetSize((w, h))
1138 1176 evt.Skip()
1139 1177  
1140   - def OnSetMIPSize(self, evt):
1141   - val = self.mip_ctrls.mip_size_spin.GetValue()
  1178 + def OnSetMIPSize(self, pubsub_evt):
  1179 + val = pubsub_evt.data
1142 1180 self.number_slices = val
1143 1181 self.ReloadActualSlice()
1144 1182  
1145   - def OnSetMIPBorder(self, evt):
1146   - val = self.mip_ctrls.border_spin.GetValue()
  1183 + def OnSetMIPBorder(self, pubsub_evt):
  1184 + val = pubsub_evt.data
1147 1185 self.slice_.n_border = val
1148 1186 buffer_ = self.slice_.buffer_slices[self.orientation]
1149 1187 buffer_.discard_buffer()
1150 1188 self.ReloadActualSlice()
1151 1189  
  1190 + def OnSetMIPInvert(self, pubsub_evt):
  1191 + val = pubsub_evt.data
  1192 + self._mip_inverted = val
  1193 + buffer_ = self.slice_.buffer_slices[self.orientation]
  1194 + buffer_.discard_buffer()
  1195 + self.ReloadActualSlice()
  1196 +
1152 1197 def set_slice_number(self, index):
  1198 + inverted = self.mip_ctrls.inverted.GetValue()
1153 1199 image = self.slice_.GetSlices(self.orientation, index,
1154   - self.number_slices)
  1200 + self.number_slices, inverted)
1155 1201 self.slice_data.actor.SetInput(image)
1156 1202 for actor in self.actors_by_slice_number.get(self.slice_data.number, []):
1157 1203 self.slice_data.renderer.RemoveActor(actor)
... ...