Commit 64f82741323b39609d9196fb2b0f8a4bfec61548

Authored by tatiana
1 parent a1115f29

ENH: Visibility of surfaces generated by seeds using connectivity

invesalius/data/polydata_utils.py
... ... @@ -173,7 +173,9 @@ def SplitDisconectedParts(polydata):
173 173 polydata_collection = []
174 174  
175 175 # Update progress value in GUI
176   - UpdateProgress = vu.ShowProgress(nregions - 1)
  176 + progress = nregions -1
  177 + if progress:
  178 + UpdateProgress = vu.ShowProgress(progress)
177 179  
178 180 for region in xrange(nregions):
179 181 conn.InitializeSpecifiedRegionList()
... ... @@ -185,6 +187,7 @@ def SplitDisconectedParts(polydata):
185 187 p.Update()
186 188  
187 189 polydata_collection.append(p)
188   - UpdateProgress(region, _("Splitting disconected parts"))
  190 + if progress:
  191 + UpdateProgress(region, _("Splitting disconected parts"))
189 192  
190 193 return polydata_collection
... ...
invesalius/data/surface.py
... ... @@ -126,6 +126,10 @@ class SurfaceManager():
126 126 ps.Publisher().subscribe(self.OnSeedSurface, "Create surface from seeds")
127 127  
128 128 def OnSeedSurface(self, pubsub_evt):
  129 + """
  130 + Create a new surface, based on the last selected surface,
  131 + using as reference seeds user add to surface of reference.
  132 + """
129 133 points_id_list = pubsub_evt.data
130 134 index = self.last_surface_index
131 135 proj = prj.Project()
... ... @@ -133,27 +137,42 @@ class SurfaceManager():
133 137  
134 138 new_polydata = pu.JoinSeedsParts(surface.polydata,
135 139 points_id_list)
136   - self.CreateSurfaceFromPolydata(new_polydata)
137   - self.ShowActor(index, False)
  140 + index = self.CreateSurfaceFromPolydata(new_polydata)
  141 + ps.Publisher().sendMessage('Show single surface', (index, True))
  142 + #self.ShowActor(index, True)
  143 +
138 144  
139 145 def OnSplitSurface(self, pubsub_evt):
  146 + """
  147 + Create n new surfaces, based on the last selected surface,
  148 + according to their connectivity.
  149 + """
140 150 index = self.last_surface_index
141 151 proj = prj.Project()
142 152 surface = proj.surface_dict[index]
143 153  
  154 + index_list = []
144 155 new_polydata_list = pu.SplitDisconectedParts(surface.polydata)
145 156 for polydata in new_polydata_list:
146   - self.CreateSurfaceFromPolydata(polydata)
147   - self.ShowActor(index, False)
  157 + index = self.CreateSurfaceFromPolydata(polydata)
  158 + index_list.append(index)
  159 + #self.ShowActor(index, True)
  160 +
  161 + ps.Publisher().sendMessage('Show multiple surfaces', (index_list, True))
  162 +
148 163  
149 164 def OnLargestSurface(self, pubsub_evt):
  165 + """
  166 + Create a new surface, based on largest part of the last
  167 + selected surface.
  168 + """
150 169 index = self.last_surface_index
151 170 proj = prj.Project()
152 171 surface = proj.surface_dict[index]
153 172  
154 173 new_polydata = pu.SelectLargestPart(surface.polydata)
155   - self.CreateSurfaceFromPolydata(new_polydata)
156   - self.ShowActor(index, False)
  174 + new_index = self.CreateSurfaceFromPolydata(new_polydata)
  175 + ps.Publisher().sendMessage('Show single surface', (new_index, True))
157 176  
158 177 def CreateSurfaceFromPolydata(self, polydata, overwrite=False):
159 178  
... ... @@ -208,6 +227,8 @@ class SurfaceManager():
208 227 surface.colour, surface.volume,
209 228 surface.transparency))
210 229  
  230 + return surface.index
  231 +
211 232  
212 233 def OnCloseProject(self, pubsub_evt):
213 234 self.CloseProject()
... ... @@ -481,7 +502,6 @@ class SurfaceManager():
481 502  
482 503 def OnShowSurface(self, pubsub_evt):
483 504 index, value = pubsub_evt.data
484   - #print "OnShowSurface", index, value
485 505 self.ShowActor(index, value)
486 506  
487 507 def ShowActor(self, index, value):
... ...
invesalius/gui/data_notebook.py
... ... @@ -341,6 +341,11 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin):
341 341 if i > index:
342 342 new_dict[i-1] = old_dict[i]
343 343 self.mask_list_index = new_dict
  344 +
  345 + if new_dict:
  346 + self.SetItemImage(0, 1)
  347 + ps.Publisher().sendMessage('Show mask', (0, 1))
  348 +
344 349 self.DeleteItem(index)
345 350  
346 351 #-------------------------------------------------
... ... @@ -372,6 +377,10 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin):
372 377 'Set surface colour')
373 378 ps.Publisher().subscribe(self.OnCloseProject, 'Close project data')
374 379  
  380 +
  381 + ps.Publisher().subscribe(self.OnShowSingle, 'Show single surface')
  382 + ps.Publisher().subscribe(self.OnShowMultiple, 'Show multiple surfaces')
  383 +
375 384 def __bind_events_wx(self):
376 385 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated)
377 386 self.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnEditLabel)
... ... @@ -436,6 +445,40 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin):
436 445 def OnCheckItem(self, index, flag):
437 446 ps.Publisher().sendMessage('Show surface', (index, flag))
438 447  
  448 + def OnShowSingle(self, pubsub_evt):
  449 + index, visibility = pubsub_evt.data
  450 + print "----------------------"
  451 + print "OnShowSingle"
  452 + print "index", index
  453 + print "visibility", visibility
  454 + print "----------------------"
  455 + for key in self.surface_list_index.keys():
  456 + if key != index:
  457 + self.SetItemImage(key, not visibility)
  458 + ps.Publisher().sendMessage('Show surface',
  459 + (key, not visibility))
  460 + self.SetItemImage(index, visibility)
  461 + ps.Publisher().sendMessage('Show surface',
  462 + (index, visibility))
  463 +
  464 + def OnShowMultiple(self, pubsub_evt):
  465 + index_list, visibility = pubsub_evt.data
  466 + print "----------------------"
  467 + print "OnShowMultiple"
  468 + print "index", index_list
  469 + print "visibility", visibility
  470 + print "----------------------"
  471 +
  472 + for key in self.surface_list_index.keys():
  473 + if key not in index_list:
  474 + self.SetItemImage(key, not visibility)
  475 + ps.Publisher().sendMessage('Show surface',
  476 + (key, not visibility))
  477 + for index in index_list:
  478 + self.SetItemImage(index, visibility)
  479 + ps.Publisher().sendMessage('Show surface',
  480 + (index, visibility))
  481 +
439 482 def AddSurface(self, pubsub_evt):
440 483  
441 484  
... ...