Commit 6c8ae9b6cb4151257e9c7c029bc951fac1a03acb

Authored by tfmoraes
1 parent 7f8d5bc7

ENH: Cursor is workin with multiple renderers

invesalius/data/cursor_actors.py
... ... @@ -139,6 +139,12 @@ class CursorCircle:
139 139 self.spacing = spacing
140 140 self.__calculate_area_pixels()
141 141  
  142 + def Show(self, value=1):
  143 + if value:
  144 + self.actor.VisibilityOn()
  145 + else:
  146 + self.actor.VisibilityOff()
  147 +
142 148 def GetPixels(self):
143 149 px, py, pz = self.edition_position
144 150 orient = self.orientation
... ...
invesalius/data/slice_data.py
... ... @@ -3,3 +3,10 @@ class SliceData(object):
3 3 self.renderer = None
4 4 self.actor = None
5 5 self.number = 0
  6 + self.cursor = None
  7 +
  8 + def SetCursor(self, cursor):
  9 + if self.cursor:
  10 + self.renderer.RemoveActor(self.cursor.actor)
  11 + self.renderer.AddActor(cursor.actor)
  12 + self.cursor = cursor
... ...
invesalius/data/viewer_slice.py
... ... @@ -112,7 +112,7 @@ class Viewer(wx.Panel):
112 112 'EDITOR': {
113 113 "MouseMoveEvent": self.OnBrushMove,
114 114 "LeftButtonPressEvent": self.OnBrushClick,
115   - "LeftButtonReleaseEvent": self.OnMouseRelease
  115 + "LeftButtonReleaseEvent": self.OnMouseRelease,
116 116 }
117 117 }
118 118  
... ... @@ -129,6 +129,9 @@ class Viewer(wx.Panel):
129 129 style.AddObserver(event,
130 130 action[mode][event])
131 131  
  132 + def OnEnter(self, obj, evt):
  133 + print "Entrei"
  134 +
132 135 def ChangeBrushSize(self, pubsub_evt):
133 136 size = pubsub_evt.data
134 137 self._brush_cursor_size = size
... ... @@ -190,10 +193,10 @@ class Viewer(wx.Panel):
190 193 self.pick.Pick(mouse_x, mouse_y, 0, render)
191 194  
192 195 coord = self.get_coordinate_cursor()
193   - self.cursor.SetPosition(coord)
194   - self.cursor.SetEditionPosition(
  196 + slice_data.cursor.SetPosition(coord)
  197 + slice_data.cursor.SetEditionPosition(
195 198 self.get_coordinate_cursor_edition(slice_data))
196   - self.__update_cursor_position(coord)
  199 + self.__update_cursor_position(slice_data, coord)
197 200 #render.Render()
198 201  
199 202 evt_msg = {const.BRUSH_ERASE: 'Erase mask pixel',
... ... @@ -202,7 +205,7 @@ class Viewer(wx.Panel):
202 205 msg = evt_msg[self._brush_cursor_op]
203 206  
204 207 pixels = itertools.ifilter(self.test_operation_position,
205   - self.cursor.GetPixels())
  208 + slice_data.cursor.GetPixels())
206 209 ps.Publisher().sendMessage(msg, pixels)
207 210  
208 211 # FIXME: This is idiot, but is the only way that brush operations are
... ... @@ -214,12 +217,20 @@ class Viewer(wx.Panel):
214 217 mouse_x, mouse_y = self.interactor.GetEventPosition()
215 218 render = self.interactor.FindPokedRenderer(mouse_x, mouse_y)
216 219 slice_data = self.get_slice_data(render)
  220 +
  221 + # TODO: Improve!
  222 + for i in self.slice_data_list:
  223 + if i is slice_data:
  224 + i.cursor.Show()
  225 + else:
  226 + i.cursor.Show(0)
  227 +
217 228 self.pick.Pick(mouse_x, mouse_y, 0, render)
218 229 coord = self.get_coordinate_cursor()
219   - self.cursor.SetPosition(coord)
220   - self.cursor.SetEditionPosition(
  230 + slice_data.cursor.SetPosition(coord)
  231 + slice_data.cursor.SetEditionPosition(
221 232 self.get_coordinate_cursor_edition(slice_data))
222   - self.__update_cursor_position(coord)
  233 + self.__update_cursor_position(slice_data, coord)
223 234  
224 235 if self._brush_cursor_op == const.BRUSH_ERASE:
225 236 evt_msg = 'Erase mask pixel'
... ... @@ -230,7 +241,7 @@ class Viewer(wx.Panel):
230 241  
231 242 if self.mouse_pressed:
232 243 pixels = itertools.ifilter(self.test_operation_position,
233   - self.cursor.GetPixels())
  244 + slice_data.cursor.GetPixels())
234 245 ps.Publisher().sendMessage(evt_msg, pixels)
235 246 ps.Publisher().sendMessage('Update slice viewer')
236 247 else:
... ... @@ -372,8 +383,18 @@ class Viewer(wx.Panel):
372 383 (i+1)*proportion_x, (j+1)*proportion_y))
373 384 slice_data = self.create_slice_window(image)
374 385 slice_data.renderer.SetViewport(position)
  386 + slice_data.SetCursor(self.__create_cursor())
375 387 self.slice_data_list.append(slice_data)
376 388  
  389 + def __create_cursor(self):
  390 + cursor = ca.CursorCircle()
  391 + cursor.SetOrientation(self.orientation)
  392 + #self.__update_cursor_position([i for i in actor_bound[1::2]])
  393 + cursor.SetColour(self._brush_cursor_colour)
  394 + cursor.SetSpacing(self.imagedata.GetSpacing())
  395 + cursor.Show(0)
  396 + return cursor
  397 +
377 398 def SetInput(self, imagedata):
378 399 self.imagedata = imagedata
379 400  
... ... @@ -426,23 +447,15 @@ class Viewer(wx.Panel):
426 447 actor_bound = actor.GetBounds()
427 448  
428 449 # Insert cursor
429   - cursor = ca.CursorCircle()
430   - cursor.SetOrientation(self.orientation)
431   - self.__update_cursor_position([i for i in actor_bound[1::2]])
432   - cursor.SetColour(self._brush_cursor_colour)
433   - cursor.SetSpacing(imagedata.GetSpacing())
434   - self.ren.AddActor(cursor.actor)
435   - self.ren.Render()
436 450  
437   - self.cursor = cursor
438 451  
439 452 self.append_mode('EDITOR')
440 453  
441   - def __update_cursor_position(self, position):
  454 + def __update_cursor_position(self, slice_data, position):
442 455 x, y, z = position
443   - if (self.cursor):
444   - slice_number = self.slice_number
445   - actor_bound = self.actor.GetBounds()
  456 + if (slice_data.cursor):
  457 + slice_number = slice_data.number
  458 + actor_bound = slice_data.actor.GetBounds()
446 459  
447 460 yz = [actor_bound[1] + 1 + slice_number, y, z]
448 461 xz = [x, actor_bound[3] - 1 - slice_number, z]
... ... @@ -458,9 +471,9 @@ class Viewer(wx.Panel):
458 471 else:
459 472 coordinates = {"SAGITAL": yz, "CORONAL": xz, "AXIAL": xy}
460 473  
461   - self.cursor.SetPosition(coordinates[self.orientation])
  474 + slice_data.cursor.SetPosition(coordinates[self.orientation])
462 475  
463   - def set_orientation(self, orientation):
  476 + def SetOrientation(self, orientation):
464 477 self.orientation = orientation
465 478 for slice_data in self.slice_data_list:
466 479 self.__update_camera(slice_data)
... ... @@ -474,6 +487,7 @@ class Viewer(wx.Panel):
474 487 slice_data = SliceData()
475 488 slice_data.renderer = renderer
476 489 slice_data.actor = actor
  490 + renderer.AddObserver("EnterEvent", self.OnEnter)
477 491 return slice_data
478 492  
479 493 def __update_camera(self, slice_data):
... ... @@ -558,13 +572,14 @@ class Viewer(wx.Panel):
558 572 slice_data.number = pos
559 573 self.__update_display_extent(slice_data)
560 574  
561   - position = {"SAGITAL": {0: self.slice_number},
562   - "CORONAL": {1: self.slice_number},
563   - "AXIAL": {2: self.slice_number}}
  575 + position = {"SAGITAL": {0: slice_data.number},
  576 + "CORONAL": {1: slice_data.number},
  577 + "AXIAL": {2: slice_data.number}}
564 578  
565   - if 'DEFAULT' in self.modes:
566   - ps.Publisher().sendMessage('Update cursor single position in slice',
567   - position[self.orientation])
  579 + if 'DEFAULT' in self.modes:
  580 + ps.Publisher().sendMessage(
  581 + 'Update cursor single position in slice',
  582 + position[self.orientation])
568 583  
569 584 def ChangeSliceNumber(self, pubsub_evt):
570 585 index = pubsub_evt.data
... ...