Commit 9f6c35ce639df1ac057dfb0bb3fd8488a61bdcc4

Authored by tfmoraes
1 parent 939ae52f

ENH: Using vtkCursor3D instead of vtkImageCursor3D to represent Cross reference in slices

Showing 1 changed file with 90 additions and 3 deletions   Show diff stats
invesalius/data/viewer_slice.py
... ... @@ -42,7 +42,7 @@ class Viewer(wx.Panel):
42 42 self.SetBackgroundColour(colour)
43 43  
44 44 # Interactor additional style
45   - self.modes = ['DEFAULT']
  45 + self.modes = [] #['DEFAULT']
46 46 self.mouse_pressed = 0
47 47  
48 48 # All renderers and image actors in this viewer
... ... @@ -181,6 +181,7 @@ class Viewer(wx.Panel):
181 181 self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))
182 182  
183 183 def __set_mode_zoom(self, pubsub_evt):
  184 + print "Zoom"
184 185 self.append_mode('ZOOM')
185 186 self.mouse_pressed = 0
186 187 ICON_IMAGE = wx.Image("../icons/tool_zoom.png",wx.BITMAP_TYPE_PNG)
... ... @@ -496,14 +497,15 @@ class Viewer(wx.Panel):
496 497 evt_msg = 'Add mask pixel'
497 498 elif self._brush_cursor_op == const.BRUSH_THRESH:
498 499 evt_msg = 'Edit mask pixel'
  500 +
  501 + self.__update_cross_position(*coord)
499 502  
500 503 if self.mouse_pressed:
501 504 pixels = itertools.ifilter(self.test_operation_position,
502 505 slice_data.cursor.GetPixels())
503 506 ps.Publisher().sendMessage(evt_msg, pixels)
504 507 ps.Publisher().sendMessage('Update slice viewer')
505   - else:
506   - self.interactor.Render()
  508 + self.interactor.Render()
507 509  
508 510 def OnCrossMove(self, obj, evt_vtk):
509 511 coord = self.get_coordinate()
... ... @@ -738,6 +740,91 @@ class Viewer(wx.Panel):
738 740 # Insert cursor
739 741 self.append_mode('EDITOR')
740 742  
  743 + self.__build_cross_lines()
  744 +
  745 + def __build_cross_lines(self):
  746 + actor = self.slice_data_list[0].actor
  747 + renderer = self.slice_data_list[0].renderer
  748 + xi, xf, yi, yf, zi, zf = actor.GetBounds()
  749 +
  750 + #vline = vtk.vtkLineSource()
  751 + #vline.SetPoint1(xi, yi, zi)
  752 + #vline.SetPoint2(xi, yf, zi)
  753 + #self.vline = vline
  754 +
  755 + #hline = vtk.vtkLineSource()
  756 + #hline.SetPoint1(xi, yi, zi)
  757 + #hline.SetPoint2(xf, yi, zi)
  758 + #self.hline = hline
  759 +
  760 + #cross = vtk.vtkAppendPolyData()
  761 + #cross.AddInput(vline.GetOutput())
  762 + #cross.AddInput(hline.GetOutput())
  763 + cross = vtk.vtkCursor3D()
  764 + cross.AllOff()
  765 + cross.AxesOn()
  766 + #cross.WrapOn()
  767 + #cross.OutlineOff()
  768 + #cross.ZShadowsOff()
  769 + #cross.YShadowsOff()
  770 + #cross.XShadowsOff()
  771 + cross.SetModelBounds(self.imagedata.GetBounds())
  772 + self.cross = cross
  773 +
  774 + cross_mapper = vtk.vtkPolyDataMapper()
  775 + cross_mapper.SetInput(cross.GetOutput())
  776 +
  777 + property = vtk.vtkProperty()
  778 + property.SetColor(1, 0, 0)
  779 +
  780 + cross_actor = vtk.vtkActor()
  781 + cross_actor.SetMapper(cross_mapper)
  782 + cross_actor.SetProperty(property)
  783 + # Only the slices are pickable
  784 + cross_actor.PickableOff()
  785 +
  786 + renderer.AddActor(cross_actor)
  787 +
  788 + def __update_cross_position(self, x, y, z):
  789 + #xi, yi, zi = self.vline.GetPoint1()
  790 + #xf, yf, zf = self.vline.GetPoint2()
  791 + #self.vline.SetPoint1(x, yi, z)
  792 + #self.vline.SetPoint2(x, yf, z)
  793 + #self.vline.Update()
  794 +
  795 + #xi, yi, zi = self.hline.GetPoint1()
  796 + #xf, yf, zf = self.hline.GetPoint2()
  797 + #self.hline.SetPoint1(xi, y, z)
  798 + #self.hline.SetPoint2(xf, y, z)
  799 + #self.hline.Update()
  800 + slice_data = self.slice_data_list[0]
  801 + slice_number = slice_data.number
  802 + actor_bound = slice_data.actor.GetBounds()
  803 +
  804 + yz = [actor_bound[1] + 1 + slice_number, y, z]
  805 + xz = [x, actor_bound[3] - 1 - slice_number, z]
  806 + xy = [x, y, actor_bound[5] + 1 + slice_number]
  807 +
  808 + proj = project.Project()
  809 + orig_orien = proj.original_orientation
  810 +
  811 + if (orig_orien == const.SAGITAL):
  812 + coordinates = {"SAGITAL": xy, "CORONAL": yz, "AXIAL": xz}
  813 + elif(orig_orien == const.CORONAL):
  814 + coordinates = {"SAGITAL": yz, "CORONAL": xy, "AXIAL": xz}
  815 + else:
  816 + coordinates = {"SAGITAL": yz, "CORONAL": xz, "AXIAL": xy}
  817 +
  818 + self.cross.SetFocalPoint(coordinates[self.orientation])
  819 +
  820 + #print
  821 + #print slice_number
  822 + #print x, y, z
  823 + #print "Focal", self.cross.GetFocalPoint()
  824 + #print "bounds", self.cross.GetModelBounds()
  825 + #print "actor bounds", slice_data.actor.GetBounds()
  826 + #print
  827 +
741 828 def __update_cursor_position(self, slice_data, position):
742 829 x, y, z = position
743 830 if (slice_data.cursor):
... ...