Commit a27efd6525030589c13cce15164ed21ed206bb34
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,6 +213,8 @@ class SurfaceManager(): | ||
213 | Publisher.subscribe(self.UpdateAffineMatrix, 'Update affine matrix') | 213 | Publisher.subscribe(self.UpdateAffineMatrix, 'Update affine matrix') |
214 | Publisher.subscribe(self.UpdateconverttoInVflag, 'Update converttoInV flag') | 214 | Publisher.subscribe(self.UpdateconverttoInVflag, 'Update converttoInV flag') |
215 | 215 | ||
216 | + Publisher.subscribe(self.CreateSurfaceFromPolydata, 'Create surface from polydata') | ||
217 | + | ||
216 | def OnDuplicate(self, surface_indexes): | 218 | def OnDuplicate(self, surface_indexes): |
217 | proj = prj.Project() | 219 | proj = prj.Project() |
218 | surface_dict = proj.surface_dict | 220 | surface_dict = proj.surface_dict |
@@ -356,9 +358,9 @@ class SurfaceManager(): | @@ -356,9 +358,9 @@ class SurfaceManager(): | ||
356 | def UpdateconverttoInVflag(self, converttoInV): | 358 | def UpdateconverttoInVflag(self, converttoInV): |
357 | self.converttoInV = converttoInV | 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 | if self.converttoInV and self.affine is not None: | 364 | if self.converttoInV and self.affine is not None: |
363 | transform = vtk.vtkTransform() | 365 | transform = vtk.vtkTransform() |
364 | transform.SetMatrix(self.affine) | 366 | transform.SetMatrix(self.affine) |
@@ -390,7 +392,9 @@ class SurfaceManager(): | @@ -390,7 +392,9 @@ class SurfaceManager(): | ||
390 | print("BOunds", actor.GetBounds()) | 392 | print("BOunds", actor.GetBounds()) |
391 | 393 | ||
392 | if overwrite: | 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 | else: | 398 | else: |
395 | surface = Surface() | 399 | surface = Surface() |
396 | 400 | ||
@@ -418,6 +422,11 @@ class SurfaceManager(): | @@ -418,6 +422,11 @@ class SurfaceManager(): | ||
418 | # Set actor colour and transparency | 422 | # Set actor colour and transparency |
419 | actor.GetProperty().SetColor(surface.colour) | 423 | actor.GetProperty().SetColor(surface.colour) |
420 | actor.GetProperty().SetOpacity(1-surface.transparency) | 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 | self.actors_dict[surface.index] = actor | 430 | self.actors_dict[surface.index] = actor |
422 | 431 | ||
423 | session = ses.Session() | 432 | session = ses.Session() |
@@ -444,7 +453,6 @@ class SurfaceManager(): | @@ -444,7 +453,6 @@ class SurfaceManager(): | ||
444 | self.last_surface_index = surface.index | 453 | self.last_surface_index = surface.index |
445 | 454 | ||
446 | Publisher.sendMessage('Load surface actor into viewer', actor=actor) | 455 | Publisher.sendMessage('Load surface actor into viewer', actor=actor) |
447 | - | ||
448 | Publisher.sendMessage('Update surface info in GUI', surface=surface) | 456 | Publisher.sendMessage('Update surface info in GUI', surface=surface) |
449 | return surface.index | 457 | return surface.index |
450 | 458 |