Skip to content

Commit

Permalink
MOD: optimization motor mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
rmatsuda committed Oct 2, 2024
1 parent de57f4e commit 3f43b67
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
5 changes: 5 additions & 0 deletions invesalius/data/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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.
Expand Down
39 changes: 17 additions & 22 deletions invesalius/data/visualization/mep_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()
1 change: 1 addition & 0 deletions invesalius/gui/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3f43b67

Please sign in to comment.