diff --git a/invesalius/data/slice_.py b/invesalius/data/slice_.py index 415b242..5fda25f 100644 --- a/invesalius/data/slice_.py +++ b/invesalius/data/slice_.py @@ -131,9 +131,9 @@ class Slice(object): #--------------------------------------------------------------------------- # BEGIN PUBSUB_EVT METHODS #--------------------------------------------------------------------------- - def __get_mask_data_for_surface_creation(self, pubsub_evt): - mask_index = pubsub_evt.data - CreateSurfaceFromIndex + #def __get_mask_data_for_surface_creation(self, pubsub_evt): + # mask_index = pubsub_evt.data + # CreateSurfaceFromIndex def __add_mask(self, pubsub_evt): mask_name = pubsub_evt.data @@ -363,14 +363,9 @@ class Slice(object): ps.Publisher().sendMessage('Update slice viewer') #--------------------------------------------------------------------------- - - - - - def CreateSurfaceFromIndex(self, pubsub_evt): - mask_index = pubsub_evt.data - + mask_index, overwrite_surface = pubsub_evt.data + proj = Project() mask = proj.mask_dict[mask_index] @@ -384,7 +379,8 @@ class Slice(object): edited_points = mask.edited_points ps.Publisher().sendMessage('Create surface', - (imagedata,colour,threshold, edited_points)) + (imagedata,colour,threshold, + edited_points, overwrite_surface)) def GetOutput(self): return self.cross.GetOutput() diff --git a/invesalius/data/surface.py b/invesalius/data/surface.py index d512a76..5376b16 100644 --- a/invesalius/data/surface.py +++ b/invesalius/data/surface.py @@ -39,15 +39,18 @@ class Surface(): Represent both vtkPolyData and associated properties. """ general_index = -1 - def __init__(self): + def __init__(self, index=None): Surface.general_index += 1 - self.index = Surface.general_index + if index is None: + self.index = Surface.general_index + else: + self.index = index self.polydata = '' self.colour = '' self.transparency = const.SURFACE_TRANSPARENCY self.volume = 0 self.is_shown = 1 - self.name = const.SURFACE_NAME_PATTERN %(Surface.general_index+1) + self.name = const.SURFACE_NAME_PATTERN %(self.index+1) def SavePlist(self, filename): surface = {} @@ -95,6 +98,7 @@ class SurfaceManager(): """ def __init__(self): self.actors_dict = {} + self.last_surface_index = 0 self.__bind_events() def __bind_events(self): @@ -168,7 +172,11 @@ class SurfaceManager(): """ Create surface actor, save into project and send it to viewer. """ - imagedata, colour, [min_value, max_value], edited_points = pubsub_evt.data + imagedata, colour, [min_value, max_value], \ + edited_points, overwrite = pubsub_evt.data + + + print "---------------- OVERWRITE:",overwrite quality=_('Optimal *') mode = 'CONTOUR' # 'GRAYSCALE' ps.Publisher().sendMessage('Begin busy cursor') @@ -253,7 +261,10 @@ class SurfaceManager(): actor.SetMapper(mapper) # Create Surface instance - surface = Surface() + if overwrite: + surface = Surface(index = self.last_surface_index) + else: + surface = Surface() surface.colour = colour surface.polydata = polydata @@ -281,29 +292,38 @@ class SurfaceManager(): # Append surface into Project.surface_dict proj = prj.Project() - index = proj.AddSurface(surface) - surface.index = index + if overwrite: + proj.ChangeSurface(surface) + else: + index = proj.AddSurface(surface) + surface.index = index session = ses.Session() session.ChangeProject() - # Save actor for future management tasks - self.actors_dict[surface.index] = actor - - # Send actor by pubsub to viewer's render - ps.Publisher().sendMessage('Load surface actor into viewer', (actor)) - - ps.Publisher().sendMessage('Update status text in GUI', - "Surface created.") - # The following lines have to be here, otherwise all volumes disappear measured_polydata = vtk.vtkMassProperties() measured_polydata.SetInput(polydata) volume = measured_polydata.GetVolume() surface.volume = volume + self.last_surface_index = surface.index + + ps.Publisher().sendMessage('Load surface actor into viewer', actor) + # Send actor by pubsub to viewer's render + if overwrite: + old_actor = self.actors_dict[self.last_surface_index] + ps.Publisher().sendMessage('Remove surface actor from viewer', old_actor) + + # Save actor for future management tasks + self.actors_dict[surface.index] = actor + + + ps.Publisher().sendMessage('Update status text in GUI', + _("Ready")) + ps.Publisher().sendMessage('Update surface info in GUI', (surface.index, surface.name, surface.colour, surface.volume, diff --git a/invesalius/data/viewer_volume.py b/invesalius/data/viewer_volume.py index 03c721e..d1dd2f9 100755 --- a/invesalius/data/viewer_volume.py +++ b/invesalius/data/viewer_volume.py @@ -83,6 +83,8 @@ class Viewer(wx.Panel): def __bind_events(self): ps.Publisher().subscribe(self.LoadActor, 'Load surface actor into viewer') + ps.Publisher().subscribe(self.RemoveActor, + 'Remove surface actor from viewer') ps.Publisher().subscribe(self.UpdateRender, 'Render volume viewer') ps.Publisher().subscribe(self.ChangeBackgroundColour, @@ -351,6 +353,15 @@ class Viewer(wx.Panel): #self.ShowOrientationCube() self.interactor.Render() + def RemoveActor(self, pubsub_evt): + print "RemoveActor" + actor = pubsub_evt.data + + ren = self.ren + ren.RemoveActor(actor) + + self.interactor.Render() + def LoadSlicePlane(self, pubsub_evt): self.slice_plane = SlicePlane() diff --git a/invesalius/gui/data_notebook.py b/invesalius/gui/data_notebook.py index 4c68b22..82a8d4c 100644 --- a/invesalius/gui/data_notebook.py +++ b/invesalius/gui/data_notebook.py @@ -273,6 +273,8 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): ps.Publisher().sendMessage('Show surface', (index, flag)) def AddSurface(self, pubsub_evt): + + index = pubsub_evt.data[0] name = pubsub_evt.data[1] colour = pubsub_evt.data[2] @@ -281,9 +283,19 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): image = self.CreateColourBitmap(colour) image_index = self.imagelist.Add(image) + + + + index_list = self.surface_list_index.keys() self.surface_list_index[index] = image_index + + if (index in index_list) and index_list: + self.UpdateItemInfo(index, name, volume, transparency, colour) + else: + self.InsertNewItem(index, name, volume, transparency, colour) + - self.InsertNewItem(index, name, volume, transparency, colour) + def InsertNewItem(self, index=0, label="Surface 1", volume="0 mm3", transparency="0%%", colour=None): @@ -293,6 +305,15 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): self.SetStringItem(index, 2, volume) self.SetStringItem(index, 3, transparency) self.SetItemImage(index, 1) + + def UpdateItemInfo(self, index=0, label="Surface 1", volume="0 mm3", + transparency="0%%", colour=None): + self.SetStringItem(index, 1, label, + imageId = self.surface_list_index[index]) + self.SetStringItem(index, 2, volume) + self.SetStringItem(index, 3, transparency) + self.SetItemImage(index, 1) + def CreateColourBitmap(self, colour): """ diff --git a/invesalius/gui/task_slice.py b/invesalius/gui/task_slice.py index 475f6bb..1cf41c1 100644 --- a/invesalius/gui/task_slice.py +++ b/invesalius/gui/task_slice.py @@ -106,17 +106,25 @@ class InnerTaskPanel(wx.Panel): self.fold_panel = fold_panel # Button to fold to select region task - button_next = wx.Button(self, -1, _("Create 3D surface")) + button_next = wx.Button(self, -1, _("Save surface")) + check_box = wx.CheckBox(self, -1, _("Overwrite last surface")) + self.check_box = check_box if sys.platform != 'win32': button_next.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) + check_box.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) button_next.Bind(wx.EVT_BUTTON, self.OnButtonNextTask) + line_sizer = wx.BoxSizer(wx.HORIZONTAL) + line_sizer.Add(check_box, 1, wx.ALIGN_LEFT|wx.RIGHT|wx.LEFT|wx.BOTTOM, 5) + line_sizer.Add(button_next, 0, + wx.ALIGN_RIGHT|wx.RIGHT|wx.LEFT|wx.BOTTOM, 5) + line_sizer.Fit(self) + # Add line sizers into main sizer main_sizer = wx.BoxSizer(wx.VERTICAL) main_sizer.Add(line_new, 0,wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) - main_sizer.Add(fold_panel, 1, wx.GROW|wx.EXPAND|wx.ALL, 5) - main_sizer.Add(button_next, 0, - wx.ALIGN_RIGHT|wx.RIGHT|wx.LEFT|wx.BOTTOM, 5) + main_sizer.Add(fold_panel, 6, wx.GROW|wx.EXPAND|wx.ALL, 5) + main_sizer.AddSizer(line_sizer, 1, wx.GROW|wx.EXPAND) main_sizer.Fit(self) self.SetSizer(main_sizer) @@ -130,9 +138,12 @@ class InnerTaskPanel(wx.Panel): if id == BTN_NEW: self.OnLinkNewMask() + def OnButtonNextTask(self, evt): + overwrite = self.check_box.IsChecked() ps.Publisher().sendMessage('Create surface from index', - self.GetMaskSelected()) + (self.GetMaskSelected(), + overwrite)) def OnLinkNewMask(self, evt=None): dlg = wx.TextEntryDialog(self, _('Name of new mask:'), diff --git a/invesalius/project.py b/invesalius/project.py index a7a9b00..ae4ff08 100755 --- a/invesalius/project.py +++ b/invesalius/project.py @@ -130,6 +130,10 @@ class Project(object): self.surface_dict[index] = surface return index + def ChangeSurface(self, surface): + index = surface.index + self.surface_dict[index] = surface + def RemoveSurface(self, index): new_dict = {} for i in self.surface_dict: -- libgit2 0.21.2