Commit 8057fbeddc02d5811e2f56c01f1b278ca7c23d22
1 parent
7040d74d
Exists in
master
and in
68 other branches
EHN: Surface GUI, select surface from combo working
Showing
3 changed files
with
49 additions
and
51 deletions
Show diff stats
invesalius/data/surface.py
| ... | ... | @@ -45,6 +45,7 @@ class Surface(): |
| 45 | 45 | self.index = Surface.general_index |
| 46 | 46 | else: |
| 47 | 47 | self.index = index |
| 48 | + Surface.general_index -= 1 | |
| 48 | 49 | self.polydata = '' |
| 49 | 50 | self.colour = '' |
| 50 | 51 | self.transparency = const.SURFACE_TRANSPARENCY |
| ... | ... | @@ -113,6 +114,7 @@ class SurfaceManager(): |
| 113 | 114 | ps.Publisher().subscribe(self.OnExportSurface,'Export surface to file') |
| 114 | 115 | ps.Publisher().subscribe(self.OnLoadSurfaceDict, 'Load surface dict') |
| 115 | 116 | ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') |
| 117 | + ps.Publisher().subscribe(self.OnSelectSurface, 'Change surface selected') | |
| 116 | 118 | |
| 117 | 119 | def OnCloseProject(self, pubsub_evt): |
| 118 | 120 | self.CloseProject() |
| ... | ... | @@ -121,47 +123,28 @@ class SurfaceManager(): |
| 121 | 123 | del self.actors_dict |
| 122 | 124 | self.actors_dict = {} |
| 123 | 125 | |
| 126 | + def OnSelectSurface(self, pubsub_evt): | |
| 127 | + index = pubsub_evt.data | |
| 128 | + #self.last_surface_index = index | |
| 129 | + # self.actors_dict. | |
| 130 | + proj = prj.Project() | |
| 131 | + surface = proj.surface_dict[index] | |
| 132 | + | |
| 133 | + ps.Publisher().sendMessage('Update surface info in GUI', | |
| 134 | + (surface.index, surface.name, | |
| 135 | + surface.colour, surface.volume, | |
| 136 | + surface.transparency)) | |
| 137 | + self.last_surface_index = index | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 124 | 141 | |
| 125 | 142 | def OnLoadSurfaceDict(self, pubsub_evt): |
| 126 | 143 | surface_dict = pubsub_evt.data |
| 144 | + #self.actors_dict[surface.index] | |
| 127 | 145 | |
| 128 | 146 | for key in surface_dict: |
| 129 | 147 | surface = surface_dict[key] |
| 130 | - # Map polygonal data (vtkPolyData) to graphics primitives. | |
| 131 | - | |
| 132 | - normals = vtk.vtkPolyDataNormals() | |
| 133 | - normals.SetInput(surface.polydata) | |
| 134 | - normals.SetFeatureAngle(80) | |
| 135 | - normals.AutoOrientNormalsOn() | |
| 136 | - normals.GetOutput().ReleaseDataFlagOn() | |
| 137 | - | |
| 138 | - stripper = vtk.vtkStripper() | |
| 139 | - stripper.SetInput(normals.GetOutput()) | |
| 140 | - stripper.PassThroughCellIdsOn() | |
| 141 | - stripper.PassThroughPointIdsOn() | |
| 142 | - | |
| 143 | - mapper = vtk.vtkPolyDataMapper() | |
| 144 | - mapper.SetInput(stripper.GetOutput()) | |
| 145 | - mapper.ScalarVisibilityOff() | |
| 146 | - | |
| 147 | - # Represent an object (geometry & properties) in the rendered scene | |
| 148 | - actor = vtk.vtkActor() | |
| 149 | - actor.SetMapper(mapper) | |
| 150 | - | |
| 151 | - # Set actor colour and transparency | |
| 152 | - actor.GetProperty().SetColor(surface.colour) | |
| 153 | - actor.GetProperty().SetOpacity(1-surface.transparency) | |
| 154 | - | |
| 155 | - self.actors_dict[surface.index] = actor | |
| 156 | - | |
| 157 | - | |
| 158 | - # Send actor by pubsub to viewer's render | |
| 159 | - ps.Publisher().sendMessage('Load surface actor into viewer', (actor)) | |
| 160 | - | |
| 161 | - ps.Publisher().sendMessage('Update status text in GUI', | |
| 162 | - _("Ready")) | |
| 163 | - | |
| 164 | - # The following lines have to be here, otherwise all volumes disappear | |
| 165 | 148 | |
| 166 | 149 | ps.Publisher().sendMessage('Update surface info in GUI', |
| 167 | 150 | (surface.index, surface.name, |
| ... | ... | @@ -280,15 +263,12 @@ class SurfaceManager(): |
| 280 | 263 | os.remove(filename_polydata) |
| 281 | 264 | except (WindowsError): |
| 282 | 265 | print "Error while removing surface temporary file" |
| 283 | - elif sys.platform == 'linux2': | |
| 266 | + else: # sys.platform == "linux2" or sys.platform == "darwin" | |
| 284 | 267 | try: |
| 285 | 268 | os.remove(filename_img) |
| 286 | 269 | os.remove(filename_polydata) |
| 287 | 270 | except (OSError): |
| 288 | 271 | print "Error while removing surface temporary file" |
| 289 | - else: | |
| 290 | - os.remove(filename_img) | |
| 291 | - os.remove(filename_polydata) | |
| 292 | 272 | |
| 293 | 273 | # Append surface into Project.surface_dict |
| 294 | 274 | proj = prj.Project() | ... | ... |
invesalius/gui/dialogs.py
| ... | ... | @@ -29,6 +29,7 @@ import wx.lib.pubsub as ps |
| 29 | 29 | import project |
| 30 | 30 | import session as ses |
| 31 | 31 | |
| 32 | + | |
| 32 | 33 | class NumberDialog(wx.Dialog): |
| 33 | 34 | def __init__(self, message, value=0): |
| 34 | 35 | pre = wx.PreDialog() |
| ... | ... | @@ -385,11 +386,13 @@ def ShowSavePresetDialog(default_filename="raycasting"): |
| 385 | 386 | |
| 386 | 387 | return filename |
| 387 | 388 | |
| 388 | - | |
| 389 | +MASK_LIST = [] | |
| 389 | 390 | class NewSurfaceDialog(wx.Dialog): |
| 390 | 391 | def __init__(self, parent, ID, title, size=wx.DefaultSize, |
| 391 | 392 | pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE, |
| 392 | 393 | useMetal=False): |
| 394 | + import data.surface as surface | |
| 395 | + import constants as const | |
| 393 | 396 | |
| 394 | 397 | # Instead of calling wx.Dialog.__init__ we precreate the dialog |
| 395 | 398 | # so we can set an extra style that must be set before |
| ... | ... | @@ -429,7 +432,9 @@ class NewSurfaceDialog(wx.Dialog): |
| 429 | 432 | |
| 430 | 433 | text = wx.TextCtrl(self, -1, "", size=(80,-1)) |
| 431 | 434 | text.SetHelpText(_("Name of the new surface to be created")) |
| 432 | - text.SetValue(_("Surface")) | |
| 435 | + | |
| 436 | + default_name = const.SURFACE_NAME_PATTERN %(surface.Surface.general_index+2) | |
| 437 | + text.SetValue(default_name) | |
| 433 | 438 | self.text = text |
| 434 | 439 | |
| 435 | 440 | sizer = wx.BoxSizer(wx.VERTICAL) | ... | ... |
invesalius/gui/task_surface.py
| ... | ... | @@ -26,10 +26,9 @@ import wx.lib.pubsub as ps |
| 26 | 26 | import gui.dialogs as dlg |
| 27 | 27 | import gui.widgets.foldpanelbar as fpb |
| 28 | 28 | import gui.widgets.colourselect as csel |
| 29 | +import utils as utl | |
| 29 | 30 | |
| 30 | 31 | #INTERPOLATION_MODE_LIST = ["Cubic", "Linear", "NearestNeighbor"] |
| 31 | -SURFACE_LIST = [] | |
| 32 | -MASK_LIST = [] | |
| 33 | 32 | MIN_TRANSPARENCY = 0 |
| 34 | 33 | MAX_TRANSPARENCY = 100 |
| 35 | 34 | |
| ... | ... | @@ -128,10 +127,11 @@ class InnerTaskPanel(wx.Panel): |
| 128 | 127 | evt.Skip() |
| 129 | 128 | |
| 130 | 129 | def OnLinkNewSurface(self, evt=None): |
| 131 | - dlg = dlg.NewSurfaceDialog(self, -1, _('InVesalius 3 - New surface')) | |
| 132 | - if dlg.ShowModal() == wx.ID_OK: | |
| 133 | - print "TODO: Send Signal - Create 3d surface %s \n" % dlg.GetValue() | |
| 134 | - dlg.Destroy() | |
| 130 | + #import gui.dialogs as dlg | |
| 131 | + dialog = dlg.NewSurfaceDialog(self, -1, _('InVesalius 3 - New surface')) | |
| 132 | + if dialog.ShowModal() == wx.ID_OK: | |
| 133 | + print "TODO: Send Signal - Create 3d surface %s \n" % dialog.GetValue() | |
| 134 | + dialog.Destroy() | |
| 135 | 135 | if evt: |
| 136 | 136 | evt.Skip() |
| 137 | 137 | |
| ... | ... | @@ -211,10 +211,12 @@ class SurfaceProperties(wx.Panel): |
| 211 | 211 | default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR) |
| 212 | 212 | self.SetBackgroundColour(default_colour) |
| 213 | 213 | |
| 214 | + self.surface_dict = utl.TwoWaysDictionary() | |
| 215 | + | |
| 214 | 216 | ## LINE 1 |
| 215 | 217 | |
| 216 | 218 | # Combo related to mask naem |
| 217 | - combo_surface_name = wx.ComboBox(self, -1, "", choices= SURFACE_LIST, | |
| 219 | + combo_surface_name = wx.ComboBox(self, -1, "", choices= self.surface_dict.keys(), | |
| 218 | 220 | style=wx.CB_DROPDOWN|wx.CB_READONLY) |
| 219 | 221 | combo_surface_name.SetSelection(0) |
| 220 | 222 | if sys.platform != 'win32': |
| ... | ... | @@ -288,20 +290,31 @@ class SurfaceProperties(wx.Panel): |
| 288 | 290 | |
| 289 | 291 | def ChangeSurfaceName(self, pubsub_evt): |
| 290 | 292 | index, name = pubsub_evt.data |
| 293 | + old_name = self.surface_dict.get_key(index) | |
| 294 | + self.surface_dict.pop(old_name, None) | |
| 295 | + self.surface_dict[name] = index | |
| 291 | 296 | self.combo_surface_name.SetString(index, name) |
| 292 | 297 | self.combo_surface_name.Refresh() |
| 293 | 298 | |
| 294 | 299 | def InsertNewSurface(self, pubsub_evt): |
| 300 | + #not_update = len(pubsub_evt.data) == 5 | |
| 301 | + index = pubsub_evt.data[0] | |
| 295 | 302 | name = pubsub_evt.data[1] |
| 296 | 303 | colour = [value*255 for value in pubsub_evt.data[2]] |
| 304 | + overwrite = name in self.surface_dict.keys() | |
| 305 | + if not overwrite or not self.surface_dict: | |
| 306 | + self.surface_dict[name] = index | |
| 307 | + index = self.combo_surface_name.Append(name) | |
| 308 | + self.combo_surface_name.SetSelection(index) | |
| 309 | + | |
| 297 | 310 | transparency = 100*pubsub_evt.data[4] |
| 298 | - index = self.combo_surface_name.Append(name) | |
| 299 | - self.combo_surface_name.SetSelection(index) | |
| 300 | 311 | self.button_colour.SetColour(colour) |
| 301 | 312 | self.slider_transparency.SetValue(transparency) |
| 302 | 313 | |
| 303 | 314 | def OnComboName(self, evt): |
| 304 | - print "TODO: Send Signal - Change 3D surface selected: %s" % (evt.GetString()) | |
| 315 | + surface_name = evt.GetString() | |
| 316 | + surface_index = evt.GetSelection() | |
| 317 | + ps.Publisher().sendMessage('Change surface selected', surface_index) | |
| 305 | 318 | |
| 306 | 319 | def OnSelectColour(self, evt): |
| 307 | 320 | colour = [value/255.0 for value in evt.GetValue()] | ... | ... |