Commit fea0946c7c0eb3719d0f63834d6b989866092562
1 parent
b5b338bc
Exists in
master
and in
68 other branches
FIX: Load surfaces from an existing project
Showing
3 changed files
with
42 additions
and
3 deletions
Show diff stats
invesalius/data/surface.py
@@ -141,16 +141,49 @@ class SurfaceManager(): | @@ -141,16 +141,49 @@ class SurfaceManager(): | ||
141 | 141 | ||
142 | def OnLoadSurfaceDict(self, pubsub_evt): | 142 | def OnLoadSurfaceDict(self, pubsub_evt): |
143 | surface_dict = pubsub_evt.data | 143 | surface_dict = pubsub_evt.data |
144 | - #self.actors_dict[surface.index] | ||
145 | 144 | ||
146 | for key in surface_dict: | 145 | for key in surface_dict: |
147 | surface = surface_dict[key] | 146 | surface = surface_dict[key] |
147 | + # Map polygonal data (vtkPolyData) to graphics primitives. | ||
148 | + | ||
149 | + normals = vtk.vtkPolyDataNormals() | ||
150 | + normals.SetInput(surface.polydata) | ||
151 | + normals.SetFeatureAngle(80) | ||
152 | + normals.AutoOrientNormalsOn() | ||
153 | + normals.GetOutput().ReleaseDataFlagOn() | ||
154 | + | ||
155 | + stripper = vtk.vtkStripper() | ||
156 | + stripper.SetInput(normals.GetOutput()) | ||
157 | + stripper.PassThroughCellIdsOn() | ||
158 | + stripper.PassThroughPointIdsOn() | ||
159 | + | ||
160 | + mapper = vtk.vtkPolyDataMapper() | ||
161 | + mapper.SetInput(stripper.GetOutput()) | ||
162 | + mapper.ScalarVisibilityOff() | ||
163 | + | ||
164 | + # Represent an object (geometry & properties) in the rendered scene | ||
165 | + actor = vtk.vtkActor() | ||
166 | + actor.SetMapper(mapper) | ||
167 | + | ||
168 | + # Set actor colour and transparency | ||
169 | + actor.GetProperty().SetColor(surface.colour) | ||
170 | + actor.GetProperty().SetOpacity(1-surface.transparency) | ||
171 | + | ||
172 | + self.actors_dict[surface.index] = actor | ||
173 | + | ||
174 | + | ||
175 | + # Send actor by pubsub to viewer's render | ||
176 | + ps.Publisher().sendMessage('Load surface actor into viewer', (actor)) | ||
177 | + | ||
178 | + ps.Publisher().sendMessage('Update status text in GUI', | ||
179 | + _("Ready")) | ||
180 | + | ||
181 | + # The following lines have to be here, otherwise all volumes disappear | ||
148 | 182 | ||
149 | ps.Publisher().sendMessage('Update surface info in GUI', | 183 | ps.Publisher().sendMessage('Update surface info in GUI', |
150 | (surface.index, surface.name, | 184 | (surface.index, surface.name, |
151 | surface.colour, surface.volume, | 185 | surface.colour, surface.volume, |
152 | surface.transparency)) | 186 | surface.transparency)) |
153 | - | ||
154 | def AddNewActor(self, pubsub_evt): | 187 | def AddNewActor(self, pubsub_evt): |
155 | """ | 188 | """ |
156 | Create surface actor, save into project and send it to viewer. | 189 | Create surface actor, save into project and send it to viewer. |
invesalius/gui/task_surface.py
@@ -291,7 +291,7 @@ class SurfaceProperties(wx.Panel): | @@ -291,7 +291,7 @@ class SurfaceProperties(wx.Panel): | ||
291 | def ChangeSurfaceName(self, pubsub_evt): | 291 | def ChangeSurfaceName(self, pubsub_evt): |
292 | index, name = pubsub_evt.data | 292 | index, name = pubsub_evt.data |
293 | old_name = self.surface_dict.get_key(index) | 293 | old_name = self.surface_dict.get_key(index) |
294 | - self.surface_dict.pop(old_name, None) | 294 | + self.surface_dict.remove(old_name) |
295 | self.surface_dict[name] = index | 295 | self.surface_dict[name] = index |
296 | self.combo_surface_name.SetString(index, name) | 296 | self.combo_surface_name.SetString(index, name) |
297 | self.combo_surface_name.Refresh() | 297 | self.combo_surface_name.Refresh() |
invesalius/utils.py
@@ -63,6 +63,12 @@ class TwoWaysDictionary(dict): | @@ -63,6 +63,12 @@ class TwoWaysDictionary(dict): | ||
63 | """ | 63 | """ |
64 | return [item[0] for item in self.items() if item[1] == value] | 64 | return [item[0] for item in self.items() if item[1] == value] |
65 | 65 | ||
66 | + def remove(self, key): | ||
67 | + try: | ||
68 | + self.pop(key) | ||
69 | + except TypeError: | ||
70 | + print "TwoWaysDictionary: no item" | ||
71 | + | ||
66 | def get_value(self, key): | 72 | def get_value(self, key): |
67 | """ | 73 | """ |
68 | Find the value given a key. | 74 | Find the value given a key. |