Commit 8e640588bfb11491c75ddf4b868f5b5f3d71aa4b

Authored by Paulo Henrique Junqueira Amorim
1 parent dab3ed36

FIX: Close project and open other project the raycast cut plane not removed #126

invesalius/data/viewer_volume.py
@@ -127,8 +127,11 @@ class Viewer(wx.Panel): @@ -127,8 +127,11 @@ class Viewer(wx.Panel):
127 ps.Publisher().subscribe(self.OnShowText, 127 ps.Publisher().subscribe(self.OnShowText,
128 'Show text actors on viewers') 128 'Show text actors on viewers')
129 ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') 129 ps.Publisher().subscribe(self.OnCloseProject, 'Close project data')
130 - ps.Publisher().subscribe(self.OnExportPicture,'Export picture to file') 130 +
  131 + ps.Publisher().subscribe(self.RemoveAllActor, 'Remove all volume actors')
131 132
  133 + ps.Publisher().subscribe(self.OnExportPicture,'Export picture to file')
  134 +
132 135
133 136
134 def OnExportPicture(self, pubsub_evt): 137 def OnExportPicture(self, pubsub_evt):
@@ -420,12 +423,16 @@ class Viewer(wx.Panel): @@ -420,12 +423,16 @@ class Viewer(wx.Panel):
420 def RemoveActor(self, pubsub_evt): 423 def RemoveActor(self, pubsub_evt):
421 print "RemoveActor" 424 print "RemoveActor"
422 actor = pubsub_evt.data 425 actor = pubsub_evt.data
423 -  
424 ren = self.ren 426 ren = self.ren
425 ren.RemoveActor(actor) 427 ren.RemoveActor(actor)
426 -  
427 self.interactor.Render() 428 self.interactor.Render()
  429 +
  430 + def RemoveAllActor(self, pubsub_evt):
  431 + print "RemoveAllActor"
  432 + self.ren.RemoveAllProps()
  433 + ps.Publisher().sendMessage('Render volume viewer')
428 434
  435 +
429 def LoadSlicePlane(self, pubsub_evt): 436 def LoadSlicePlane(self, pubsub_evt):
430 self.slice_plane = SlicePlane() 437 self.slice_plane = SlicePlane()
431 438
invesalius/data/volume.py
@@ -107,12 +107,23 @@ class Volume(): @@ -107,12 +107,23 @@ class Volume():
107 self.CloseProject() 107 self.CloseProject()
108 108
109 def CloseProject(self): 109 def CloseProject(self):
  110 + #if self.plane:
  111 + # self.plane = None
  112 + # ps.Publisher().sendMessage('Remove surface actor from viewer', self.plane_actor)
110 if self.plane: 113 if self.plane:
111 - self.plane = None  
112 - ps.Publisher().sendMessage('Remove surface actor from viewer', self.plane_actor) 114 + print "======================================================================================================"
  115 + #ps.Publisher().sendMessage('Remove surface actor from viewer', self.plane.plane_actor)
  116 + #self.plane.Disable()
  117 + self.plane.DestroyObjs()
  118 + del self.plane
  119 + #del self.final_imagedata
  120 + self.plane = 0
  121 +
  122 +
113 if self.exist: 123 if self.exist:
114 self.exist = None 124 self.exist = None
115 ps.Publisher().sendMessage('Remove surface actor from viewer', self.volume) 125 ps.Publisher().sendMessage('Remove surface actor from viewer', self.volume)
  126 + ps.Publisher().sendMessage('Disable volume cut menu')
116 127
117 def OnLoadVolume(self, pubsub_evt): 128 def OnLoadVolume(self, pubsub_evt):
118 label = pubsub_evt.data 129 label = pubsub_evt.data
@@ -559,6 +570,7 @@ class Volume(): @@ -559,6 +570,7 @@ class Volume():
559 self.plane.Disable() 570 self.plane.Disable()
560 else: 571 else:
561 print "Enable" 572 print "Enable"
  573 + self.final_imagedata.Update()
562 self.plane_on = True 574 self.plane_on = True
563 self.plane = CutPlane(self.final_imagedata, 575 self.plane = CutPlane(self.final_imagedata,
564 self.volume_mapper) 576 self.volume_mapper)
@@ -618,7 +630,7 @@ class CutPlane: @@ -618,7 +630,7 @@ class CutPlane:
618 plane_source.SetPoint1(plane_widget.GetPoint1()) 630 plane_source.SetPoint1(plane_widget.GetPoint1())
619 plane_source.SetPoint2(plane_widget.GetPoint2()) 631 plane_source.SetPoint2(plane_widget.GetPoint2())
620 plane_source.SetNormal(plane_widget.GetNormal()) 632 plane_source.SetNormal(plane_widget.GetNormal())
621 - plane_mapper = vtk.vtkPolyDataMapper() 633 + plane_mapper = self.plane_mapper = vtk.vtkPolyDataMapper()
622 plane_mapper.SetInput(plane_source.GetOutput()) 634 plane_mapper.SetInput(plane_source.GetOutput())
623 self.plane_actor = plane_actor = vtk.vtkActor() 635 self.plane_actor = plane_actor = vtk.vtkActor()
624 plane_actor.SetMapper(plane_mapper) 636 plane_actor.SetMapper(plane_mapper)
@@ -673,5 +685,15 @@ class CutPlane: @@ -673,5 +685,15 @@ class CutPlane:
673 self.plane_actor.VisibilityOn() 685 self.plane_actor.VisibilityOn()
674 self.plane.SetNormal(self.normal) 686 self.plane.SetNormal(self.normal)
675 self.plane.SetOrigin(self.origin) 687 self.plane.SetOrigin(self.origin)
676 - ps.Publisher().sendMessage('Render volume viewer', None)  
677 - 688 + ps.Publisher().sendMessage('Render volume viewer', None)
  689 +
  690 + def DestroyObjs(self):
  691 + ps.Publisher().sendMessage('Remove surface actor from viewer', self.plane_actor)
  692 +
  693 + del self.plane_widget
  694 + del self.plane_source
  695 + del self.plane_actor
  696 + del self.normal
  697 + del self.plane
  698 + ps.Publisher().sendMessage('Remove all volume actors')
  699 +
678 \ No newline at end of file 700 \ No newline at end of file
invesalius/gui/default_viewers.py
@@ -392,6 +392,7 @@ class VolumeToolPanel(wx.Panel): @@ -392,6 +392,7 @@ class VolumeToolPanel(wx.Panel):
392 'Change volume viewer gui colour') 392 'Change volume viewer gui colour')
393 ps.Publisher().subscribe(self.DisablePreset, 'Close project data') 393 ps.Publisher().subscribe(self.DisablePreset, 'Close project data')
394 ps.Publisher().subscribe(self.Uncheck, 'Uncheck image plane menu') 394 ps.Publisher().subscribe(self.Uncheck, 'Uncheck image plane menu')
  395 + ps.Publisher().subscribe(self.DisableVolumeCutMenu, 'Disable volume cut menu')
395 396
396 def DisablePreset(self, pubsub_evt): 397 def DisablePreset(self, pubsub_evt):
397 self.off_item.Check(1) 398 self.off_item.Check(1)
@@ -422,7 +423,7 @@ class VolumeToolPanel(wx.Panel): @@ -422,7 +423,7 @@ class VolumeToolPanel(wx.Panel):
422 423
423 def __init_menus(self, pubsub_evt=None): 424 def __init_menus(self, pubsub_evt=None):
424 # MENU RELATED TO RAYCASTING TYPES 425 # MENU RELATED TO RAYCASTING TYPES
425 - menu = wx.Menu() 426 + menu = self.menu = wx.Menu()
426 for name in const.RAYCASTING_TYPES: 427 for name in const.RAYCASTING_TYPES:
427 id = wx.NewId() 428 id = wx.NewId()
428 item = wx.MenuItem(menu, id, name, kind=wx.ITEM_RADIO) 429 item = wx.MenuItem(menu, id, name, kind=wx.ITEM_RADIO)
@@ -434,9 +435,13 @@ class VolumeToolPanel(wx.Panel): @@ -434,9 +435,13 @@ class VolumeToolPanel(wx.Panel):
434 435
435 menu.AppendSeparator() 436 menu.AppendSeparator()
436 # MENU RELATED TO RAYCASTING TOOLS 437 # MENU RELATED TO RAYCASTING TOOLS
  438 + self.id_cutplane = None
437 submenu = wx.Menu() 439 submenu = wx.Menu()
438 for name in const.RAYCASTING_TOOLS: 440 for name in const.RAYCASTING_TOOLS:
439 id = wx.NewId() 441 id = wx.NewId()
  442 + if not(self.id_cutplane):
  443 + self.id_cutplane = id
  444 +
440 item = wx.MenuItem(submenu, id, name, kind=wx.ITEM_CHECK) 445 item = wx.MenuItem(submenu, id, name, kind=wx.ITEM_CHECK)
441 submenu.AppendItem(item) 446 submenu.AppendItem(item)
442 ID_TO_TOOL[id] = name 447 ID_TO_TOOL[id] = name
@@ -480,6 +485,11 @@ class VolumeToolPanel(wx.Panel): @@ -480,6 +485,11 @@ class VolumeToolPanel(wx.Panel):
480 485
481 self.Fit() 486 self.Fit()
482 self.Update() 487 self.Update()
  488 +
  489 + def DisableVolumeCutMenu(self, pusub_evt):
  490 + self.menu.Enable(RAYCASTING_TOOLS, 0)
  491 + item = ID_TO_TOOL_ITEM[self.id_cutplane]
  492 + item.Check(0)
483 493
484 def BuildRaycastingMenu(self): 494 def BuildRaycastingMenu(self):
485 presets = [] 495 presets = []