Commit e82c89cee51c88e21339c9f6b6b537b7a4d97263
1 parent
e7bc240b
Exists in
command-line
No-gui doing less work when creating surface
Showing
3 changed files
with
117 additions
and
101 deletions
Show diff stats
app.py
| ... | ... | @@ -361,7 +361,6 @@ def export(path_, threshold_range): |
| 361 | 361 | } |
| 362 | 362 | Publisher.sendMessage('Create surface from index', surface_options) |
| 363 | 363 | Publisher.sendMessage('Export surface to file', (path_, const.FILETYPE_STL)) |
| 364 | - Publisher.sendMessage('Remove surfaces', [0]) | |
| 365 | 364 | |
| 366 | 365 | |
| 367 | 366 | def print_events(data): | ... | ... |
invesalius/data/slice_.py
| ... | ... | @@ -353,19 +353,19 @@ class Slice(object): |
| 353 | 353 | |
| 354 | 354 | # TODO: merge this code with apply_slice_buffer_to_mask |
| 355 | 355 | b_mask = self.buffer_slices["AXIAL"].mask |
| 356 | - if b_mask: | |
| 356 | + if b_mask is not None: | |
| 357 | 357 | n = self.buffer_slices["AXIAL"].index + 1 |
| 358 | 358 | self.current_mask.matrix[n, 1:, 1:] = b_mask |
| 359 | 359 | self.current_mask.matrix[n, 0, 0] = 1 |
| 360 | 360 | |
| 361 | 361 | b_mask = self.buffer_slices["CORONAL"].mask |
| 362 | - if b_mask: | |
| 362 | + if b_mask is not None: | |
| 363 | 363 | n = self.buffer_slices["CORONAL"].index + 1 |
| 364 | 364 | self.current_mask.matrix[1:, n, 1:] = b_mask |
| 365 | 365 | self.current_mask.matrix[0, n, 0] = 1 |
| 366 | 366 | |
| 367 | 367 | b_mask = self.buffer_slices["SAGITAL"].mask |
| 368 | - if b_mask: | |
| 368 | + if b_mask is not None: | |
| 369 | 369 | n = self.buffer_slices["SAGITAL"].index + 1 |
| 370 | 370 | self.current_mask.matrix[1:, 1:, n] = b_mask |
| 371 | 371 | self.current_mask.matrix[0, 0, n] = 1 |
| ... | ... | @@ -885,7 +885,7 @@ class Slice(object): |
| 885 | 885 | self.current_mask.matrix[n+1, 1:, 1:] = m |
| 886 | 886 | else: |
| 887 | 887 | slice_ = self.buffer_slices[orientation].image |
| 888 | - if slice_: | |
| 888 | + if slice_ is not None: | |
| 889 | 889 | self.buffer_slices[orientation].mask = (255 * ((slice_ >= thresh_min) & (slice_ <= thresh_max))).astype('uint8') |
| 890 | 890 | |
| 891 | 891 | # Update viewer | ... | ... |
invesalius/data/surface.py
| ... | ... | @@ -661,7 +661,6 @@ class SurfaceManager(): |
| 661 | 661 | # polydata.SetSource(None) |
| 662 | 662 | del decimation |
| 663 | 663 | |
| 664 | - to_measure = polydata | |
| 665 | 664 | #to_measure.Register(None) |
| 666 | 665 | # to_measure.SetSource(None) |
| 667 | 666 | |
| ... | ... | @@ -700,115 +699,133 @@ class SurfaceManager(): |
| 700 | 699 | # polydata.DebugOn() |
| 701 | 700 | del filled_polydata |
| 702 | 701 | |
| 703 | - normals = vtk.vtkPolyDataNormals() | |
| 704 | - # normals.ReleaseDataFlagOn() | |
| 705 | - normals_ref = weakref.ref(normals) | |
| 706 | - normals_ref().AddObserver("ProgressEvent", lambda obj,evt: | |
| 707 | - UpdateProgress(normals_ref(), _("Creating 3D surface..."))) | |
| 708 | - normals.SetInputData(polydata) | |
| 709 | - normals.SetFeatureAngle(80) | |
| 710 | - normals.AutoOrientNormalsOn() | |
| 711 | - # normals.GetOutput().ReleaseDataFlagOn() | |
| 712 | - normals.Update() | |
| 713 | - del polydata | |
| 714 | - polydata = normals.GetOutput() | |
| 715 | - #polydata.Register(None) | |
| 716 | - # polydata.SetSource(None) | |
| 717 | - del normals | |
| 718 | - | |
| 719 | - # Improve performance | |
| 720 | - stripper = vtk.vtkStripper() | |
| 721 | - # stripper.ReleaseDataFlagOn() | |
| 722 | - stripper_ref = weakref.ref(stripper) | |
| 723 | - stripper_ref().AddObserver("ProgressEvent", lambda obj,evt: | |
| 724 | - UpdateProgress(stripper_ref(), _("Creating 3D surface..."))) | |
| 725 | - stripper.SetInputData(polydata) | |
| 726 | - stripper.PassThroughCellIdsOn() | |
| 727 | - stripper.PassThroughPointIdsOn() | |
| 728 | - # stripper.GetOutput().ReleaseDataFlagOn() | |
| 729 | - stripper.Update() | |
| 730 | - del polydata | |
| 731 | - polydata = stripper.GetOutput() | |
| 732 | - #polydata.Register(None) | |
| 733 | - # polydata.SetSource(None) | |
| 734 | - del stripper | |
| 702 | + to_measure = polydata | |
| 735 | 703 | |
| 736 | - # Map polygonal data (vtkPolyData) to graphics primitives. | |
| 737 | - mapper = vtk.vtkPolyDataMapper() | |
| 738 | - mapper.SetInputData(polydata) | |
| 739 | - mapper.ScalarVisibilityOff() | |
| 740 | - # mapper.ReleaseDataFlagOn() | |
| 741 | - mapper.ImmediateModeRenderingOn() # improve performance | |
| 704 | + # If InVesalius is running without GUI | |
| 705 | + if wx.GetApp() is None: | |
| 706 | + proj = prj.Project() | |
| 707 | + #Create Surface instance | |
| 708 | + if overwrite: | |
| 709 | + surface = Surface(index = self.last_surface_index) | |
| 710 | + proj.ChangeSurface(surface) | |
| 711 | + else: | |
| 712 | + surface = Surface(name=surface_name) | |
| 713 | + index = proj.AddSurface(surface) | |
| 714 | + surface.index = index | |
| 715 | + self.last_surface_index = index | |
| 716 | + surface.colour = colour | |
| 717 | + surface.polydata = polydata | |
| 742 | 718 | |
| 743 | - # Represent an object (geometry & properties) in the rendered scene | |
| 744 | - actor = vtk.vtkActor() | |
| 745 | - actor.SetMapper(mapper) | |
| 746 | - del mapper | |
| 747 | - #Create Surface instance | |
| 748 | - if overwrite: | |
| 749 | - surface = Surface(index = self.last_surface_index) | |
| 719 | + # With GUI | |
| 750 | 720 | else: |
| 751 | - surface = Surface(name=surface_name) | |
| 752 | - surface.colour = colour | |
| 753 | - surface.polydata = polydata | |
| 754 | - del polydata | |
| 721 | + normals = vtk.vtkPolyDataNormals() | |
| 722 | + # normals.ReleaseDataFlagOn() | |
| 723 | + normals_ref = weakref.ref(normals) | |
| 724 | + normals_ref().AddObserver("ProgressEvent", lambda obj,evt: | |
| 725 | + UpdateProgress(normals_ref(), _("Creating 3D surface..."))) | |
| 726 | + normals.SetInputData(polydata) | |
| 727 | + normals.SetFeatureAngle(80) | |
| 728 | + normals.AutoOrientNormalsOn() | |
| 729 | + # normals.GetOutput().ReleaseDataFlagOn() | |
| 730 | + normals.Update() | |
| 731 | + del polydata | |
| 732 | + polydata = normals.GetOutput() | |
| 733 | + #polydata.Register(None) | |
| 734 | + # polydata.SetSource(None) | |
| 735 | + del normals | |
| 755 | 736 | |
| 756 | - # Set actor colour and transparency | |
| 757 | - actor.GetProperty().SetColor(colour) | |
| 758 | - actor.GetProperty().SetOpacity(1-surface.transparency) | |
| 737 | + # Improve performance | |
| 738 | + stripper = vtk.vtkStripper() | |
| 739 | + # stripper.ReleaseDataFlagOn() | |
| 740 | + stripper_ref = weakref.ref(stripper) | |
| 741 | + stripper_ref().AddObserver("ProgressEvent", lambda obj,evt: | |
| 742 | + UpdateProgress(stripper_ref(), _("Creating 3D surface..."))) | |
| 743 | + stripper.SetInputData(polydata) | |
| 744 | + stripper.PassThroughCellIdsOn() | |
| 745 | + stripper.PassThroughPointIdsOn() | |
| 746 | + # stripper.GetOutput().ReleaseDataFlagOn() | |
| 747 | + stripper.Update() | |
| 748 | + del polydata | |
| 749 | + polydata = stripper.GetOutput() | |
| 750 | + #polydata.Register(None) | |
| 751 | + # polydata.SetSource(None) | |
| 752 | + del stripper | |
| 759 | 753 | |
| 760 | - prop = actor.GetProperty() | |
| 754 | + # Map polygonal data (vtkPolyData) to graphics primitives. | |
| 755 | + mapper = vtk.vtkPolyDataMapper() | |
| 756 | + mapper.SetInputData(polydata) | |
| 757 | + mapper.ScalarVisibilityOff() | |
| 758 | + # mapper.ReleaseDataFlagOn() | |
| 759 | + mapper.ImmediateModeRenderingOn() # improve performance | |
| 761 | 760 | |
| 762 | - interpolation = int(ses.Session().surface_interpolation) | |
| 761 | + # Represent an object (geometry & properties) in the rendered scene | |
| 762 | + actor = vtk.vtkActor() | |
| 763 | + actor.SetMapper(mapper) | |
| 764 | + del mapper | |
| 765 | + #Create Surface instance | |
| 766 | + if overwrite: | |
| 767 | + surface = Surface(index = self.last_surface_index) | |
| 768 | + else: | |
| 769 | + surface = Surface(name=surface_name) | |
| 770 | + surface.colour = colour | |
| 771 | + surface.polydata = polydata | |
| 772 | + del polydata | |
| 763 | 773 | |
| 764 | - prop.SetInterpolation(interpolation) | |
| 774 | + # Set actor colour and transparency | |
| 775 | + actor.GetProperty().SetColor(colour) | |
| 776 | + actor.GetProperty().SetOpacity(1-surface.transparency) | |
| 765 | 777 | |
| 766 | - proj = prj.Project() | |
| 767 | - if overwrite: | |
| 768 | - proj.ChangeSurface(surface) | |
| 769 | - else: | |
| 770 | - index = proj.AddSurface(surface) | |
| 771 | - surface.index = index | |
| 772 | - self.last_surface_index = index | |
| 778 | + prop = actor.GetProperty() | |
| 773 | 779 | |
| 774 | - session = ses.Session() | |
| 775 | - session.ChangeProject() | |
| 780 | + interpolation = int(ses.Session().surface_interpolation) | |
| 776 | 781 | |
| 777 | - # The following lines have to be here, otherwise all volumes disappear | |
| 778 | - measured_polydata = vtk.vtkMassProperties() | |
| 779 | - # measured_polydata.ReleaseDataFlagOn() | |
| 780 | - measured_polydata.SetInputData(to_measure) | |
| 781 | - volume = float(measured_polydata.GetVolume()) | |
| 782 | - area = float(measured_polydata.GetSurfaceArea()) | |
| 783 | - surface.volume = volume | |
| 784 | - surface.area = area | |
| 785 | - self.last_surface_index = surface.index | |
| 786 | - del measured_polydata | |
| 787 | - del to_measure | |
| 782 | + prop.SetInterpolation(interpolation) | |
| 788 | 783 | |
| 789 | - Publisher.sendMessage('Load surface actor into viewer', actor) | |
| 784 | + proj = prj.Project() | |
| 785 | + if overwrite: | |
| 786 | + proj.ChangeSurface(surface) | |
| 787 | + else: | |
| 788 | + index = proj.AddSurface(surface) | |
| 789 | + surface.index = index | |
| 790 | + self.last_surface_index = index | |
| 790 | 791 | |
| 791 | - # Send actor by pubsub to viewer's render | |
| 792 | - if overwrite and self.actors_dict.keys(): | |
| 793 | - old_actor = self.actors_dict[self.last_surface_index] | |
| 794 | - Publisher.sendMessage('Remove surface actor from viewer', old_actor) | |
| 792 | + session = ses.Session() | |
| 793 | + session.ChangeProject() | |
| 795 | 794 | |
| 796 | - # Save actor for future management tasks | |
| 797 | - self.actors_dict[surface.index] = actor | |
| 795 | + measured_polydata = vtk.vtkMassProperties() | |
| 796 | + # measured_polydata.ReleaseDataFlagOn() | |
| 797 | + measured_polydata.SetInputData(to_measure) | |
| 798 | + volume = float(measured_polydata.GetVolume()) | |
| 799 | + area = float(measured_polydata.GetSurfaceArea()) | |
| 800 | + surface.volume = volume | |
| 801 | + surface.area = area | |
| 802 | + self.last_surface_index = surface.index | |
| 803 | + del measured_polydata | |
| 804 | + del to_measure | |
| 798 | 805 | |
| 799 | - Publisher.sendMessage('Update surface info in GUI', | |
| 800 | - (surface.index, surface.name, | |
| 801 | - surface.colour, surface.volume, | |
| 802 | - surface.area, | |
| 803 | - surface.transparency)) | |
| 804 | - | |
| 805 | - #When you finalize the progress. The bar is cleaned. | |
| 806 | - UpdateProgress = vu.ShowProgress(1) | |
| 807 | - UpdateProgress(0, _("Ready")) | |
| 808 | - Publisher.sendMessage('Update status text in GUI', _("Ready")) | |
| 809 | - | |
| 810 | - Publisher.sendMessage('End busy cursor') | |
| 811 | - del actor | |
| 806 | + Publisher.sendMessage('Load surface actor into viewer', actor) | |
| 807 | + | |
| 808 | + # Send actor by pubsub to viewer's render | |
| 809 | + if overwrite and self.actors_dict.keys(): | |
| 810 | + old_actor = self.actors_dict[self.last_surface_index] | |
| 811 | + Publisher.sendMessage('Remove surface actor from viewer', old_actor) | |
| 812 | + | |
| 813 | + # Save actor for future management tasks | |
| 814 | + self.actors_dict[surface.index] = actor | |
| 815 | + | |
| 816 | + Publisher.sendMessage('Update surface info in GUI', | |
| 817 | + (surface.index, surface.name, | |
| 818 | + surface.colour, surface.volume, | |
| 819 | + surface.area, | |
| 820 | + surface.transparency)) | |
| 821 | + | |
| 822 | + #When you finalize the progress. The bar is cleaned. | |
| 823 | + UpdateProgress = vu.ShowProgress(1) | |
| 824 | + UpdateProgress(0, _("Ready")) | |
| 825 | + Publisher.sendMessage('Update status text in GUI', _("Ready")) | |
| 826 | + | |
| 827 | + Publisher.sendMessage('End busy cursor') | |
| 828 | + del actor | |
| 812 | 829 | |
| 813 | 830 | def UpdateSurfaceInterpolation(self, pub_evt): |
| 814 | 831 | interpolation = int(ses.Session().surface_interpolation) | ... | ... |