Commit a27efd6525030589c13cce15164ed21ed206bb34

Authored by Thiago Franco de Moraes
1 parent 07f7b52a
Exists in master

Created a pubsub subscribe to create surface from polydata

Showing 1 changed file with 13 additions and 5 deletions   Show diff stats
invesalius/data/surface.py
... ... @@ -213,6 +213,8 @@ class SurfaceManager():
213 213 Publisher.subscribe(self.UpdateAffineMatrix, 'Update affine matrix')
214 214 Publisher.subscribe(self.UpdateconverttoInVflag, 'Update converttoInV flag')
215 215  
  216 + Publisher.subscribe(self.CreateSurfaceFromPolydata, 'Create surface from polydata')
  217 +
216 218 def OnDuplicate(self, surface_indexes):
217 219 proj = prj.Project()
218 220 surface_dict = proj.surface_dict
... ... @@ -356,9 +358,9 @@ class SurfaceManager():
356 358 def UpdateconverttoInVflag(self, converttoInV):
357 359 self.converttoInV = converttoInV
358 360  
359   - def CreateSurfaceFromPolydata(self, polydata, overwrite=False,
360   - name=None, colour=None,
361   - transparency=None, volume=None, area=None, scalar=False):
  361 + def CreateSurfaceFromPolydata(self, polydata, overwrite=False, index=None,
  362 + name=None, colour=None, transparency=None,
  363 + volume=None, area=None, scalar=False):
362 364 if self.converttoInV and self.affine is not None:
363 365 transform = vtk.vtkTransform()
364 366 transform.SetMatrix(self.affine)
... ... @@ -390,7 +392,9 @@ class SurfaceManager():
390 392 print("BOunds", actor.GetBounds())
391 393  
392 394 if overwrite:
393   - surface = Surface(index = self.last_surface_index)
  395 + if index is None:
  396 + index = self.last_surface_index
  397 + surface = Surface(index=index)
394 398 else:
395 399 surface = Surface()
396 400  
... ... @@ -418,6 +422,11 @@ class SurfaceManager():
418 422 # Set actor colour and transparency
419 423 actor.GetProperty().SetColor(surface.colour)
420 424 actor.GetProperty().SetOpacity(1-surface.transparency)
  425 +
  426 + if overwrite and self.actors_dict.keys():
  427 + old_actor = self.actors_dict[index]
  428 + Publisher.sendMessage('Remove surface actor from viewer', actor=old_actor)
  429 +
421 430 self.actors_dict[surface.index] = actor
422 431  
423 432 session = ses.Session()
... ... @@ -444,7 +453,6 @@ class SurfaceManager():
444 453 self.last_surface_index = surface.index
445 454  
446 455 Publisher.sendMessage('Load surface actor into viewer', actor=actor)
447   -
448 456 Publisher.sendMessage('Update surface info in GUI', surface=surface)
449 457 return surface.index
450 458  
... ...