From fea0946c7c0eb3719d0f63834d6b989866092562 Mon Sep 17 00:00:00 2001 From: tatiana Date: Fri, 22 Jan 2010 18:03:23 +0000 Subject: [PATCH] FIX: Load surfaces from an existing project --- invesalius/data/surface.py | 37 +++++++++++++++++++++++++++++++++++-- invesalius/gui/task_surface.py | 2 +- invesalius/utils.py | 6 ++++++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/invesalius/data/surface.py b/invesalius/data/surface.py index e42971b..9383f7e 100644 --- a/invesalius/data/surface.py +++ b/invesalius/data/surface.py @@ -141,16 +141,49 @@ class SurfaceManager(): def OnLoadSurfaceDict(self, pubsub_evt): surface_dict = pubsub_evt.data - #self.actors_dict[surface.index] for key in surface_dict: surface = surface_dict[key] + # Map polygonal data (vtkPolyData) to graphics primitives. + + normals = vtk.vtkPolyDataNormals() + normals.SetInput(surface.polydata) + normals.SetFeatureAngle(80) + normals.AutoOrientNormalsOn() + normals.GetOutput().ReleaseDataFlagOn() + + stripper = vtk.vtkStripper() + stripper.SetInput(normals.GetOutput()) + stripper.PassThroughCellIdsOn() + stripper.PassThroughPointIdsOn() + + mapper = vtk.vtkPolyDataMapper() + mapper.SetInput(stripper.GetOutput()) + mapper.ScalarVisibilityOff() + + # Represent an object (geometry & properties) in the rendered scene + actor = vtk.vtkActor() + actor.SetMapper(mapper) + + # Set actor colour and transparency + actor.GetProperty().SetColor(surface.colour) + actor.GetProperty().SetOpacity(1-surface.transparency) + + 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', + _("Ready")) + + # The following lines have to be here, otherwise all volumes disappear ps.Publisher().sendMessage('Update surface info in GUI', (surface.index, surface.name, surface.colour, surface.volume, surface.transparency)) - def AddNewActor(self, pubsub_evt): """ Create surface actor, save into project and send it to viewer. diff --git a/invesalius/gui/task_surface.py b/invesalius/gui/task_surface.py index b0b12ee..5809a90 100644 --- a/invesalius/gui/task_surface.py +++ b/invesalius/gui/task_surface.py @@ -291,7 +291,7 @@ class SurfaceProperties(wx.Panel): def ChangeSurfaceName(self, pubsub_evt): index, name = pubsub_evt.data old_name = self.surface_dict.get_key(index) - self.surface_dict.pop(old_name, None) + self.surface_dict.remove(old_name) self.surface_dict[name] = index self.combo_surface_name.SetString(index, name) self.combo_surface_name.Refresh() diff --git a/invesalius/utils.py b/invesalius/utils.py index ef38763..375eed3 100755 --- a/invesalius/utils.py +++ b/invesalius/utils.py @@ -63,6 +63,12 @@ class TwoWaysDictionary(dict): """ return [item[0] for item in self.items() if item[1] == value] + def remove(self, key): + try: + self.pop(key) + except TypeError: + print "TwoWaysDictionary: no item" + def get_value(self, key): """ Find the value given a key. -- libgit2 0.21.2