Skip to content

Commit

Permalink
Update GUI defaults in navigation and improved functionalities (#196)
Browse files Browse the repository at this point in the history
* ENH:Update GUI navigation defaults for better workflow

* ENH: Improved visualization in navigation
- Larger distance text in target interface
- Better colors for coil objects and aim
- Update defaults in navigation tab

* ENH: Save last used NDI markers filenames to config.json
  • Loading branch information
vhosouza authored and tfmoraes committed Jun 10, 2019
1 parent a76ce75 commit bfb7466
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 50 deletions.
1 change: 1 addition & 0 deletions invesalius/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
TEXT_SIZE = 12
TEXT_SIZE_LARGE = 16
TEXT_SIZE_EXTRA_LARGE = 20
TEXT_SIZE_DIST_NAV = 32
TEXT_COLOUR = (1,1,1)

(X,Y) = (0.03, 0.97)
Expand Down
62 changes: 47 additions & 15 deletions invesalius/data/viewer_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def __init__(self, parent):
self.obj_state = None
self.obj_actor_list = None
self.arrow_actor_list = None
#self.pTarget = [0., 0., 0.]

# self.obj_axes = None

Expand Down Expand Up @@ -623,6 +624,7 @@ def OnUpdateDistThreshold(self, dist_threshold):
self.distthreshold = dist_threshold

def ActivateTargetMode(self, evt=None, target_mode=None):
vtk_colors = vtk.vtkNamedColors()
self.target_mode = target_mode
if self.target_coord and self.target_mode:
self.CreateTargetAim()
Expand All @@ -646,21 +648,33 @@ def ActivateTargetMode(self, evt=None, target_mode=None):
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(normals.GetOutput())
mapper.ScalarVisibilityOff()
mapper.ImmediateModeRenderingOn() # improve performance
#mapper.ImmediateModeRenderingOn() # improve performance

obj_roll = vtk.vtkActor()
obj_roll.SetMapper(mapper)
obj_roll.GetProperty().SetColor(1, 1, 1)
# obj_roll.GetProperty().SetDiffuseColor(vtk_colors.GetColor3d('GhostWhite'))
# obj_roll.GetProperty().SetSpecular(30)
# obj_roll.GetProperty().SetSpecularPower(80)
obj_roll.SetPosition(0, 25, -30)
obj_roll.RotateX(-60)
obj_roll.RotateZ(180)

obj_yaw = vtk.vtkActor()
obj_yaw.SetMapper(mapper)
obj_yaw.GetProperty().SetColor(1, 1, 1)
# obj_yaw.GetProperty().SetDiffuseColor(vtk_colors.GetColor3d('GhostWhite'))
# obj_yaw.GetProperty().SetSpecular(30)
# obj_yaw.GetProperty().SetSpecularPower(80)
obj_yaw.SetPosition(0, -115, 5)
obj_yaw.RotateZ(180)

obj_pitch = vtk.vtkActor()
obj_pitch.SetMapper(mapper)
obj_pitch.GetProperty().SetColor(1, 1, 1)
# obj_pitch.GetProperty().SetDiffuseColor(vtk_colors.GetColor3d('GhostWhite'))
# obj_pitch.GetProperty().SetSpecular(30)
# obj_pitch.GetProperty().SetSpecularPower(80)
obj_pitch.SetPosition(5, -265, 5)
obj_pitch.RotateY(90)
obj_pitch.RotateZ(180)
Expand Down Expand Up @@ -717,6 +731,9 @@ def ActivateTargetMode(self, evt=None, target_mode=None):
self.DisableCoilTracker()

def OnUpdateObjectTargetGuide(self, m_img, coord):

vtk_colors = vtk.vtkNamedColors()

if self.target_coord and self.target_mode:

target_dist = distance.euclidean(coord[0:3],
Expand All @@ -734,10 +751,10 @@ def OnUpdateObjectTargetGuide(self, m_img, coord):

if target_dist <= self.distthreshold:
thrdist = True
self.aim_actor.GetProperty().SetColor(0, 1, 0)
self.aim_actor.GetProperty().SetDiffuseColor(vtk_colors.GetColor3d('Green'))
else:
thrdist = False
self.aim_actor.GetProperty().SetColor(1, 1, 1)
self.aim_actor.GetProperty().SetDiffuseColor(vtk_colors.GetColor3d('Yellow'))

coordx = self.target_coord[3] - coord[3]
if coordx > const.ARROW_UPPER_LIMIT:
Expand Down Expand Up @@ -765,9 +782,11 @@ def OnUpdateObjectTargetGuide(self, m_img, coord):

if self.anglethreshold * const.ARROW_SCALE > coordx > -self.anglethreshold * const.ARROW_SCALE:
thrcoordx = True
# self.obj_actor_list[0].GetProperty().SetDiffuseColor(vtk_colors.GetColor3d('Green'))
self.obj_actor_list[0].GetProperty().SetColor(0, 1, 0)
else:
thrcoordx = False
# self.obj_actor_list[0].GetProperty().SetDiffuseColor(vtk_colors.GetColor3d('GhostWhite'))
self.obj_actor_list[0].GetProperty().SetColor(1, 1, 1)

offset = 5
Expand All @@ -784,9 +803,11 @@ def OnUpdateObjectTargetGuide(self, m_img, coord):

if self.anglethreshold * const.ARROW_SCALE > coordz > -self.anglethreshold * const.ARROW_SCALE:
thrcoordz = True
# self.obj_actor_list[1].GetProperty().SetDiffuseColor(vtk_colors.GetColor3d('Green'))
self.obj_actor_list[1].GetProperty().SetColor(0, 1, 0)
else:
thrcoordz = False
# self.obj_actor_list[1].GetProperty().SetDiffuseColor(vtk_colors.GetColor3d('GhostWhite'))
self.obj_actor_list[1].GetProperty().SetColor(1, 1, 1)

offset = -35
Expand All @@ -803,9 +824,11 @@ def OnUpdateObjectTargetGuide(self, m_img, coord):

if self.anglethreshold * const.ARROW_SCALE > coordy > -self.anglethreshold * const.ARROW_SCALE:
thrcoordy = True
#self.obj_actor_list[2].GetProperty().SetDiffuseColor(vtk_colors.GetColor3d('Green'))
self.obj_actor_list[2].GetProperty().SetColor(0, 1, 0)
else:
thrcoordy = False
#self.obj_actor_list[2].GetProperty().SetDiffuseColor(vtk_colors.GetColor3d('GhostWhite'))
self.obj_actor_list[2].GetProperty().SetColor(1, 1, 1)

offset = 38
Expand All @@ -823,17 +846,16 @@ def OnUpdateObjectTargetGuide(self, m_img, coord):
arrow_pitch_y2.GetProperty().SetColor(1, 0, 0)

if thrdist and thrcoordx and thrcoordy and thrcoordz:
self.dummy_coil_actor.GetProperty().SetColor(0, 1, 0)
self.dummy_coil_actor.GetProperty().SetDiffuseColor(vtk_colors.GetColor3d('Green'))
else:
self.dummy_coil_actor.GetProperty().SetColor(1, 1, 1)
self.dummy_coil_actor.GetProperty().SetDiffuseColor(vtk_colors.GetColor3d('DarkOrange'))

self.arrow_actor_list = arrow_roll_x1, arrow_roll_x2, arrow_yaw_z1, arrow_yaw_z2, \
arrow_pitch_y1, arrow_pitch_y2

for ind in self.arrow_actor_list:
self.ren2.AddActor(ind)


self.Refresh()

def OnUpdateTargetCoordinates(self, coord):
Expand All @@ -853,6 +875,8 @@ def CreateTargetAim(self):
self.RemoveTargetAim()
self.aim_actor = None

vtk_colors = vtk.vtkNamedColors()

a, b, g = np.radians(self.target_coord[3:])
r_ref = tr.euler_matrix(a, b, g, 'sxyz')
t_ref = tr.translation_matrix(self.target_coord[:3])
Expand Down Expand Up @@ -885,8 +909,10 @@ def CreateTargetAim(self):

aim_actor = vtk.vtkActor()
aim_actor.SetMapper(mapper)
aim_actor.GetProperty().SetColor(1, 1, 1)
aim_actor.GetProperty().SetOpacity(0.6)
aim_actor.GetProperty().SetDiffuseColor(vtk_colors.GetColor3d('Yellow'))
aim_actor.GetProperty().SetSpecular(.2)
aim_actor.GetProperty().SetSpecularPower(100)
aim_actor.GetProperty().SetOpacity(1.)
self.aim_actor = aim_actor
self.ren.AddActor(aim_actor)

Expand All @@ -909,11 +935,14 @@ def CreateTargetAim(self):
obj_mapper = vtk.vtkPolyDataMapper()
obj_mapper.SetInputData(normals.GetOutput())
obj_mapper.ScalarVisibilityOff()
obj_mapper.ImmediateModeRenderingOn() # improve performance
#obj_mapper.ImmediateModeRenderingOn() # improve performance

self.dummy_coil_actor = vtk.vtkActor()
self.dummy_coil_actor.SetMapper(obj_mapper)
self.dummy_coil_actor.GetProperty().SetOpacity(0.15)
self.dummy_coil_actor.GetProperty().SetDiffuseColor(vtk_colors.GetColor3d('DarkOrange'))
self.dummy_coil_actor.GetProperty().SetSpecular(0.5)
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)

Expand All @@ -928,9 +957,9 @@ def RemoveTargetAim(self):

def CreateTextDistance(self):
tdist = vtku.Text()
tdist.SetSize(const.TEXT_SIZE_LARGE)
tdist.SetSize(const.TEXT_SIZE_DIST_NAV)
tdist.SetPosition((const.X, 1.03-const.Y))
tdist.ShadowOff()
#tdist.ShadowOff()
tdist.BoldOn()

self.ren.AddActor(tdist.actor)
Expand Down Expand Up @@ -1162,7 +1191,7 @@ def AddObjectActor(self, obj_name):
"""
Coil for navigation rendered in volume viewer.
"""

vtk_colors = vtk.vtkNamedColors()
obj_polydata = self.CreateObjectPolyData(obj_name)

transform = vtk.vtkTransform()
Expand All @@ -1182,11 +1211,14 @@ def AddObjectActor(self, obj_name):
obj_mapper = vtk.vtkPolyDataMapper()
obj_mapper.SetInputData(normals.GetOutput())
obj_mapper.ScalarVisibilityOff()
obj_mapper.ImmediateModeRenderingOn() # improve performance
#obj_mapper.ImmediateModeRenderingOn() # improve performance

self.obj_actor = vtk.vtkActor()
self.obj_actor.SetMapper(obj_mapper)
self.obj_actor.GetProperty().SetOpacity(0.9)
self.obj_actor.GetProperty().SetAmbientColor(vtk_colors.GetColor3d('GhostWhite'))
self.obj_actor.GetProperty().SetSpecular(30)
self.obj_actor.GetProperty().SetSpecularPower(80)
self.obj_actor.GetProperty().SetOpacity(.4)
self.obj_actor.SetVisibility(0)

self.ren.AddActor(self.obj_actor)
Expand Down
2 changes: 2 additions & 0 deletions invesalius/gui/default_viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,11 @@ def OnButtonTarget(self, evt):
if not self.button_target.IsPressed() and evt is not False:
self.button_target._pressed = True
Publisher.sendMessage('Target navigation mode', target_mode=self.button_target._pressed)
Publisher.sendMessage('Change camera checkbox', status=self.button_target._pressed)
elif self.button_target.IsPressed() or evt is False:
self.button_target._pressed = False
Publisher.sendMessage('Target navigation mode', target_mode=self.button_target._pressed)
Publisher.sendMessage('Change camera checkbox', status=self.button_target._pressed)

def OnSavePreset(self, evt):
d = wx.TextEntryDialog(self, _("Preset name"))
Expand Down
Loading

0 comments on commit bfb7466

Please sign in to comment.