From 3f43b673346c8213fbfb180cdbaf046298d6829e Mon Sep 17 00:00:00 2001 From: rmatsuda Date: Wed, 2 Oct 2024 13:57:00 +0300 Subject: [PATCH] MOD: optimization motor mapping --- invesalius/data/surface.py | 5 +++ .../data/visualization/mep_visualizer.py | 39 ++++++++----------- invesalius/gui/preferences.py | 1 + 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/invesalius/data/surface.py b/invesalius/data/surface.py index 23522e1dc..c2822e0e9 100644 --- a/invesalius/data/surface.py +++ b/invesalius/data/surface.py @@ -208,6 +208,7 @@ def __bind_events(self): Publisher.subscribe(self.OnChangeSurfaceName, "Change surface name") Publisher.subscribe(self.OnShowSurface, "Show surface") + Publisher.subscribe(self.OnHideAllSurfaces, "Hide all surfaces") Publisher.subscribe(self.OnExportSurface, "Export surface to file") Publisher.subscribe(self.OnLoadSurfaceDict, "Load surface dict") Publisher.subscribe(self.OnCloseProject, "Close project data") @@ -1130,6 +1131,10 @@ def OnChangeSurfaceName(self, index, name): def OnShowSurface(self, index, visibility): self.ShowActor(index, visibility) + def OnHideAllSurfaces(self): + for key in self.actors_dict: + self.ShowActor(key, False) + def GetBrainSurfaceActor(self, index): """ Gets the first visible surface actor. diff --git a/invesalius/data/visualization/mep_visualizer.py b/invesalius/data/visualization/mep_visualizer.py index aa25a3b8a..693d8aab4 100644 --- a/invesalius/data/visualization/mep_visualizer.py +++ b/invesalius/data/visualization/mep_visualizer.py @@ -68,9 +68,7 @@ def __init__(self): self.colorBarActor = None self.actors_dict = {} # Dictionary to store all actors created by the MEP visualizer - self.marker_storage = [] - self.first_load = True self.is_navigating = False @@ -129,19 +127,9 @@ def DisplayMotorMap(self, show: bool): return False progress_dialog = dialogs.BrainSurfaceLoadingProgressWindow() progress_dialog.Update(value=20, msg="Preparing brain surface...") - if self.colorBarActor: - Publisher.sendMessage("Remove surface actor from viewer", actor=self.colorBarActor) - Publisher.sendMessage("Remove surface actor from viewer", actor=self.surface) - self.colorBarActor = self.CreateColorbarActor() - if self.surface: # Hides the original surface - Publisher.sendMessage( - "Show single surface", - index=self.surface_index, - visibility=True, - ) - Publisher.sendMessage("Get brain surface actor", index=self.surface_index) - progress_dialog.Update(value=50, msg="Preparing brain surface...") + Publisher.sendMessage("Hide all surfaces") self.UpdateVisualization() + progress_dialog.Update(value=50, msg="Preparing brain surface...") self.UpdateMEPPoints() progress_dialog.Close() else: @@ -161,7 +149,7 @@ def DisplayMotorMap(self, show: bool): # --- Data Interpolation and Visualization --- def InterpolateData(self): - surface = self.surface + surface = self.decimate_surface points = self.points if not surface: # TODO: Show modal dialog to select a surface from project @@ -190,7 +178,7 @@ def InterpolateData(self): resample = vtkResampleWithDataSet() - polydata = surface.GetMapper().GetInput() + polydata = surface.GetOutput() resample.SetInputData(polydata) resample.SetSourceConnection(interpolator.GetOutputPort()) resample.SetPassPointArrays(1) @@ -234,7 +222,7 @@ def DecimateBrainSurface(self): # Setup the decimation filter decimate_filter = vtkDecimatePro() decimate_filter.SetInputData(triangulated_polydata) - decimate_filter.SetTargetReduction(0.8) # Reduce the number of triangles by 80% + decimate_filter.SetTargetReduction(0.6) # Reduce the number of triangles by 60% decimate_filter.PreserveTopologyOn() # Preserve the topology decimate_filter.Update() return decimate_filter @@ -243,10 +231,8 @@ def SetBrainSurface(self, actor: vtkActor, index: int): self.surface = actor self.surface_index = index self.decimate_surface = self.DecimateBrainSurface() - self.actors_dict[id(actor)] = actor self.bounds = np.array(actor.GetBounds()) - self.UpdateVisualization() - # hide the original surface if MEP is enabled + self.marker_storage = [] if self._config_params["mep_enabled"]: Publisher.sendMessage("Show surface", index=index, visibility=False) self._SaveUserParameters() @@ -380,7 +366,6 @@ def UpdateVisualization(self): self.colorBarActor = self.CreateColorbarActor() Publisher.sendMessage("AppendActor", actor=self.colored_surface_actor) - Publisher.sendMessage("AppendActor", actor=self.surface) Publisher.sendMessage("AppendActor", actor=self.point_actor) Publisher.sendMessage("AppendActor", actor=self.colorBarActor) @@ -425,7 +410,7 @@ def CreateColoredSurface(self, poly_data) -> vtkActor: """Creates the actor for the surface with color mapping.""" normals = vtkPolyDataNormals() normals.SetInputData(poly_data) - normals.ComputePointNormalsOn() + normals.ComputePointNormalsOff() normals.ComputeCellNormalsOff() normals.Update() @@ -500,4 +485,14 @@ def OnCloseProject(self): """Cleanup the visualization when the project is closed.""" self.DisplayMotorMap(False) self._config_params["mep_enabled"] = False + self.points = vtkPolyData() + self.surface = None + self.surface_index = None + self.decimate_surface = None + self.colored_surface_actor = None + self.point_actor = None + self.bounds = None + self.colorBarActor = None + self.actors_dict = {} + Publisher.sendMessage("Press motor map button", pressed=False) self._SaveUserParameters() diff --git a/invesalius/gui/preferences.py b/invesalius/gui/preferences.py index d99e9a105..d08e9422b 100644 --- a/invesalius/gui/preferences.py +++ b/invesalius/gui/preferences.py @@ -514,6 +514,7 @@ def UpdateMEPFromSession(self): self.conf = dict(self.session.GetConfig("mep_configuration")) self.spin_gaussian_radius.SetValue(self.conf.get("gaussian_radius")) self.spin_std_dev.SetValue(self.conf.get("gaussian_sharpness")) + self.spin_dims_size.SetValue(self.conf.get("dimensions_size")) self.combo_thresh.SetSelection(self.colormaps.index(self.conf.get("mep_colormap"))) partial(self.OnSelectColormap, event=None, ctrl=self.combo_thresh)