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