From 64f82741323b39609d9196fb2b0f8a4bfec61548 Mon Sep 17 00:00:00 2001 From: tatiana Date: Wed, 10 Feb 2010 11:22:41 +0000 Subject: [PATCH] ENH: Visibility of surfaces generated by seeds using connectivity --- invesalius/data/polydata_utils.py | 7 +++++-- invesalius/data/surface.py | 34 +++++++++++++++++++++++++++------- invesalius/gui/data_notebook.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 9 deletions(-) diff --git a/invesalius/data/polydata_utils.py b/invesalius/data/polydata_utils.py index cbc1da8..9d832c3 100644 --- a/invesalius/data/polydata_utils.py +++ b/invesalius/data/polydata_utils.py @@ -173,7 +173,9 @@ def SplitDisconectedParts(polydata): polydata_collection = [] # Update progress value in GUI - UpdateProgress = vu.ShowProgress(nregions - 1) + progress = nregions -1 + if progress: + UpdateProgress = vu.ShowProgress(progress) for region in xrange(nregions): conn.InitializeSpecifiedRegionList() @@ -185,6 +187,7 @@ def SplitDisconectedParts(polydata): p.Update() polydata_collection.append(p) - UpdateProgress(region, _("Splitting disconected parts")) + if progress: + UpdateProgress(region, _("Splitting disconected parts")) return polydata_collection diff --git a/invesalius/data/surface.py b/invesalius/data/surface.py index 0a4e8aa..bb011df 100644 --- a/invesalius/data/surface.py +++ b/invesalius/data/surface.py @@ -126,6 +126,10 @@ class SurfaceManager(): ps.Publisher().subscribe(self.OnSeedSurface, "Create surface from seeds") def OnSeedSurface(self, pubsub_evt): + """ + Create a new surface, based on the last selected surface, + using as reference seeds user add to surface of reference. + """ points_id_list = pubsub_evt.data index = self.last_surface_index proj = prj.Project() @@ -133,27 +137,42 @@ class SurfaceManager(): new_polydata = pu.JoinSeedsParts(surface.polydata, points_id_list) - self.CreateSurfaceFromPolydata(new_polydata) - self.ShowActor(index, False) + index = self.CreateSurfaceFromPolydata(new_polydata) + ps.Publisher().sendMessage('Show single surface', (index, True)) + #self.ShowActor(index, True) + def OnSplitSurface(self, pubsub_evt): + """ + Create n new surfaces, based on the last selected surface, + according to their connectivity. + """ index = self.last_surface_index proj = prj.Project() surface = proj.surface_dict[index] + index_list = [] new_polydata_list = pu.SplitDisconectedParts(surface.polydata) for polydata in new_polydata_list: - self.CreateSurfaceFromPolydata(polydata) - self.ShowActor(index, False) + index = self.CreateSurfaceFromPolydata(polydata) + index_list.append(index) + #self.ShowActor(index, True) + + ps.Publisher().sendMessage('Show multiple surfaces', (index_list, True)) + def OnLargestSurface(self, pubsub_evt): + """ + Create a new surface, based on largest part of the last + selected surface. + """ index = self.last_surface_index proj = prj.Project() surface = proj.surface_dict[index] new_polydata = pu.SelectLargestPart(surface.polydata) - self.CreateSurfaceFromPolydata(new_polydata) - self.ShowActor(index, False) + new_index = self.CreateSurfaceFromPolydata(new_polydata) + ps.Publisher().sendMessage('Show single surface', (new_index, True)) def CreateSurfaceFromPolydata(self, polydata, overwrite=False): @@ -208,6 +227,8 @@ class SurfaceManager(): surface.colour, surface.volume, surface.transparency)) + return surface.index + def OnCloseProject(self, pubsub_evt): self.CloseProject() @@ -481,7 +502,6 @@ class SurfaceManager(): def OnShowSurface(self, pubsub_evt): index, value = pubsub_evt.data - #print "OnShowSurface", index, value self.ShowActor(index, value) def ShowActor(self, index, value): diff --git a/invesalius/gui/data_notebook.py b/invesalius/gui/data_notebook.py index 5b2c5ce..d8c1e43 100644 --- a/invesalius/gui/data_notebook.py +++ b/invesalius/gui/data_notebook.py @@ -341,6 +341,11 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): if i > index: new_dict[i-1] = old_dict[i] self.mask_list_index = new_dict + + if new_dict: + self.SetItemImage(0, 1) + ps.Publisher().sendMessage('Show mask', (0, 1)) + self.DeleteItem(index) #------------------------------------------------- @@ -372,6 +377,10 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): 'Set surface colour') ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') + + ps.Publisher().subscribe(self.OnShowSingle, 'Show single surface') + ps.Publisher().subscribe(self.OnShowMultiple, 'Show multiple surfaces') + def __bind_events_wx(self): self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated) self.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnEditLabel) @@ -436,6 +445,40 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): def OnCheckItem(self, index, flag): ps.Publisher().sendMessage('Show surface', (index, flag)) + def OnShowSingle(self, pubsub_evt): + index, visibility = pubsub_evt.data + print "----------------------" + print "OnShowSingle" + print "index", index + print "visibility", visibility + print "----------------------" + for key in self.surface_list_index.keys(): + if key != index: + self.SetItemImage(key, not visibility) + ps.Publisher().sendMessage('Show surface', + (key, not visibility)) + self.SetItemImage(index, visibility) + ps.Publisher().sendMessage('Show surface', + (index, visibility)) + + def OnShowMultiple(self, pubsub_evt): + index_list, visibility = pubsub_evt.data + print "----------------------" + print "OnShowMultiple" + print "index", index_list + print "visibility", visibility + print "----------------------" + + for key in self.surface_list_index.keys(): + if key not in index_list: + self.SetItemImage(key, not visibility) + ps.Publisher().sendMessage('Show surface', + (key, not visibility)) + for index in index_list: + self.SetItemImage(index, visibility) + ps.Publisher().sendMessage('Show surface', + (index, visibility)) + def AddSurface(self, pubsub_evt): -- libgit2 0.21.2