From 6e312c12c93510adda1d5e21e0e4a694ab578ec9 Mon Sep 17 00:00:00 2001 From: Renan Date: Mon, 29 Nov 2021 11:51:03 +0200 Subject: [PATCH] FIX: create and apply vtk matrix to positioning arrow --- invesalius/data/viewer_volume.py | 41 ++++++++++++++++++++++------------------- invesalius/gui/task_navigator.py | 9 +-------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/invesalius/data/viewer_volume.py b/invesalius/data/viewer_volume.py index 10415c6..0e97b4a 100644 --- a/invesalius/data/viewer_volume.py +++ b/invesalius/data/viewer_volume.py @@ -71,7 +71,7 @@ class Viewer(wx.Panel): self.initial_focus = None self.static_markers = [] - self.static_arrows =[] + self.static_arrows = [] self.style = None interactor = wxVTKRenderWindowInteractor(self, -1, size = self.GetSize()) @@ -607,11 +607,11 @@ class Viewer(wx.Panel): self.RemoveTarget() self.UpdateRender() + def AddMarkerwithOrientation(self, arrow_id, size, color, coord): """ Markers arrow with orientation created by navigation tools and rendered in volume viewer. """ - self.arrow_marker_id = arrow_id coord_flip = list(coord) coord_flip[1] = -coord_flip[1] @@ -619,10 +619,9 @@ class Viewer(wx.Panel): arrow_actor = self.Add_ObjectArrow(coord_flip[:3], coord_flip[3:6], color, size) self.static_markers.append(arrow_actor) self.ren.AddActor(self.static_markers[self.arrow_marker_id]) - self.arrow_marker_id +=1 - #self.UpdateRender() - self.Refresh() + self.arrow_marker_id += 1 + self.Refresh() def AddMarker(self, ball_id, size, colour, coord): """ @@ -1009,16 +1008,10 @@ class Viewer(wx.Panel): self.RemoveTarget() self.DisableCoilTracker() - def CreateTargetAim(self): - if self.aim_actor: - self.RemoveTargetAim() - self.aim_actor = None - - vtk_colors = vtk.vtkNamedColors() - + def CreateVTKObjectMatrix(self, direction, orientation): m_img = dco.coordinates_to_transformation_matrix( - position=self.target_coord[:3], - orientation=self.target_coord[3:], + position=direction, + orientation=orientation, axes='sxyz', ) m_img = np.asmatrix(m_img) @@ -1029,7 +1022,16 @@ class Viewer(wx.Panel): for col in range(0, 4): m_img_vtk.SetElement(row, col, m_img[row, col]) - self.m_img_vtk = m_img_vtk + return m_img_vtk + + def CreateTargetAim(self): + if self.aim_actor: + self.RemoveTargetAim() + self.aim_actor = None + + vtk_colors = vtk.vtkNamedColors() + + self.m_img_vtk = self.CreateVTKObjectMatrix(self.target_coord[:3], self.target_coord[3:]) filename = os.path.join(inv_paths.OBJ_DIR, "aim.stl") @@ -1040,7 +1042,7 @@ class Viewer(wx.Panel): # Transform the polydata transform = vtk.vtkTransform() - transform.SetMatrix(m_img_vtk) + transform.SetMatrix(self.m_img_vtk) transformPD = vtk.vtkTransformPolyDataFilter() transformPD.SetTransform(transform) transformPD.SetInputConnection(reader.GetOutputPort()) @@ -1088,7 +1090,7 @@ class Viewer(wx.Panel): self.dummy_coil_actor.GetProperty().SetSpecularPower(10) self.dummy_coil_actor.GetProperty().SetOpacity(.3) self.dummy_coil_actor.SetVisibility(1) - self.dummy_coil_actor.SetUserMatrix(m_img_vtk) + self.dummy_coil_actor.SetUserMatrix(self.m_img_vtk) self.ren.AddActor(self.dummy_coil_actor) @@ -1441,8 +1443,9 @@ class Viewer(wx.Panel): actor.GetProperty().SetLineWidth(5) actor.AddPosition(0, 0, 0) actor.SetScale(size) - actor.SetPosition(direction) - actor.SetOrientation(orientation) + + m_img_vtk = self.CreateVTKObjectMatrix(direction, orientation) + actor.SetUserMatrix(m_img_vtk) return actor diff --git a/invesalius/gui/task_navigator.py b/invesalius/gui/task_navigator.py index c3b8bb5..e063292 100644 --- a/invesalius/gui/task_navigator.py +++ b/invesalius/gui/task_navigator.py @@ -1623,7 +1623,6 @@ class MarkersPanel(wx.Panel): self.__set_marker_as_target(len(self.markers) - 1) except Exception as e: - wx.MessageBox(_("Invalid markers file."), _("InVesalius 3")) def OnMarkersVisibility(self, evt, ctrl): @@ -1689,13 +1688,7 @@ class MarkersPanel(wx.Panel): new_robot_marker.robot_target_matrix = self.current_robot_target_matrix # Note that ball_id is zero-based, so we assign it len(self.markers) before the new marker is added - if label in self.__list_fiducial_labels(): - Publisher.sendMessage('Add marker', ball_id=len(self.markers), - size=new_marker.size, - colour=new_marker.colour, - coord=new_marker.coord[:3]) - - elif all([elem is not None for elem in new_marker.coord[3:]]): + if all([elem is not None for elem in new_marker.coord[3:]]): Publisher.sendMessage('Add arrow marker', arrow_id=len(self.markers), size=self.arrow_marker_size, color=new_marker.colour, -- libgit2 0.21.2