Commit 59bf4f1370686fd8c1fde1adb91e2915f08b69a4

Authored by tfmoraes
1 parent 06a07287

ENH: Showing or hidding the cross when necessary

Showing 1 changed file with 61 additions and 13 deletions   Show diff stats
invesalius/data/viewer_slice.py
... ... @@ -20,6 +20,8 @@
20 20 import itertools
21 21 import os.path
22 22  
  23 +import numpy
  24 +
23 25 import vtk
24 26 from vtk.wx.wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor
25 27  
... ... @@ -190,7 +192,15 @@ class Viewer(wx.Panel):
190 192 self.interactor.Bind(wx.EVT_LEFT_DCLICK, self.OnUnZoom)
191 193 else:
192 194 self.interactor.Bind(wx.EVT_LEFT_DCLICK, None)
193   -
  195 +
  196 + #try:
  197 + # if mode == "CROSS":
  198 + # self.cross_actor.VisibilityOn()
  199 + # else:
  200 + # self.cross_actor.VisibilityOff()
  201 + #except AttributeError:
  202 + # pass
  203 +
194 204 self.style = style
195 205 self.interactor.SetInteractorStyle(style)
196 206  
... ... @@ -237,6 +247,7 @@ class Viewer(wx.Panel):
237 247 def __set_mode_cross(self, pubsub_evt):
238 248 self.append_mode('CROSS')
239 249 self.mouse_pressed = 0
  250 + self.cross_actor.VisibilityOn()
240 251 self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_NONE))
241 252  
242 253 def OnWindowLevelMove(self, evt, obj):
... ... @@ -716,6 +727,9 @@ class Viewer(wx.Panel):
716 727 ps.Publisher().subscribe(self.UpdateWindowLevelValue,\
717 728 'Update window level value')
718 729  
  730 + ps.Publisher().subscribe(self.__set_cross_visibility,\
  731 + 'Set cross visibility')
  732 +
719 733 ###
720 734 ps.Publisher().subscribe(self.__set_layout,
721 735 'Set slice viewer layout')
... ... @@ -871,6 +885,7 @@ class Viewer(wx.Panel):
871 885 cross_actor = vtk.vtkActor()
872 886 cross_actor.SetMapper(cross_mapper)
873 887 cross_actor.SetProperty(property)
  888 + cross_actor.VisibilityOff()
874 889 # Only the slices are pickable
875 890 cross_actor.PickableOff()
876 891 self.cross_actor = cross_actor
... ... @@ -895,25 +910,53 @@ class Viewer(wx.Panel):
895 910 slice_number = slice_data.number
896 911 actor_bound = slice_data.actor.GetBounds()
897 912 extent = slice_data.actor.GetDisplayExtent()
  913 + cam = slice_data.renderer.GetActiveCamera()
898 914  
899 915 print
900 916 print self.orientation
901 917 print x, y, z
902 918 print actor_bound
  919 + #print "ViewUp", cam.GetViewUp()
  920 + #print "Position", cam.GetPosition()
  921 + #print "Orientation", cam.GetOrientation()
  922 + #print "Focal Point", cam.GetFocalPoint()
  923 +
  924 + vCamera = numpy.array(cam.GetPosition()) - numpy.array(cam.GetFocalPoint())
  925 + n_vCamera = vCamera / numpy.linalg.norm(vCamera)
  926 + print "Normalized", n_vCamera
903 927  
904   - yz = [x + abs(x * 0.001), y, z]
905   - xz = [x, y - abs(y * 0.001), z]
906   - xy = [x, y, z + abs(z * 0.001)]
  928 + pos = [j + 0.01 * i for i,j in zip(n_vCamera, (x, y, z))]
  929 + print "posicao", pos
907 930  
908   - proj = project.Project()
909   - orig_orien = proj.original_orientation
  931 + #yz = [x + abs(x * 0.001), y, z]
  932 + #xz = [x, y - abs(y * 0.001), z]
  933 + #xy = [x, y, z + abs(z * 0.001)]
910 934  
911   - if (orig_orien == const.SAGITAL):
912   - coordinates = {"SAGITAL": xy, "CORONAL": yz, "AXIAL": xz}
913   - elif(orig_orien == const.CORONAL):
914   - coordinates = {"SAGITAL": yz, "CORONAL": xy, "AXIAL": xz}
915   - else:
916   - coordinates = {"SAGITAL": yz, "CORONAL": xz, "AXIAL": xy}
  935 + #proj = project.Project()
  936 + #orig_orien = proj.original_orientation
  937 + #pos = [x, y, z]
  938 +
  939 + #if (orig_orien == const.SAGITAL):
  940 + # coordinates = {"SAGITAL": xy, "CORONAL": yz, "AXIAL": xz}
  941 + #elif(orig_orien == const.CORONAL):
  942 + # #coordinates = {"SAGITAL": yz, "CORONAL": xy, "AXIAL": xz}
  943 + # if orientation == "AXIAL":
  944 + # pos[2] += abs(pos[2] * 0.001)
  945 + # elif orientation == "SAGITAL":
  946 + # pos[0] += abs(pos[0] * 0.001)
  947 + # elif orientation == "CORONAL":
  948 + # pos[1] -= abs(pos[1] * 0.001)
  949 + #else:
  950 + # #coordinates = {"SAGITAL": yz, "CORONAL": xz, "AXIAL": xy}
  951 + # print "AXIAL"
  952 + # if orientation == "AXIAL":
  953 + # pos[2] += abs(pos[2] * 0.001)
  954 + # elif orientation == "SAGITAL":
  955 + # pos[0] += abs(pos[0] * 0.001)
  956 + # elif orientation == "CORONAL":
  957 + # pos[1] -= abs(pos[1] * 0.001)
  958 +
  959 + #print ">POS", pos
917 960  
918 961 #pos = [x, y, z]
919 962 #if orientation == "AXIAL":
... ... @@ -924,7 +967,7 @@ class Viewer(wx.Panel):
924 967 # pos[1] -= abs(pos[1] * 0.001)
925 968 #print ">POS", pos
926 969 #print
927   - self.cross.SetFocalPoint(coordinates[orientation])
  970 + self.cross.SetFocalPoint(pos)
928 971  
929 972 #print
930 973 #print slice_number
... ... @@ -934,6 +977,11 @@ class Viewer(wx.Panel):
934 977 #print "actor bounds", slice_data.actor.GetBounds()
935 978 #print
936 979  
  980 + def __set_cross_visibility(self, pubsub_evt):
  981 + visibility = pubsub_evt.data
  982 + self.cross_actor.SetVisibility(visibility)
  983 + self.interactor.Render()
  984 +
937 985 def __update_cursor_position(self, slice_data, position):
938 986 x, y, z = position
939 987 if (slice_data.cursor):
... ...