Commit 6c8ae9b6cb4151257e9c7c029bc951fac1a03acb
1 parent
7f8d5bc7
Exists in
master
and in
68 other branches
ENH: Cursor is workin with multiple renderers
Showing
3 changed files
with
57 additions
and
29 deletions
Show diff stats
invesalius/data/cursor_actors.py
@@ -139,6 +139,12 @@ class CursorCircle: | @@ -139,6 +139,12 @@ class CursorCircle: | ||
139 | self.spacing = spacing | 139 | self.spacing = spacing |
140 | self.__calculate_area_pixels() | 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 | def GetPixels(self): | 148 | def GetPixels(self): |
143 | px, py, pz = self.edition_position | 149 | px, py, pz = self.edition_position |
144 | orient = self.orientation | 150 | orient = self.orientation |
invesalius/data/slice_data.py
@@ -3,3 +3,10 @@ class SliceData(object): | @@ -3,3 +3,10 @@ class SliceData(object): | ||
3 | self.renderer = None | 3 | self.renderer = None |
4 | self.actor = None | 4 | self.actor = None |
5 | self.number = 0 | 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,7 +112,7 @@ class Viewer(wx.Panel): | ||
112 | 'EDITOR': { | 112 | 'EDITOR': { |
113 | "MouseMoveEvent": self.OnBrushMove, | 113 | "MouseMoveEvent": self.OnBrushMove, |
114 | "LeftButtonPressEvent": self.OnBrushClick, | 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,6 +129,9 @@ class Viewer(wx.Panel): | ||
129 | style.AddObserver(event, | 129 | style.AddObserver(event, |
130 | action[mode][event]) | 130 | action[mode][event]) |
131 | 131 | ||
132 | + def OnEnter(self, obj, evt): | ||
133 | + print "Entrei" | ||
134 | + | ||
132 | def ChangeBrushSize(self, pubsub_evt): | 135 | def ChangeBrushSize(self, pubsub_evt): |
133 | size = pubsub_evt.data | 136 | size = pubsub_evt.data |
134 | self._brush_cursor_size = size | 137 | self._brush_cursor_size = size |
@@ -190,10 +193,10 @@ class Viewer(wx.Panel): | @@ -190,10 +193,10 @@ class Viewer(wx.Panel): | ||
190 | self.pick.Pick(mouse_x, mouse_y, 0, render) | 193 | self.pick.Pick(mouse_x, mouse_y, 0, render) |
191 | 194 | ||
192 | coord = self.get_coordinate_cursor() | 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 | self.get_coordinate_cursor_edition(slice_data)) | 198 | self.get_coordinate_cursor_edition(slice_data)) |
196 | - self.__update_cursor_position(coord) | 199 | + self.__update_cursor_position(slice_data, coord) |
197 | #render.Render() | 200 | #render.Render() |
198 | 201 | ||
199 | evt_msg = {const.BRUSH_ERASE: 'Erase mask pixel', | 202 | evt_msg = {const.BRUSH_ERASE: 'Erase mask pixel', |
@@ -202,7 +205,7 @@ class Viewer(wx.Panel): | @@ -202,7 +205,7 @@ class Viewer(wx.Panel): | ||
202 | msg = evt_msg[self._brush_cursor_op] | 205 | msg = evt_msg[self._brush_cursor_op] |
203 | 206 | ||
204 | pixels = itertools.ifilter(self.test_operation_position, | 207 | pixels = itertools.ifilter(self.test_operation_position, |
205 | - self.cursor.GetPixels()) | 208 | + slice_data.cursor.GetPixels()) |
206 | ps.Publisher().sendMessage(msg, pixels) | 209 | ps.Publisher().sendMessage(msg, pixels) |
207 | 210 | ||
208 | # FIXME: This is idiot, but is the only way that brush operations are | 211 | # FIXME: This is idiot, but is the only way that brush operations are |
@@ -214,12 +217,20 @@ class Viewer(wx.Panel): | @@ -214,12 +217,20 @@ class Viewer(wx.Panel): | ||
214 | mouse_x, mouse_y = self.interactor.GetEventPosition() | 217 | mouse_x, mouse_y = self.interactor.GetEventPosition() |
215 | render = self.interactor.FindPokedRenderer(mouse_x, mouse_y) | 218 | render = self.interactor.FindPokedRenderer(mouse_x, mouse_y) |
216 | slice_data = self.get_slice_data(render) | 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 | self.pick.Pick(mouse_x, mouse_y, 0, render) | 228 | self.pick.Pick(mouse_x, mouse_y, 0, render) |
218 | coord = self.get_coordinate_cursor() | 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 | self.get_coordinate_cursor_edition(slice_data)) | 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 | if self._brush_cursor_op == const.BRUSH_ERASE: | 235 | if self._brush_cursor_op == const.BRUSH_ERASE: |
225 | evt_msg = 'Erase mask pixel' | 236 | evt_msg = 'Erase mask pixel' |
@@ -230,7 +241,7 @@ class Viewer(wx.Panel): | @@ -230,7 +241,7 @@ class Viewer(wx.Panel): | ||
230 | 241 | ||
231 | if self.mouse_pressed: | 242 | if self.mouse_pressed: |
232 | pixels = itertools.ifilter(self.test_operation_position, | 243 | pixels = itertools.ifilter(self.test_operation_position, |
233 | - self.cursor.GetPixels()) | 244 | + slice_data.cursor.GetPixels()) |
234 | ps.Publisher().sendMessage(evt_msg, pixels) | 245 | ps.Publisher().sendMessage(evt_msg, pixels) |
235 | ps.Publisher().sendMessage('Update slice viewer') | 246 | ps.Publisher().sendMessage('Update slice viewer') |
236 | else: | 247 | else: |
@@ -372,8 +383,18 @@ class Viewer(wx.Panel): | @@ -372,8 +383,18 @@ class Viewer(wx.Panel): | ||
372 | (i+1)*proportion_x, (j+1)*proportion_y)) | 383 | (i+1)*proportion_x, (j+1)*proportion_y)) |
373 | slice_data = self.create_slice_window(image) | 384 | slice_data = self.create_slice_window(image) |
374 | slice_data.renderer.SetViewport(position) | 385 | slice_data.renderer.SetViewport(position) |
386 | + slice_data.SetCursor(self.__create_cursor()) | ||
375 | self.slice_data_list.append(slice_data) | 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 | def SetInput(self, imagedata): | 398 | def SetInput(self, imagedata): |
378 | self.imagedata = imagedata | 399 | self.imagedata = imagedata |
379 | 400 | ||
@@ -426,23 +447,15 @@ class Viewer(wx.Panel): | @@ -426,23 +447,15 @@ class Viewer(wx.Panel): | ||
426 | actor_bound = actor.GetBounds() | 447 | actor_bound = actor.GetBounds() |
427 | 448 | ||
428 | # Insert cursor | 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 | self.append_mode('EDITOR') | 452 | self.append_mode('EDITOR') |
440 | 453 | ||
441 | - def __update_cursor_position(self, position): | 454 | + def __update_cursor_position(self, slice_data, position): |
442 | x, y, z = position | 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 | yz = [actor_bound[1] + 1 + slice_number, y, z] | 460 | yz = [actor_bound[1] + 1 + slice_number, y, z] |
448 | xz = [x, actor_bound[3] - 1 - slice_number, z] | 461 | xz = [x, actor_bound[3] - 1 - slice_number, z] |
@@ -458,9 +471,9 @@ class Viewer(wx.Panel): | @@ -458,9 +471,9 @@ class Viewer(wx.Panel): | ||
458 | else: | 471 | else: |
459 | coordinates = {"SAGITAL": yz, "CORONAL": xz, "AXIAL": xy} | 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 | self.orientation = orientation | 477 | self.orientation = orientation |
465 | for slice_data in self.slice_data_list: | 478 | for slice_data in self.slice_data_list: |
466 | self.__update_camera(slice_data) | 479 | self.__update_camera(slice_data) |
@@ -474,6 +487,7 @@ class Viewer(wx.Panel): | @@ -474,6 +487,7 @@ class Viewer(wx.Panel): | ||
474 | slice_data = SliceData() | 487 | slice_data = SliceData() |
475 | slice_data.renderer = renderer | 488 | slice_data.renderer = renderer |
476 | slice_data.actor = actor | 489 | slice_data.actor = actor |
490 | + renderer.AddObserver("EnterEvent", self.OnEnter) | ||
477 | return slice_data | 491 | return slice_data |
478 | 492 | ||
479 | def __update_camera(self, slice_data): | 493 | def __update_camera(self, slice_data): |
@@ -558,13 +572,14 @@ class Viewer(wx.Panel): | @@ -558,13 +572,14 @@ class Viewer(wx.Panel): | ||
558 | slice_data.number = pos | 572 | slice_data.number = pos |
559 | self.__update_display_extent(slice_data) | 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 | def ChangeSliceNumber(self, pubsub_evt): | 584 | def ChangeSliceNumber(self, pubsub_evt): |
570 | index = pubsub_evt.data | 585 | index = pubsub_evt.data |