Commit 6e312c12c93510adda1d5e21e0e4a694ab578ec9

Authored by Renan
1 parent 486d4343
Exists in master

FIX: create and apply vtk matrix to positioning arrow

invesalius/data/viewer_volume.py
... ... @@ -71,7 +71,7 @@ class Viewer(wx.Panel):
71 71 self.initial_focus = None
72 72  
73 73 self.static_markers = []
74   - self.static_arrows =[]
  74 + self.static_arrows = []
75 75 self.style = None
76 76  
77 77 interactor = wxVTKRenderWindowInteractor(self, -1, size = self.GetSize())
... ... @@ -607,11 +607,11 @@ class Viewer(wx.Panel):
607 607 self.RemoveTarget()
608 608  
609 609 self.UpdateRender()
  610 +
610 611 def AddMarkerwithOrientation(self, arrow_id, size, color, coord):
611 612 """
612 613 Markers arrow with orientation created by navigation tools and rendered in volume viewer.
613 614 """
614   -
615 615 self.arrow_marker_id = arrow_id
616 616 coord_flip = list(coord)
617 617 coord_flip[1] = -coord_flip[1]
... ... @@ -619,10 +619,9 @@ class Viewer(wx.Panel):
619 619 arrow_actor = self.Add_ObjectArrow(coord_flip[:3], coord_flip[3:6], color, size)
620 620 self.static_markers.append(arrow_actor)
621 621 self.ren.AddActor(self.static_markers[self.arrow_marker_id])
622   - self.arrow_marker_id +=1
623   - #self.UpdateRender()
624   - self.Refresh()
  622 + self.arrow_marker_id += 1
625 623  
  624 + self.Refresh()
626 625  
627 626 def AddMarker(self, ball_id, size, colour, coord):
628 627 """
... ... @@ -1009,16 +1008,10 @@ class Viewer(wx.Panel):
1009 1008 self.RemoveTarget()
1010 1009 self.DisableCoilTracker()
1011 1010  
1012   - def CreateTargetAim(self):
1013   - if self.aim_actor:
1014   - self.RemoveTargetAim()
1015   - self.aim_actor = None
1016   -
1017   - vtk_colors = vtk.vtkNamedColors()
1018   -
  1011 + def CreateVTKObjectMatrix(self, direction, orientation):
1019 1012 m_img = dco.coordinates_to_transformation_matrix(
1020   - position=self.target_coord[:3],
1021   - orientation=self.target_coord[3:],
  1013 + position=direction,
  1014 + orientation=orientation,
1022 1015 axes='sxyz',
1023 1016 )
1024 1017 m_img = np.asmatrix(m_img)
... ... @@ -1029,7 +1022,16 @@ class Viewer(wx.Panel):
1029 1022 for col in range(0, 4):
1030 1023 m_img_vtk.SetElement(row, col, m_img[row, col])
1031 1024  
1032   - self.m_img_vtk = m_img_vtk
  1025 + return m_img_vtk
  1026 +
  1027 + def CreateTargetAim(self):
  1028 + if self.aim_actor:
  1029 + self.RemoveTargetAim()
  1030 + self.aim_actor = None
  1031 +
  1032 + vtk_colors = vtk.vtkNamedColors()
  1033 +
  1034 + self.m_img_vtk = self.CreateVTKObjectMatrix(self.target_coord[:3], self.target_coord[3:])
1033 1035  
1034 1036 filename = os.path.join(inv_paths.OBJ_DIR, "aim.stl")
1035 1037  
... ... @@ -1040,7 +1042,7 @@ class Viewer(wx.Panel):
1040 1042  
1041 1043 # Transform the polydata
1042 1044 transform = vtk.vtkTransform()
1043   - transform.SetMatrix(m_img_vtk)
  1045 + transform.SetMatrix(self.m_img_vtk)
1044 1046 transformPD = vtk.vtkTransformPolyDataFilter()
1045 1047 transformPD.SetTransform(transform)
1046 1048 transformPD.SetInputConnection(reader.GetOutputPort())
... ... @@ -1088,7 +1090,7 @@ class Viewer(wx.Panel):
1088 1090 self.dummy_coil_actor.GetProperty().SetSpecularPower(10)
1089 1091 self.dummy_coil_actor.GetProperty().SetOpacity(.3)
1090 1092 self.dummy_coil_actor.SetVisibility(1)
1091   - self.dummy_coil_actor.SetUserMatrix(m_img_vtk)
  1093 + self.dummy_coil_actor.SetUserMatrix(self.m_img_vtk)
1092 1094  
1093 1095 self.ren.AddActor(self.dummy_coil_actor)
1094 1096  
... ... @@ -1441,8 +1443,9 @@ class Viewer(wx.Panel):
1441 1443 actor.GetProperty().SetLineWidth(5)
1442 1444 actor.AddPosition(0, 0, 0)
1443 1445 actor.SetScale(size)
1444   - actor.SetPosition(direction)
1445   - actor.SetOrientation(orientation)
  1446 +
  1447 + m_img_vtk = self.CreateVTKObjectMatrix(direction, orientation)
  1448 + actor.SetUserMatrix(m_img_vtk)
1446 1449  
1447 1450 return actor
1448 1451  
... ...
invesalius/gui/task_navigator.py
... ... @@ -1623,7 +1623,6 @@ class MarkersPanel(wx.Panel):
1623 1623 self.__set_marker_as_target(len(self.markers) - 1)
1624 1624  
1625 1625 except Exception as e:
1626   -
1627 1626 wx.MessageBox(_("Invalid markers file."), _("InVesalius 3"))
1628 1627  
1629 1628 def OnMarkersVisibility(self, evt, ctrl):
... ... @@ -1689,13 +1688,7 @@ class MarkersPanel(wx.Panel):
1689 1688 new_robot_marker.robot_target_matrix = self.current_robot_target_matrix
1690 1689  
1691 1690 # Note that ball_id is zero-based, so we assign it len(self.markers) before the new marker is added
1692   - if label in self.__list_fiducial_labels():
1693   - Publisher.sendMessage('Add marker', ball_id=len(self.markers),
1694   - size=new_marker.size,
1695   - colour=new_marker.colour,
1696   - coord=new_marker.coord[:3])
1697   -
1698   - elif all([elem is not None for elem in new_marker.coord[3:]]):
  1691 + if all([elem is not None for elem in new_marker.coord[3:]]):
1699 1692 Publisher.sendMessage('Add arrow marker', arrow_id=len(self.markers),
1700 1693 size=self.arrow_marker_size,
1701 1694 color=new_marker.colour,
... ...