Commit 900a2fafea57ae0592fb69e6d05923bb5ee4a5f8

Authored by Renan
1 parent f8b595d9
Exists in master

FIX: standardized viewer volume marker id

invesalius/data/viewer_volume.py
... ... @@ -281,7 +281,6 @@ class Viewer(wx.Panel):
281 281  
282 282 # Related to marker creation in navigation tools
283 283 Publisher.subscribe(self.AddMarker, 'Add marker')
284   - Publisher.subscribe(self.AddMarkerwithOrientation, 'Add arrow marker')
285 284 Publisher.subscribe(self.HideAllMarkers, 'Hide all markers')
286 285 Publisher.subscribe(self.ShowAllMarkers, 'Show all markers')
287 286 Publisher.subscribe(self.RemoveAllMarkers, 'Remove all markers')
... ... @@ -616,7 +615,7 @@ class Viewer(wx.Panel):
616 615 target = marker["target"]
617 616  
618 617 self.AddMarker(
619   - ball_id=ball_id,
  618 + marker_id=ball_id,
620 619 size=size,
621 620 colour=colour,
622 621 coord=position,
... ... @@ -631,49 +630,28 @@ class Viewer(wx.Panel):
631 630  
632 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 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 638 coord_flip = list(coord)
655 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 655 self.Refresh()
678 656  
679 657 def add_marker(self, coord, color):
... ... @@ -726,7 +704,7 @@ class Viewer(wx.Panel):
726 704 for i in reversed(index):
727 705 self.ren.RemoveActor(self.static_markers[i])
728 706 del self.static_markers[i]
729   - self.ball_id = self.ball_id - 1
  707 + self.marker_id = self.marker_id - 1
730 708 self.UpdateRender()
731 709  
732 710 def BlinkMarker(self, index):
... ... @@ -1383,8 +1361,8 @@ class Viewer(wx.Panel):
1383 1361 self.y_actor = self.add_line([0., 0., 0.], [0., 1., 0.], color=[.0, 1.0, .0])
1384 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 1366 self.object_orientation_torus_actor = self.Add_Torus([0., 0., 0.], [0., 0., 0.],
1389 1367 vtk_colors.GetColor3d('Red'))
1390 1368  
... ... @@ -1449,9 +1427,24 @@ class Viewer(wx.Panel):
1449 1427  
1450 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 1448 arrow = vtk.vtkArrowSource()
1456 1449 arrow.SetTipResolution(40)
1457 1450 arrow.SetShaftResolution(40)
... ... @@ -1464,7 +1457,7 @@ class Viewer(wx.Panel):
1464 1457  
1465 1458 actor = vtk.vtkActor()
1466 1459 actor.SetMapper(mapper)
1467   - actor.GetProperty().SetColor(color)
  1460 + actor.GetProperty().SetColor(colour)
1468 1461 actor.GetProperty().SetLineWidth(5)
1469 1462 actor.AddPosition(0, 0, 0)
1470 1463 actor.SetScale(size)
... ...
invesalius/gui/task_navigator.py
... ... @@ -172,13 +172,16 @@ class InnerFoldPanel(wx.Panel):
172 172 fold_panel = fpb.FoldPanelBar(self, -1, wx.DefaultPosition,
173 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 177 tracker = Tracker()
178 178 pedal_connection = PedalConnection() if HAS_PEDAL_CONNECTION else None
179 179  
180 180 neuronavigation_api = NeuronavigationApi()
181   -
  181 + navigation = Navigation(
  182 + pedal_connection=pedal_connection,
  183 + neuronavigation_api=neuronavigation_api,
  184 + )
182 185 # Fold panel style
183 186 style = fpb.CaptionBarStyle()
184 187 style.SetCaptionStyle(fpb.CAPTIONBAR_GRADIENT_V)
... ... @@ -189,6 +192,7 @@ class InnerFoldPanel(wx.Panel):
189 192 item = fold_panel.AddFoldPanel(_("Neuronavigation"), collapsed=True)
190 193 ntw = NeuronavigationPanel(
191 194 parent=item,
  195 + navigation=navigation,
192 196 tracker=tracker,
193 197 pedal_connection=pedal_connection,
194 198 neuronavigation_api=neuronavigation_api,
... ... @@ -209,7 +213,7 @@ class InnerFoldPanel(wx.Panel):
209 213  
210 214 # Fold 3 - Markers panel
211 215 item = fold_panel.AddFoldPanel(_("Markers"), collapsed=True)
212   - mtw = MarkersPanel(item, tracker)
  216 + mtw = MarkersPanel(item, navigation, tracker)
213 217  
214 218 fold_panel.ApplyCaptionStyle(item, style)
215 219 fold_panel.AddFoldPanelWindow(item, mtw, spacing= 0,
... ... @@ -348,7 +352,7 @@ class InnerFoldPanel(wx.Panel):
348 352  
349 353  
350 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 356 wx.Panel.__init__(self, parent)
353 357 try:
354 358 default_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR)
... ... @@ -364,10 +368,7 @@ class NeuronavigationPanel(wx.Panel):
364 368 self.pedal_connection = pedal_connection
365 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 372 self.icp = ICP()
372 373 self.tracker = tracker
373 374 self.robot = Robot(tracker)
... ... @@ -1260,7 +1261,7 @@ class MarkersPanel(wx.Panel):
1260 1261 def robot_target_matrix(self, new_m_robot_target):
1261 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 1265 wx.Panel.__init__(self, parent)
1265 1266 try:
1266 1267 default_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR)
... ... @@ -1270,6 +1271,7 @@ class MarkersPanel(wx.Panel):
1270 1271  
1271 1272 self.SetAutoLayout(1)
1272 1273  
  1274 + self.navigation = navigation
1273 1275 self.tracker = tracker
1274 1276  
1275 1277 self.__bind_events()
... ... @@ -1455,11 +1457,13 @@ class MarkersPanel(wx.Panel):
1455 1457  
1456 1458 def UpdateCurrentCoord(self, position):
1457 1459 self.current_coord = list(position)
  1460 + if not self.navigation.track_obj:
  1461 + self.current_coord[3:] = None, None, None
1458 1462  
1459 1463 def UpdateNavigationStatus(self, nav_status, vis_status):
1460 1464 if not nav_status:
1461   - self.current_coord = [None, None, None]
1462 1465 self.nav_status = False
  1466 + self.current_coord[3:] = None, None, None
1463 1467 else:
1464 1468 self.nav_status = True
1465 1469  
... ... @@ -1703,15 +1707,15 @@ class MarkersPanel(wx.Panel):
1703 1707  
1704 1708 # Note that ball_id is zero-based, so we assign it len(self.markers) before the new marker is added
1705 1709 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)
  1710 + arrow_flag = True
1710 1711 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])
  1712 + arrow_flag = False
  1713 +
  1714 + Publisher.sendMessage('Add marker', marker_id=len(self.markers),
  1715 + size=new_marker.size,
  1716 + colour=new_marker.colour,
  1717 + coord=new_marker.coord,
  1718 + arrow_flag=arrow_flag)
1715 1719  
1716 1720  
1717 1721 self.markers.append(new_marker)
... ...