Commit c5c9a4728a6275b102029cf907d6eb19d008f954
1 parent
4303f718
Exists in
master
and in
6 other branches
ADD: Surface duplication support on the way
Showing
1 changed file
with
53 additions
and
8 deletions
Show diff stats
invesalius/data/surface.py
... | ... | @@ -33,6 +33,7 @@ import polydata_utils as pu |
33 | 33 | import project as prj |
34 | 34 | import session as ses |
35 | 35 | import surface_process |
36 | +import utils as utl | |
36 | 37 | import vtk_utils as vu |
37 | 38 | |
38 | 39 | class Surface(): |
... | ... | @@ -125,17 +126,47 @@ class SurfaceManager(): |
125 | 126 | 'Create surface from largest region') |
126 | 127 | ps.Publisher().subscribe(self.OnSeedSurface, "Create surface from seeds") |
127 | 128 | |
128 | - | |
129 | + ps.Publisher().subscribe(self.OnDuplicate, "Duplicate surfaces") | |
129 | 130 | ps.Publisher().subscribe(self.OnRemove,"Remove surfaces") |
131 | + ps.Publisher().subscribe(self.OnDuplicate, "Duplicate surfaces") | |
132 | + | |
133 | + | |
134 | + def OnDuplicate(self, pubsub_evt): | |
135 | + | |
136 | + selected_items = pubsub_evt.data | |
137 | + proj = prj.Project() | |
138 | + surface_dict = proj.surface_dict | |
139 | + for index in selected_items: | |
140 | + original_surface = surface_dict[index] | |
141 | + # compute copy name | |
142 | + name = original_surface.name | |
143 | + names_list = [surface_dict[i].name for i in surface_dict.keys()] | |
144 | + new_name = utl.next_copy_name(name, names_list) | |
145 | + # create new mask | |
146 | + self.CreateSurfaceFromPolydata(polydata = original_surface.polydata, | |
147 | + overwrite = False, | |
148 | + name = new_name, | |
149 | + colour = original_surface.colour, | |
150 | + transparency = original_surface.transparency, | |
151 | + volume = original_surface.volume) | |
152 | + | |
130 | 153 | |
131 | 154 | |
132 | 155 | def OnRemove(self, pubsub_evt): |
156 | + print "OnRemove" | |
133 | 157 | selected_items = pubsub_evt.data |
134 | 158 | proj = prj.Project() |
135 | 159 | for item in selected_items: |
160 | + print "before" | |
161 | + print "1:", proj.surface_dict | |
162 | + print "2:", self.actors_dict | |
136 | 163 | proj.RemoveSurface(item) |
164 | + print "after" | |
165 | + print "1", proj.surface_dict | |
137 | 166 | actor = self.actors_dict[item] |
138 | 167 | self.actors_dict.pop(item) |
168 | + print "2", self.actors_dict | |
169 | + print "\n" | |
139 | 170 | ps.Publisher().sendMessage('Remove surface actor from viewer', actor) |
140 | 171 | |
141 | 172 | def OnSeedSurface(self, pubsub_evt): |
... | ... | @@ -187,7 +218,9 @@ class SurfaceManager(): |
187 | 218 | new_index = self.CreateSurfaceFromPolydata(new_polydata) |
188 | 219 | ps.Publisher().sendMessage('Show single surface', (new_index, True)) |
189 | 220 | |
190 | - def CreateSurfaceFromPolydata(self, polydata, overwrite=False): | |
221 | + def CreateSurfaceFromPolydata(self, polydata, overwrite=False, | |
222 | + name=None, colour=None, | |
223 | + transparency=None, volume=None): | |
191 | 224 | |
192 | 225 | normals = vtk.vtkPolyDataNormals() |
193 | 226 | normals.SetInput(polydata) |
... | ... | @@ -206,9 +239,18 @@ class SurfaceManager(): |
206 | 239 | else: |
207 | 240 | surface = Surface() |
208 | 241 | |
209 | - surface.colour = random.choice(const.SURFACE_COLOUR) | |
242 | + if not colour: | |
243 | + surface.colour = random.choice(const.SURFACE_COLOUR) | |
244 | + else: | |
245 | + surface.colour = colour | |
210 | 246 | surface.polydata = polydata |
211 | 247 | |
248 | + if transparency: | |
249 | + surface.transparency = transparency | |
250 | + | |
251 | + if name: | |
252 | + surface.name = name | |
253 | + | |
212 | 254 | # Set actor colour and transparency |
213 | 255 | actor.GetProperty().SetColor(surface.colour) |
214 | 256 | actor.GetProperty().SetOpacity(1-surface.transparency) |
... | ... | @@ -227,10 +269,13 @@ class SurfaceManager(): |
227 | 269 | session.ChangeProject() |
228 | 270 | |
229 | 271 | # The following lines have to be here, otherwise all volumes disappear |
230 | - measured_polydata = vtk.vtkMassProperties() | |
231 | - measured_polydata.SetInput(polydata) | |
232 | - volume = measured_polydata.GetVolume() | |
233 | - surface.volume = volume | |
272 | + if not volume: | |
273 | + measured_polydata = vtk.vtkMassProperties() | |
274 | + measured_polydata.SetInput(polydata) | |
275 | + volume = measured_polydata.GetVolume() | |
276 | + surface.volume = volume | |
277 | + else: | |
278 | + surface.volume = volume | |
234 | 279 | self.last_surface_index = surface.index |
235 | 280 | |
236 | 281 | ps.Publisher().sendMessage('Load surface actor into viewer', actor) |
... | ... | @@ -568,7 +613,7 @@ class SurfaceManager(): |
568 | 613 | polydata_list.append(surface.polydata) |
569 | 614 | |
570 | 615 | if len(polydata_list) == 0: |
571 | - print "oops - no polydata" | |
616 | + utl.debug("oops - no polydata") | |
572 | 617 | return |
573 | 618 | elif len(polydata_list) == 1: |
574 | 619 | polydata = polydata_list[0] | ... | ... |