Commit ce0616257cc7dc852fb3258acaf0e92e8f246522
1 parent
a2350755
Exists in
master
and in
5 other branches
Resolved the problem with the input of vtkMassProperties not being a VTK_TRIANGLE
Showing
1 changed file
with
3 additions
and
57 deletions
Show diff stats
invesalius/data/surface.py
@@ -148,7 +148,6 @@ class SurfaceManager(): | @@ -148,7 +148,6 @@ class SurfaceManager(): | ||
148 | transparency = original_surface.transparency, | 148 | transparency = original_surface.transparency, |
149 | volume = original_surface.volume) | 149 | volume = original_surface.volume) |
150 | 150 | ||
151 | - | ||
152 | def OnRemove(self, pubsub_evt): | 151 | def OnRemove(self, pubsub_evt): |
153 | selected_items = pubsub_evt.data | 152 | selected_items = pubsub_evt.data |
154 | proj = prj.Project() | 153 | proj = prj.Project() |
@@ -173,7 +172,6 @@ class SurfaceManager(): | @@ -173,7 +172,6 @@ class SurfaceManager(): | ||
173 | self.last_surface_index = 0 | 172 | self.last_surface_index = 0 |
174 | else: | 173 | else: |
175 | self.last_surface_index = None | 174 | self.last_surface_index = None |
176 | - | ||
177 | 175 | ||
178 | def OnSeedSurface(self, pubsub_evt): | 176 | def OnSeedSurface(self, pubsub_evt): |
179 | """ | 177 | """ |
@@ -191,7 +189,6 @@ class SurfaceManager(): | @@ -191,7 +189,6 @@ class SurfaceManager(): | ||
191 | ps.Publisher().sendMessage('Show single surface', (index, True)) | 189 | ps.Publisher().sendMessage('Show single surface', (index, True)) |
192 | #self.ShowActor(index, True) | 190 | #self.ShowActor(index, True) |
193 | 191 | ||
194 | - | ||
195 | def OnSplitSurface(self, pubsub_evt): | 192 | def OnSplitSurface(self, pubsub_evt): |
196 | """ | 193 | """ |
197 | Create n new surfaces, based on the last selected surface, | 194 | Create n new surfaces, based on the last selected surface, |
@@ -209,7 +206,6 @@ class SurfaceManager(): | @@ -209,7 +206,6 @@ class SurfaceManager(): | ||
209 | #self.ShowActor(index, True) | 206 | #self.ShowActor(index, True) |
210 | 207 | ||
211 | ps.Publisher().sendMessage('Show multiple surfaces', (index_list, True)) | 208 | ps.Publisher().sendMessage('Show multiple surfaces', (index_list, True)) |
212 | - | ||
213 | 209 | ||
214 | def OnLargestSurface(self, pubsub_evt): | 210 | def OnLargestSurface(self, pubsub_evt): |
215 | """ | 211 | """ |
@@ -257,8 +253,6 @@ class SurfaceManager(): | @@ -257,8 +253,6 @@ class SurfaceManager(): | ||
257 | if name: | 253 | if name: |
258 | surface.name = name | 254 | surface.name = name |
259 | 255 | ||
260 | - | ||
261 | - | ||
262 | # Append surface into Project.surface_dict | 256 | # Append surface into Project.surface_dict |
263 | proj = prj.Project() | 257 | proj = prj.Project() |
264 | if overwrite: | 258 | if overwrite: |
@@ -292,10 +286,8 @@ class SurfaceManager(): | @@ -292,10 +286,8 @@ class SurfaceManager(): | ||
292 | (surface.index, surface.name, | 286 | (surface.index, surface.name, |
293 | surface.colour, surface.volume, | 287 | surface.colour, surface.volume, |
294 | surface.transparency)) | 288 | surface.transparency)) |
295 | - | ||
296 | return surface.index | 289 | return surface.index |
297 | 290 | ||
298 | - | ||
299 | def OnCloseProject(self, pubsub_evt): | 291 | def OnCloseProject(self, pubsub_evt): |
300 | self.CloseProject() | 292 | self.CloseProject() |
301 | 293 | ||
@@ -318,8 +310,6 @@ class SurfaceManager(): | @@ -318,8 +310,6 @@ class SurfaceManager(): | ||
318 | self.last_surface_index = index | 310 | self.last_surface_index = index |
319 | self.ShowActor(index, True) | 311 | self.ShowActor(index, True) |
320 | 312 | ||
321 | - | ||
322 | - | ||
323 | def OnLoadSurfaceDict(self, pubsub_evt): | 313 | def OnLoadSurfaceDict(self, pubsub_evt): |
324 | surface_dict = pubsub_evt.data | 314 | surface_dict = pubsub_evt.data |
325 | for key in surface_dict: | 315 | for key in surface_dict: |
@@ -340,7 +330,7 @@ class SurfaceManager(): | @@ -340,7 +330,7 @@ class SurfaceManager(): | ||
340 | mapper = vtk.vtkPolyDataMapper() | 330 | mapper = vtk.vtkPolyDataMapper() |
341 | mapper.SetInput(stripper.GetOutput()) | 331 | mapper.SetInput(stripper.GetOutput()) |
342 | mapper.ScalarVisibilityOff() | 332 | mapper.ScalarVisibilityOff() |
343 | - mapper.ImmediateModeRenderingOn() # improve performance | 333 | + mapper.ImmediateModeRenderingOn() # improve performance |
344 | 334 | ||
345 | # Represent an object (geometry & properties) in the rendered scene | 335 | # Represent an object (geometry & properties) in the rendered scene |
346 | actor = vtk.vtkActor() | 336 | actor = vtk.vtkActor() |
@@ -352,7 +342,6 @@ class SurfaceManager(): | @@ -352,7 +342,6 @@ class SurfaceManager(): | ||
352 | 342 | ||
353 | self.actors_dict[surface.index] = actor | 343 | self.actors_dict[surface.index] = actor |
354 | 344 | ||
355 | - | ||
356 | # Send actor by pubsub to viewer's render | 345 | # Send actor by pubsub to viewer's render |
357 | ps.Publisher().sendMessage('Load surface actor into viewer', (actor)) | 346 | ps.Publisher().sendMessage('Load surface actor into viewer', (actor)) |
358 | 347 | ||
@@ -360,7 +349,6 @@ class SurfaceManager(): | @@ -360,7 +349,6 @@ class SurfaceManager(): | ||
360 | _("Ready")) | 349 | _("Ready")) |
361 | 350 | ||
362 | # The following lines have to be here, otherwise all volumes disappear | 351 | # The following lines have to be here, otherwise all volumes disappear |
363 | - | ||
364 | ps.Publisher().sendMessage('Update surface info in GUI', | 352 | ps.Publisher().sendMessage('Update surface info in GUI', |
365 | (surface.index, surface.name, | 353 | (surface.index, surface.name, |
366 | surface.colour, surface.volume, | 354 | surface.colour, surface.volume, |
@@ -398,14 +386,6 @@ class SurfaceManager(): | @@ -398,14 +386,6 @@ class SurfaceManager(): | ||
398 | surface_name = "" | 386 | surface_name = "" |
399 | colour = mask.colour | 387 | colour = mask.colour |
400 | 388 | ||
401 | - #ps.Publisher().sendMessage('Begin busy cursor') | ||
402 | - #imagedata_tmp = None | ||
403 | - #if (edited_points): | ||
404 | - #imagedata_tmp = vtk.vtkImageData() | ||
405 | - #imagedata_tmp.DeepCopy(imagedata) | ||
406 | - #imagedata_tmp.Update() | ||
407 | - #imagedata = iu.BuildEditedImage(imagedata_tmp, edited_points) | ||
408 | - | ||
409 | if quality in const.SURFACE_QUALITY.keys(): | 389 | if quality in const.SURFACE_QUALITY.keys(): |
410 | imagedata_resolution = const.SURFACE_QUALITY[quality][0] | 390 | imagedata_resolution = const.SURFACE_QUALITY[quality][0] |
411 | smooth_iterations = const.SURFACE_QUALITY[quality][1] | 391 | smooth_iterations = const.SURFACE_QUALITY[quality][1] |
@@ -429,13 +409,6 @@ class SurfaceManager(): | @@ -429,13 +409,6 @@ class SurfaceManager(): | ||
429 | UpdateProgress = vu.ShowProgress(pipeline_size) | 409 | UpdateProgress = vu.ShowProgress(pipeline_size) |
430 | UpdateProgress(0, _("Generating 3D surface...")) | 410 | UpdateProgress(0, _("Generating 3D surface...")) |
431 | 411 | ||
432 | - #filename_img = tempfile.mktemp() | ||
433 | - | ||
434 | - #writer = vtk.vtkXMLImageDataWriter() | ||
435 | - #writer.SetFileName(filename_img) | ||
436 | - #writer.SetInput(imagedata) | ||
437 | - #writer.Write() | ||
438 | - | ||
439 | language = ses.Session().language | 412 | language = ses.Session().language |
440 | 413 | ||
441 | overwrite = 0 | 414 | overwrite = 0 |
@@ -487,7 +460,6 @@ class SurfaceManager(): | @@ -487,7 +460,6 @@ class SurfaceManager(): | ||
487 | if none_count > n_pieces: | 460 | if none_count > n_pieces: |
488 | break | 461 | break |
489 | 462 | ||
490 | - | ||
491 | polydata_append = vtk.vtkAppendPolyData() | 463 | polydata_append = vtk.vtkAppendPolyData() |
492 | t = n_pieces | 464 | t = n_pieces |
493 | while t: | 465 | while t: |
@@ -497,8 +469,8 @@ class SurfaceManager(): | @@ -497,8 +469,8 @@ class SurfaceManager(): | ||
497 | reader.SetFileName(filename_polydata) | 469 | reader.SetFileName(filename_polydata) |
498 | reader.Update() | 470 | reader.Update() |
499 | polydata_append.AddInput(reader.GetOutput()) | 471 | polydata_append.AddInput(reader.GetOutput()) |
500 | - | ||
501 | t -= 1 | 472 | t -= 1 |
473 | + | ||
502 | polydata = polydata_append.GetOutput() | 474 | polydata = polydata_append.GetOutput() |
503 | clean = vtk.vtkCleanPolyData() | 475 | clean = vtk.vtkCleanPolyData() |
504 | clean.AddObserver("ProgressEvent", lambda obj,evt: | 476 | clean.AddObserver("ProgressEvent", lambda obj,evt: |
@@ -508,7 +480,6 @@ class SurfaceManager(): | @@ -508,7 +480,6 @@ class SurfaceManager(): | ||
508 | clean.Update() | 480 | clean.Update() |
509 | polydata = clean.GetOutput() | 481 | polydata = clean.GetOutput() |
510 | 482 | ||
511 | - | ||
512 | smoother = vtk.vtkWindowedSincPolyDataFilter() | 483 | smoother = vtk.vtkWindowedSincPolyDataFilter() |
513 | smoother.AddObserver("ProgressEvent", lambda obj,evt: | 484 | smoother.AddObserver("ProgressEvent", lambda obj,evt: |
514 | UpdateProgress(obj, _("Generating 3D surface..."))) | 485 | UpdateProgress(obj, _("Generating 3D surface..."))) |
@@ -531,7 +502,6 @@ class SurfaceManager(): | @@ -531,7 +502,6 @@ class SurfaceManager(): | ||
531 | UpdateProgress(obj, _("Generating 3D surface..."))) | 502 | UpdateProgress(obj, _("Generating 3D surface..."))) |
532 | polydata = conn.GetOutput() | 503 | polydata = conn.GetOutput() |
533 | 504 | ||
534 | - | ||
535 | # Filter used to detect and fill holes. Only fill boundary edges holes. | 505 | # Filter used to detect and fill holes. Only fill boundary edges holes. |
536 | #TODO: Hey! This piece of code is the same from | 506 | #TODO: Hey! This piece of code is the same from |
537 | # polydata_utils.FillSurfaceHole, we need to review this. | 507 | # polydata_utils.FillSurfaceHole, we need to review this. |
@@ -588,23 +558,7 @@ class SurfaceManager(): | @@ -588,23 +558,7 @@ class SurfaceManager(): | ||
588 | interpolation = int(ses.Session().surface_interpolation) | 558 | interpolation = int(ses.Session().surface_interpolation) |
589 | 559 | ||
590 | prop.SetInterpolation(interpolation) | 560 | prop.SetInterpolation(interpolation) |
591 | - #prop.SetInterpolationToPhong() | ||
592 | - | ||
593 | - # Remove temporary files | ||
594 | - #if sys.platform == "win32": | ||
595 | - # try: | ||
596 | - # os.remove(filename_img) | ||
597 | - # os.remove(filename_polydata) | ||
598 | - # except (WindowsError): | ||
599 | - # print "Error while removing surface temporary file" | ||
600 | - #else: # sys.platform == "linux2" or sys.platform == "darwin" | ||
601 | - # try: | ||
602 | - # os.remove(filename_img) | ||
603 | - # os.remove(filename_polydata) | ||
604 | - # except (OSError): | ||
605 | - # print "Error while removing surface temporary file" | ||
606 | 561 | ||
607 | - # Append surface into Project.surface_dict | ||
608 | proj = prj.Project() | 562 | proj = prj.Project() |
609 | if overwrite: | 563 | if overwrite: |
610 | proj.ChangeSurface(surface) | 564 | proj.ChangeSurface(surface) |
@@ -613,14 +567,12 @@ class SurfaceManager(): | @@ -613,14 +567,12 @@ class SurfaceManager(): | ||
613 | surface.index = index | 567 | surface.index = index |
614 | self.last_surface_index = index | 568 | self.last_surface_index = index |
615 | 569 | ||
616 | - | ||
617 | session = ses.Session() | 570 | session = ses.Session() |
618 | session.ChangeProject() | 571 | session.ChangeProject() |
619 | 572 | ||
620 | - | ||
621 | # The following lines have to be here, otherwise all volumes disappear | 573 | # The following lines have to be here, otherwise all volumes disappear |
622 | measured_polydata = vtk.vtkMassProperties() | 574 | measured_polydata = vtk.vtkMassProperties() |
623 | - measured_polydata.SetInput(polydata) | 575 | + measured_polydata.SetInput(smoother.GetOutput()) |
624 | volume = measured_polydata.GetVolume() | 576 | volume = measured_polydata.GetVolume() |
625 | surface.volume = volume | 577 | surface.volume = volume |
626 | self.last_surface_index = surface.index | 578 | self.last_surface_index = surface.index |
@@ -639,7 +591,6 @@ class SurfaceManager(): | @@ -639,7 +591,6 @@ class SurfaceManager(): | ||
639 | (surface.index, surface.name, | 591 | (surface.index, surface.name, |
640 | surface.colour, surface.volume, | 592 | surface.colour, surface.volume, |
641 | surface.transparency)) | 593 | surface.transparency)) |
642 | - | ||
643 | 594 | ||
644 | #When you finalize the progress. The bar is cleaned. | 595 | #When you finalize the progress. The bar is cleaned. |
645 | UpdateProgress = vu.ShowProgress(1) | 596 | UpdateProgress = vu.ShowProgress(1) |
@@ -649,7 +600,6 @@ class SurfaceManager(): | @@ -649,7 +600,6 @@ class SurfaceManager(): | ||
649 | 600 | ||
650 | ps.Publisher().sendMessage('End busy cursor') | 601 | ps.Publisher().sendMessage('End busy cursor') |
651 | 602 | ||
652 | - | ||
653 | def UpdateSurfaceInterpolation(self, pub_evt): | 603 | def UpdateSurfaceInterpolation(self, pub_evt): |
654 | interpolation = int(ses.Session().surface_interpolation) | 604 | interpolation = int(ses.Session().surface_interpolation) |
655 | key_actors = self.actors_dict.keys() | 605 | key_actors = self.actors_dict.keys() |
@@ -658,7 +608,6 @@ class SurfaceManager(): | @@ -658,7 +608,6 @@ class SurfaceManager(): | ||
658 | self.actors_dict[key].GetProperty().SetInterpolation(interpolation) | 608 | self.actors_dict[key].GetProperty().SetInterpolation(interpolation) |
659 | ps.Publisher().sendMessage('Render volume viewer') | 609 | ps.Publisher().sendMessage('Render volume viewer') |
660 | 610 | ||
661 | - | ||
662 | def RemoveActor(self, index): | 611 | def RemoveActor(self, index): |
663 | """ | 612 | """ |
664 | Remove actor, according to given actor index. | 613 | Remove actor, according to given actor index. |
@@ -669,7 +618,6 @@ class SurfaceManager(): | @@ -669,7 +618,6 @@ class SurfaceManager(): | ||
669 | proj = prj.Project() | 618 | proj = prj.Project() |
670 | proj.surface_dict.pop(index) | 619 | proj.surface_dict.pop(index) |
671 | 620 | ||
672 | - | ||
673 | def OnChangeSurfaceName(self, pubsub_evt): | 621 | def OnChangeSurfaceName(self, pubsub_evt): |
674 | index, name = pubsub_evt.data | 622 | index, name = pubsub_evt.data |
675 | proj = prj.Project() | 623 | proj = prj.Project() |
@@ -711,7 +659,6 @@ class SurfaceManager(): | @@ -711,7 +659,6 @@ class SurfaceManager(): | ||
711 | proj.surface_dict[index].colour = colour | 659 | proj.surface_dict[index].colour = colour |
712 | ps.Publisher().sendMessage('Render volume viewer') | 660 | ps.Publisher().sendMessage('Render volume viewer') |
713 | 661 | ||
714 | - | ||
715 | def OnExportSurface(self, pubsub_evt): | 662 | def OnExportSurface(self, pubsub_evt): |
716 | filename, filetype = pubsub_evt.data | 663 | filename, filetype = pubsub_evt.data |
717 | if (filetype == const.FILETYPE_STL) or\ | 664 | if (filetype == const.FILETYPE_STL) or\ |
@@ -737,7 +684,6 @@ class SurfaceManager(): | @@ -737,7 +684,6 @@ class SurfaceManager(): | ||
737 | else: | 684 | else: |
738 | polydata = pu.Merge(polydata_list) | 685 | polydata = pu.Merge(polydata_list) |
739 | 686 | ||
740 | - | ||
741 | # Having a polydata that represents all surfaces | 687 | # Having a polydata that represents all surfaces |
742 | # selected, we write it, according to filetype | 688 | # selected, we write it, according to filetype |
743 | if filetype == const.FILETYPE_STL: | 689 | if filetype == const.FILETYPE_STL: |