Commit 956ad569117ae585f8ec93389df5a62213890c7c
Committed by
GitHub
Exists in
master
Merge pull request #431 from rmatsuda/fix_arrows_markers_id
Fix arrows markers
Showing
2 changed files
with
62 additions
and
61 deletions
Show diff stats
invesalius/data/viewer_volume.py
@@ -281,7 +281,6 @@ class Viewer(wx.Panel): | @@ -281,7 +281,6 @@ class Viewer(wx.Panel): | ||
281 | 281 | ||
282 | # Related to marker creation in navigation tools | 282 | # Related to marker creation in navigation tools |
283 | Publisher.subscribe(self.AddMarker, 'Add marker') | 283 | Publisher.subscribe(self.AddMarker, 'Add marker') |
284 | - Publisher.subscribe(self.AddMarkerwithOrientation, 'Add arrow marker') | ||
285 | Publisher.subscribe(self.HideAllMarkers, 'Hide all markers') | 284 | Publisher.subscribe(self.HideAllMarkers, 'Hide all markers') |
286 | Publisher.subscribe(self.ShowAllMarkers, 'Show all markers') | 285 | Publisher.subscribe(self.ShowAllMarkers, 'Show all markers') |
287 | Publisher.subscribe(self.RemoveAllMarkers, 'Remove all markers') | 286 | Publisher.subscribe(self.RemoveAllMarkers, 'Remove all markers') |
@@ -616,7 +615,7 @@ class Viewer(wx.Panel): | @@ -616,7 +615,7 @@ class Viewer(wx.Panel): | ||
616 | target = marker["target"] | 615 | target = marker["target"] |
617 | 616 | ||
618 | self.AddMarker( | 617 | self.AddMarker( |
619 | - ball_id=ball_id, | 618 | + marker_id=ball_id, |
620 | size=size, | 619 | size=size, |
621 | colour=colour, | 620 | colour=colour, |
622 | coord=position, | 621 | coord=position, |
@@ -631,49 +630,28 @@ class Viewer(wx.Panel): | @@ -631,49 +630,28 @@ class Viewer(wx.Panel): | ||
631 | 630 | ||
632 | self.UpdateRender() | 631 | self.UpdateRender() |
633 | 632 | ||
634 | - def AddMarkerwithOrientation(self, arrow_id, size, color, coord): | ||
635 | - """ | ||
636 | - Markers arrow with orientation created by navigation tools and rendered in volume viewer. | ||
637 | - """ | ||
638 | - self.arrow_marker_id = arrow_id | ||
639 | - coord_flip = list(coord) | ||
640 | - coord_flip[1] = -coord_flip[1] | ||
641 | - | ||
642 | - arrow_actor = self.Add_ObjectArrow(coord_flip[:3], coord_flip[3:6], color, size) | ||
643 | - self.static_markers.append(arrow_actor) | ||
644 | - self.ren.AddActor(self.static_markers[self.arrow_marker_id]) | ||
645 | - self.arrow_marker_id += 1 | ||
646 | - | ||
647 | - self.Refresh() | ||
648 | - | ||
649 | - def AddMarker(self, ball_id, size, colour, coord): | 633 | + def AddMarker(self, marker_id, size, colour, coord, arrow_flag): |
650 | """ | 634 | """ |
651 | Markers created by navigation tools and rendered in volume viewer. | 635 | Markers created by navigation tools and rendered in volume viewer. |
652 | """ | 636 | """ |
653 | - self.ball_id = ball_id | 637 | + self.marker_id = marker_id |
654 | coord_flip = list(coord) | 638 | coord_flip = list(coord) |
655 | coord_flip[1] = -coord_flip[1] | 639 | coord_flip[1] = -coord_flip[1] |
656 | 640 | ||
657 | - ball_ref = vtk.vtkSphereSource() | ||
658 | - ball_ref.SetRadius(size) | ||
659 | - ball_ref.SetCenter(coord_flip) | ||
660 | - | ||
661 | - mapper = vtk.vtkPolyDataMapper() | ||
662 | - mapper.SetInputConnection(ball_ref.GetOutputPort()) | ||
663 | - | ||
664 | - prop = vtk.vtkProperty() | ||
665 | - prop.SetColor(colour) | ||
666 | - | ||
667 | - # adding a new actor for the present ball | ||
668 | - self.static_markers.append(vtk.vtkActor()) | 641 | + if arrow_flag: |
642 | + """ | ||
643 | + Markers arrow with orientation created by navigation tools and rendered in volume viewer. | ||
644 | + """ | ||
645 | + marker_actor = self.CreateActorArrow(coord_flip[:3], coord_flip[3:6], colour, const.ARROW_MARKER_SIZE) | ||
646 | + else: | ||
647 | + marker_actor = self.CreateActorBall(coord_flip[:3], colour, size) | ||
669 | 648 | ||
670 | - self.static_markers[self.ball_id].SetMapper(mapper) | ||
671 | - self.static_markers[self.ball_id].SetProperty(prop) | 649 | + # adding a new actor for the marker |
650 | + self.static_markers.append(marker_actor) | ||
672 | 651 | ||
673 | - self.ren.AddActor(self.static_markers[self.ball_id]) | ||
674 | - self.ball_id += 1 | 652 | + self.ren.AddActor(self.static_markers[self.marker_id]) |
653 | + self.marker_id += 1 | ||
675 | 654 | ||
676 | - #self.UpdateRender() | ||
677 | self.Refresh() | 655 | self.Refresh() |
678 | 656 | ||
679 | def add_marker(self, coord, color): | 657 | def add_marker(self, coord, color): |
@@ -726,7 +704,7 @@ class Viewer(wx.Panel): | @@ -726,7 +704,7 @@ class Viewer(wx.Panel): | ||
726 | for i in reversed(index): | 704 | for i in reversed(index): |
727 | self.ren.RemoveActor(self.static_markers[i]) | 705 | self.ren.RemoveActor(self.static_markers[i]) |
728 | del self.static_markers[i] | 706 | del self.static_markers[i] |
729 | - self.ball_id = self.ball_id - 1 | 707 | + self.marker_id = self.marker_id - 1 |
730 | self.UpdateRender() | 708 | self.UpdateRender() |
731 | 709 | ||
732 | def BlinkMarker(self, index): | 710 | def BlinkMarker(self, index): |
@@ -1383,8 +1361,8 @@ class Viewer(wx.Panel): | @@ -1383,8 +1361,8 @@ class Viewer(wx.Panel): | ||
1383 | self.y_actor = self.add_line([0., 0., 0.], [0., 1., 0.], color=[.0, 1.0, .0]) | 1361 | self.y_actor = self.add_line([0., 0., 0.], [0., 1., 0.], color=[.0, 1.0, .0]) |
1384 | self.z_actor = self.add_line([0., 0., 0.], [0., 0., 1.], color=[1.0, .0, .0]) | 1362 | self.z_actor = self.add_line([0., 0., 0.], [0., 0., 1.], color=[1.0, .0, .0]) |
1385 | 1363 | ||
1386 | - self.obj_projection_arrow_actor = self.Add_ObjectArrow([0., 0., 0.], [0., 0., 0.], vtk_colors.GetColor3d('Red'), | ||
1387 | - 8) | 1364 | + self.obj_projection_arrow_actor = self.CreateActorArrow([0., 0., 0.], [0., 0., 0.], vtk_colors.GetColor3d('Red'), |
1365 | + 8) | ||
1388 | self.object_orientation_torus_actor = self.Add_Torus([0., 0., 0.], [0., 0., 0.], | 1366 | self.object_orientation_torus_actor = self.Add_Torus([0., 0., 0.], [0., 0., 0.], |
1389 | vtk_colors.GetColor3d('Red')) | 1367 | vtk_colors.GetColor3d('Red')) |
1390 | 1368 | ||
@@ -1449,9 +1427,24 @@ class Viewer(wx.Panel): | @@ -1449,9 +1427,24 @@ class Viewer(wx.Panel): | ||
1449 | 1427 | ||
1450 | return torusActor | 1428 | return torusActor |
1451 | 1429 | ||
1452 | - def Add_ObjectArrow(self, direction, orientation, color=[0.0, 0.0, 1.0], size=2): | ||
1453 | - vtk_colors = vtk.vtkNamedColors() | 1430 | + def CreateActorBall(self, coord_flip, colour=[0.0, 0.0, 1.0], size=2): |
1431 | + ball_ref = vtk.vtkSphereSource() | ||
1432 | + ball_ref.SetRadius(size) | ||
1433 | + ball_ref.SetCenter(coord_flip) | ||
1434 | + | ||
1435 | + mapper = vtk.vtkPolyDataMapper() | ||
1436 | + mapper.SetInputConnection(ball_ref.GetOutputPort()) | ||
1437 | + | ||
1438 | + prop = vtk.vtkProperty() | ||
1439 | + prop.SetColor(colour) | ||
1454 | 1440 | ||
1441 | + actor = vtk.vtkActor() | ||
1442 | + actor.SetMapper(mapper) | ||
1443 | + actor.SetProperty(prop) | ||
1444 | + | ||
1445 | + return actor | ||
1446 | + | ||
1447 | + def CreateActorArrow(self, direction, orientation, colour=[0.0, 0.0, 1.0], size=const.ARROW_MARKER_SIZE): | ||
1455 | arrow = vtk.vtkArrowSource() | 1448 | arrow = vtk.vtkArrowSource() |
1456 | arrow.SetTipResolution(40) | 1449 | arrow.SetTipResolution(40) |
1457 | arrow.SetShaftResolution(40) | 1450 | arrow.SetShaftResolution(40) |
@@ -1464,7 +1457,7 @@ class Viewer(wx.Panel): | @@ -1464,7 +1457,7 @@ class Viewer(wx.Panel): | ||
1464 | 1457 | ||
1465 | actor = vtk.vtkActor() | 1458 | actor = vtk.vtkActor() |
1466 | actor.SetMapper(mapper) | 1459 | actor.SetMapper(mapper) |
1467 | - actor.GetProperty().SetColor(color) | 1460 | + actor.GetProperty().SetColor(colour) |
1468 | actor.GetProperty().SetLineWidth(5) | 1461 | actor.GetProperty().SetLineWidth(5) |
1469 | actor.AddPosition(0, 0, 0) | 1462 | actor.AddPosition(0, 0, 0) |
1470 | actor.SetScale(size) | 1463 | actor.SetScale(size) |
invesalius/gui/task_navigator.py
@@ -172,13 +172,16 @@ class InnerFoldPanel(wx.Panel): | @@ -172,13 +172,16 @@ class InnerFoldPanel(wx.Panel): | ||
172 | fold_panel = fpb.FoldPanelBar(self, -1, wx.DefaultPosition, | 172 | fold_panel = fpb.FoldPanelBar(self, -1, wx.DefaultPosition, |
173 | (10, 330), 0, fpb.FPB_SINGLE_FOLD) | 173 | (10, 330), 0, fpb.FPB_SINGLE_FOLD) |
174 | 174 | ||
175 | - # Initialize Tracker and PedalConnection objects here so that they are available to several panels. | 175 | + # Initialize Navigation, Tracker and PedalConnection objects here so that they are available to several panels. |
176 | # | 176 | # |
177 | tracker = Tracker() | 177 | tracker = Tracker() |
178 | pedal_connection = PedalConnection() if HAS_PEDAL_CONNECTION else None | 178 | pedal_connection = PedalConnection() if HAS_PEDAL_CONNECTION else None |
179 | 179 | ||
180 | neuronavigation_api = NeuronavigationApi() | 180 | neuronavigation_api = NeuronavigationApi() |
181 | - | 181 | + navigation = Navigation( |
182 | + pedal_connection=pedal_connection, | ||
183 | + neuronavigation_api=neuronavigation_api, | ||
184 | + ) | ||
182 | # Fold panel style | 185 | # Fold panel style |
183 | style = fpb.CaptionBarStyle() | 186 | style = fpb.CaptionBarStyle() |
184 | style.SetCaptionStyle(fpb.CAPTIONBAR_GRADIENT_V) | 187 | style.SetCaptionStyle(fpb.CAPTIONBAR_GRADIENT_V) |
@@ -189,6 +192,7 @@ class InnerFoldPanel(wx.Panel): | @@ -189,6 +192,7 @@ class InnerFoldPanel(wx.Panel): | ||
189 | item = fold_panel.AddFoldPanel(_("Neuronavigation"), collapsed=True) | 192 | item = fold_panel.AddFoldPanel(_("Neuronavigation"), collapsed=True) |
190 | ntw = NeuronavigationPanel( | 193 | ntw = NeuronavigationPanel( |
191 | parent=item, | 194 | parent=item, |
195 | + navigation=navigation, | ||
192 | tracker=tracker, | 196 | tracker=tracker, |
193 | pedal_connection=pedal_connection, | 197 | pedal_connection=pedal_connection, |
194 | neuronavigation_api=neuronavigation_api, | 198 | neuronavigation_api=neuronavigation_api, |
@@ -209,7 +213,7 @@ class InnerFoldPanel(wx.Panel): | @@ -209,7 +213,7 @@ class InnerFoldPanel(wx.Panel): | ||
209 | 213 | ||
210 | # Fold 3 - Markers panel | 214 | # Fold 3 - Markers panel |
211 | item = fold_panel.AddFoldPanel(_("Markers"), collapsed=True) | 215 | item = fold_panel.AddFoldPanel(_("Markers"), collapsed=True) |
212 | - mtw = MarkersPanel(item, tracker) | 216 | + mtw = MarkersPanel(item, navigation, tracker) |
213 | 217 | ||
214 | fold_panel.ApplyCaptionStyle(item, style) | 218 | fold_panel.ApplyCaptionStyle(item, style) |
215 | fold_panel.AddFoldPanelWindow(item, mtw, spacing= 0, | 219 | fold_panel.AddFoldPanelWindow(item, mtw, spacing= 0, |
@@ -348,7 +352,7 @@ class InnerFoldPanel(wx.Panel): | @@ -348,7 +352,7 @@ class InnerFoldPanel(wx.Panel): | ||
348 | 352 | ||
349 | 353 | ||
350 | class NeuronavigationPanel(wx.Panel): | 354 | class NeuronavigationPanel(wx.Panel): |
351 | - def __init__(self, parent, tracker, pedal_connection, neuronavigation_api): | 355 | + def __init__(self, parent, navigation, tracker, pedal_connection, neuronavigation_api): |
352 | wx.Panel.__init__(self, parent) | 356 | wx.Panel.__init__(self, parent) |
353 | try: | 357 | try: |
354 | default_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR) | 358 | default_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR) |
@@ -364,10 +368,7 @@ class NeuronavigationPanel(wx.Panel): | @@ -364,10 +368,7 @@ class NeuronavigationPanel(wx.Panel): | ||
364 | self.pedal_connection = pedal_connection | 368 | self.pedal_connection = pedal_connection |
365 | self.neuronavigation_api = neuronavigation_api | 369 | self.neuronavigation_api = neuronavigation_api |
366 | 370 | ||
367 | - self.navigation = Navigation( | ||
368 | - pedal_connection=pedal_connection, | ||
369 | - neuronavigation_api=neuronavigation_api, | ||
370 | - ) | 371 | + self.navigation = navigation |
371 | self.icp = ICP() | 372 | self.icp = ICP() |
372 | self.tracker = tracker | 373 | self.tracker = tracker |
373 | self.robot = Robot(tracker) | 374 | self.robot = Robot(tracker) |
@@ -1260,7 +1261,7 @@ class MarkersPanel(wx.Panel): | @@ -1260,7 +1261,7 @@ class MarkersPanel(wx.Panel): | ||
1260 | def robot_target_matrix(self, new_m_robot_target): | 1261 | def robot_target_matrix(self, new_m_robot_target): |
1261 | self.m_robot_target = new_m_robot_target | 1262 | self.m_robot_target = new_m_robot_target |
1262 | 1263 | ||
1263 | - def __init__(self, parent, tracker): | 1264 | + def __init__(self, parent, navigation, tracker): |
1264 | wx.Panel.__init__(self, parent) | 1265 | wx.Panel.__init__(self, parent) |
1265 | try: | 1266 | try: |
1266 | default_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR) | 1267 | default_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR) |
@@ -1270,6 +1271,7 @@ class MarkersPanel(wx.Panel): | @@ -1270,6 +1271,7 @@ class MarkersPanel(wx.Panel): | ||
1270 | 1271 | ||
1271 | self.SetAutoLayout(1) | 1272 | self.SetAutoLayout(1) |
1272 | 1273 | ||
1274 | + self.navigation = navigation | ||
1273 | self.tracker = tracker | 1275 | self.tracker = tracker |
1274 | 1276 | ||
1275 | self.__bind_events() | 1277 | self.__bind_events() |
@@ -1455,11 +1457,13 @@ class MarkersPanel(wx.Panel): | @@ -1455,11 +1457,13 @@ class MarkersPanel(wx.Panel): | ||
1455 | 1457 | ||
1456 | def UpdateCurrentCoord(self, position): | 1458 | def UpdateCurrentCoord(self, position): |
1457 | self.current_coord = list(position) | 1459 | self.current_coord = list(position) |
1460 | + if not self.navigation.track_obj: | ||
1461 | + self.current_coord[3:] = None, None, None | ||
1458 | 1462 | ||
1459 | def UpdateNavigationStatus(self, nav_status, vis_status): | 1463 | def UpdateNavigationStatus(self, nav_status, vis_status): |
1460 | if not nav_status: | 1464 | if not nav_status: |
1461 | - self.current_coord = [None, None, None] | ||
1462 | self.nav_status = False | 1465 | self.nav_status = False |
1466 | + self.current_coord[3:] = None, None, None | ||
1463 | else: | 1467 | else: |
1464 | self.nav_status = True | 1468 | self.nav_status = True |
1465 | 1469 | ||
@@ -1483,6 +1487,11 @@ class MarkersPanel(wx.Panel): | @@ -1483,6 +1487,11 @@ class MarkersPanel(wx.Panel): | ||
1483 | send_target_to_robot = menu_id.Append(3, _('Send target to robot')) | 1487 | send_target_to_robot = menu_id.Append(3, _('Send target to robot')) |
1484 | menu_id.Bind(wx.EVT_MENU, self.OnMenuSendTargetToRobot, send_target_to_robot) | 1488 | menu_id.Bind(wx.EVT_MENU, self.OnMenuSendTargetToRobot, send_target_to_robot) |
1485 | 1489 | ||
1490 | + if all([elem is not None for elem in self.markers[self.lc.GetFocusedItem()].coord[3:]]): | ||
1491 | + target_menu.Enable(True) | ||
1492 | + else: | ||
1493 | + target_menu.Enable(False) | ||
1494 | + | ||
1486 | # Enable "Send target to robot" button only if tracker is robot, if navigation is on and if target is not none | 1495 | # Enable "Send target to robot" button only if tracker is robot, if navigation is on and if target is not none |
1487 | m_target_robot = np.array([self.robot_markers[self.lc.GetFocusedItem()].robot_target_matrix]) | 1496 | m_target_robot = np.array([self.robot_markers[self.lc.GetFocusedItem()].robot_target_matrix]) |
1488 | if self.tracker.tracker_id == const.ROBOT and self.nav_status and m_target_robot.any(): | 1497 | if self.tracker.tracker_id == const.ROBOT and self.nav_status and m_target_robot.any(): |
@@ -1493,7 +1502,6 @@ class MarkersPanel(wx.Panel): | @@ -1493,7 +1502,6 @@ class MarkersPanel(wx.Panel): | ||
1493 | # target_menu_rem = menu_id.Append(3, _('Remove target')) | 1502 | # target_menu_rem = menu_id.Append(3, _('Remove target')) |
1494 | # menu_id.Bind(wx.EVT_MENU, self.OnMenuRemoveTarget, target_menu_rem) | 1503 | # menu_id.Bind(wx.EVT_MENU, self.OnMenuRemoveTarget, target_menu_rem) |
1495 | 1504 | ||
1496 | - target_menu.Enable(True) | ||
1497 | self.PopupMenu(menu_id) | 1505 | self.PopupMenu(menu_id) |
1498 | menu_id.Destroy() | 1506 | menu_id.Destroy() |
1499 | 1507 | ||
@@ -1703,15 +1711,15 @@ class MarkersPanel(wx.Panel): | @@ -1703,15 +1711,15 @@ class MarkersPanel(wx.Panel): | ||
1703 | 1711 | ||
1704 | # Note that ball_id is zero-based, so we assign it len(self.markers) before the new marker is added | 1712 | # Note that ball_id is zero-based, so we assign it len(self.markers) before the new marker is added |
1705 | if all([elem is not None for elem in new_marker.coord[3:]]): | 1713 | if all([elem is not None for elem in new_marker.coord[3:]]): |
1706 | - Publisher.sendMessage('Add arrow marker', arrow_id=len(self.markers), | ||
1707 | - size=self.arrow_marker_size, | ||
1708 | - color=new_marker.colour, | ||
1709 | - coord=new_marker.coord) | 1714 | + arrow_flag = True |
1710 | else: | 1715 | else: |
1711 | - Publisher.sendMessage('Add marker', ball_id=len(self.markers), | ||
1712 | - size=new_marker.size, | ||
1713 | - colour=new_marker.colour, | ||
1714 | - coord=new_marker.coord[:3]) | 1716 | + arrow_flag = False |
1717 | + | ||
1718 | + Publisher.sendMessage('Add marker', marker_id=len(self.markers), | ||
1719 | + size=new_marker.size, | ||
1720 | + colour=new_marker.colour, | ||
1721 | + coord=new_marker.coord, | ||
1722 | + arrow_flag=arrow_flag) | ||
1715 | 1723 | ||
1716 | 1724 | ||
1717 | self.markers.append(new_marker) | 1725 | self.markers.append(new_marker) |