Commit 7afb7ef626eabeb825e856e13e83742f2fdf880f

Authored by Paulo Henrique Junqueira Amorim
1 parent ad70187d

ENH: Added session with volume rendering and surface interpolation option

invesalius/constants.py
@@ -504,3 +504,7 @@ STYLE_LEVEL = {SLICE_STATE_EDITOR: 1, @@ -504,3 +504,7 @@ STYLE_LEVEL = {SLICE_STATE_EDITOR: 1,
504 STATE_ZOOM_SL: 2, 504 STATE_ZOOM_SL: 2,
505 STATE_PAN:2, 505 STATE_PAN:2,
506 VOLUME_STATE_SEED:1} 506 VOLUME_STATE_SEED:1}
  507 +
  508 +#------------ Prefereces options key ------------
  509 +RENDERING = 0
  510 +SURFACE_INTERPOLATION = 1
invesalius/gui/frame.py
@@ -74,6 +74,7 @@ class Frame(wx.Frame): @@ -74,6 +74,7 @@ class Frame(wx.Frame):
74 # Create aui manager and insert content in it 74 # Create aui manager and insert content in it
75 self.__init_aui() 75 self.__init_aui()
76 76
  77 + self.preferences = preferences.Preferences(self)
77 # Initialize bind to pubsub events 78 # Initialize bind to pubsub events
78 self.__bind_events() 79 self.__bind_events()
79 self.__bind_events_wx() 80 self.__bind_events_wx()
@@ -324,9 +325,9 @@ class Frame(wx.Frame): @@ -324,9 +325,9 @@ class Frame(wx.Frame):
324 evt.Skip() 325 evt.Skip()
325 326
326 def ShowPreferences(self): 327 def ShowPreferences(self):
327 - prf = preferences.Preferences(self)  
328 - prf.ShowModal()  
329 - #print "Show Preferences" 328 + if self.preferences.ShowModal():
  329 + self.preferences.GetPreferences()
  330 + self.preferences.Close()
330 331
331 def ShowAbout(self): 332 def ShowAbout(self):
332 """ 333 """
invesalius/gui/preferences.py
1 import wx 1 import wx
  2 +import constants as const
2 3
3 ID = wx.NewId() 4 ID = wx.NewId()
4 5
@@ -10,7 +11,7 @@ except ImportError: # if it's not there locally, try the wxPython lib. @@ -10,7 +11,7 @@ except ImportError: # if it's not there locally, try the wxPython lib.
10 11
11 class Preferences(wx.Dialog): 12 class Preferences(wx.Dialog):
12 13
13 - def __init__( self, parent, id = ID, title = "Preferences", size=wx.DefaultSize,\ 14 + def __init__( self, parent, id = ID, title = _("Preferences"), size=wx.DefaultSize,\
14 pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE): 15 pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE):
15 16
16 pre = wx.PreDialog() 17 pre = wx.PreDialog()
@@ -25,21 +26,21 @@ class Preferences(wx.Dialog): @@ -25,21 +26,21 @@ class Preferences(wx.Dialog):
25 self.book = fnb.FlatNotebook(self, wx.ID_ANY, agwStyle=bookStyle) 26 self.book = fnb.FlatNotebook(self, wx.ID_ANY, agwStyle=bookStyle)
26 sizer.Add(self.book, 80, wx.EXPAND|wx.ALL) 27 sizer.Add(self.book, 80, wx.EXPAND|wx.ALL)
27 28
28 - self.pnl_volume_rendering = Viewer3D(self) 29 + self.pnl_viewer3d = Viewer3D(self)
29 self.pnl_language = Language(self) 30 self.pnl_language = Language(self)
30 31
31 - self.book.AddPage(self.pnl_volume_rendering, "Visualization")  
32 - self.book.AddPage(self.pnl_language, "Language") 32 + self.book.AddPage(self.pnl_viewer3d, _("Visualization"))
  33 + self.book.AddPage(self.pnl_language, _("Language"))
33 34
34 line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL) 35 line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
35 sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5) 36 sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5)
36 37
37 btnsizer = wx.StdDialogButtonSizer() 38 btnsizer = wx.StdDialogButtonSizer()
38 39
39 - btn = wx.Button(self, wx.ID_OK, "Apply") 40 + btn = wx.Button(self, wx.ID_OK)
40 btnsizer.AddButton(btn) 41 btnsizer.AddButton(btn)
41 42
42 - btn = wx.Button(self, wx.ID_CANCEL, "Cancel") 43 + btn = wx.Button(self, wx.ID_CANCEL)
43 btnsizer.AddButton(btn) 44 btnsizer.AddButton(btn)
44 45
45 btnsizer.Realize() 46 btnsizer.Realize()
@@ -48,6 +49,10 @@ class Preferences(wx.Dialog): @@ -48,6 +49,10 @@ class Preferences(wx.Dialog):
48 49
49 self.SetSizer(sizer) 50 self.SetSizer(sizer)
50 sizer.Fit(self) 51 sizer.Fit(self)
  52 +
  53 + def GetPreferences(self):
  54 +
  55 + print ">>>>>>>>>", self.pnl_viewer3d.GetSelection()
51 56
52 57
53 58
@@ -58,28 +63,27 @@ class Viewer3D(wx.Panel): @@ -58,28 +63,27 @@ class Viewer3D(wx.Panel):
58 wx.Panel.__init__(self, parent, size = wx.Size(800,600)) 63 wx.Panel.__init__(self, parent, size = wx.Size(800,600))
59 64
60 65
61 - box_visualization = wx.StaticBox(self, -1, "Surface") 66 + box_visualization = wx.StaticBox(self, -1, _("Surface"))
62 bsizer = wx.StaticBoxSizer(box_visualization, wx.VERTICAL) 67 bsizer = wx.StaticBoxSizer(box_visualization, wx.VERTICAL)
63 68
64 - lbl_inter = wx.StaticText(self, -1, "Interpolation ") 69 + lbl_inter = wx.StaticText(self, -1, _("Interpolation "))
65 bsizer.Add(lbl_inter, 0, wx.TOP|wx.LEFT, 10) 70 bsizer.Add(lbl_inter, 0, wx.TOP|wx.LEFT, 10)
66 71
67 - rb_inter = wx.RadioBox(self, -1, "", wx.DefaultPosition, wx.DefaultSize, 72 + rb_inter = self.rb_inter = wx.RadioBox(self, -1, "", wx.DefaultPosition, wx.DefaultSize,
68 ['Flat','Gouraud','Phong'], 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER) 73 ['Flat','Gouraud','Phong'], 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER)
69 74
70 bsizer.Add(rb_inter, 0, wx.TOP|wx.LEFT, 0) 75 bsizer.Add(rb_inter, 0, wx.TOP|wx.LEFT, 0)
71 76
72 - box_rendering = wx.StaticBox(self, -1, "Volume Rendering") 77 + box_rendering = wx.StaticBox(self, -1, _("Volume Rendering"))
73 bsizer_ren = wx.StaticBoxSizer(box_rendering, wx.VERTICAL) 78 bsizer_ren = wx.StaticBoxSizer(box_rendering, wx.VERTICAL)
74 79
75 - lbl_rendering = wx.StaticText(self, -1, "Rendering") 80 + lbl_rendering = wx.StaticText(self, -1, _("Rendering"))
76 bsizer_ren.Add(lbl_rendering, 0, wx.TOP | wx.LEFT, 10) 81 bsizer_ren.Add(lbl_rendering, 0, wx.TOP | wx.LEFT, 10)
77 82
78 - rb_rendering = wx.RadioBox(self, -1, "", wx.DefaultPosition, wx.DefaultSize, 83 + rb_rendering = self.rb_rendering = wx.RadioBox(self, -1, "", wx.DefaultPosition, wx.DefaultSize,
79 ['CPU', 'GPU (Only NVidia video card)'], 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER) 84 ['CPU', 'GPU (Only NVidia video card)'], 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER)
80 85
81 bsizer_ren.Add(rb_rendering, 0, wx.TOP | wx.LEFT, 0) 86 bsizer_ren.Add(rb_rendering, 0, wx.TOP | wx.LEFT, 0)
82 -  
83 border = wx.BoxSizer(wx.VERTICAL) 87 border = wx.BoxSizer(wx.VERTICAL)
84 border.Add(bsizer, 50, wx.EXPAND|wx.ALL, 10) 88 border.Add(bsizer, 50, wx.EXPAND|wx.ALL, 10)
85 border.Add(bsizer_ren, 50, wx.EXPAND|wx.ALL, 10) 89 border.Add(bsizer_ren, 50, wx.EXPAND|wx.ALL, 10)
@@ -87,6 +91,14 @@ class Viewer3D(wx.Panel): @@ -87,6 +91,14 @@ class Viewer3D(wx.Panel):
87 91
88 border.Fit(self) 92 border.Fit(self)
89 93
  94 +
  95 + def GetSelection(self):
  96 +
  97 + options = {const.RENDERING:self.rb_rendering.GetSelection(),
  98 + const.SURFACE_INTERPOLATION:self.rb_inter.GetSelection()}
  99 +
  100 + return options
  101 +
90 class Language(wx.Panel): 102 class Language(wx.Panel):
91 103
92 def __init__(self, parent): 104 def __init__(self, parent):
invesalius/session.py
@@ -25,7 +25,6 @@ class Session(object): @@ -25,7 +25,6 @@ class Session(object):
25 import constants as const 25 import constants as const
26 self.project_path = () 26 self.project_path = ()
27 self.debug = False 27 self.debug = False
28 -  
29 self.project_status = const.PROJ_CLOSE 28 self.project_status = const.PROJ_CLOSE
30 # const.PROJ_NEW*, const.PROJ_OPEN, const.PROJ_CHANGE*, 29 # const.PROJ_NEW*, const.PROJ_OPEN, const.PROJ_CHANGE*,
31 # const.PROJ_CLOSE 30 # const.PROJ_CLOSE
@@ -47,7 +46,8 @@ class Session(object): @@ -47,7 +46,8 @@ class Session(object):
47 # Recent projects list 46 # Recent projects list
48 self.recent_projects = [(const.SAMPLE_DIR, "Cranium.inv3")] 47 self.recent_projects = [(const.SAMPLE_DIR, "Cranium.inv3")]
49 self.last_dicom_folder = '' 48 self.last_dicom_folder = ''
50 - 49 + self.surface_interpolation = 0
  50 + self.rendering = 0
51 self.CreateSessionFile() 51 self.CreateSessionFile()
52 52
53 def StopRecording(self, pubsub_evt): 53 def StopRecording(self, pubsub_evt):
@@ -64,13 +64,13 @@ class Session(object): @@ -64,13 +64,13 @@ class Session(object):
64 homedir = self.homedir = os.path.expanduser('~') 64 homedir = self.homedir = os.path.expanduser('~')
65 try: 65 try:
66 path = os.path.join(self.homedir , 66 path = os.path.join(self.homedir ,
67 - '.invesalius', 'config.backup') 67 + '.invesalius', 'config.backup')
68 path_dst = os.path.join(self.homedir , 68 path_dst = os.path.join(self.homedir ,
69 - '.invesalius', 'config.cfg') 69 + '.invesalius', 'config.cfg')
70 shutil.copy(path, path_dst) 70 shutil.copy(path, path_dst)
71 return True 71 return True
72 except(IOError): 72 except(IOError):
73 - return False 73 + return False
74 74
75 75
76 def CloseProject(self): 76 def CloseProject(self):
@@ -132,6 +132,8 @@ class Session(object): @@ -132,6 +132,8 @@ class Session(object):
132 config.set('session', 'status', self.project_status) 132 config.set('session', 'status', self.project_status)
133 config.set('session','debug', self.debug) 133 config.set('session','debug', self.debug)
134 config.set('session', 'language', self.language) 134 config.set('session', 'language', self.language)
  135 + config.set('session', 'surface_interpolation', self.surface_interpolation)
  136 + config.set('session', 'rendering', self.rendering)
135 137
136 config.add_section('project') 138 config.add_section('project')
137 config.set('project', 'recent_projects', self.recent_projects) 139 config.set('project', 'recent_projects', self.recent_projects)
@@ -204,15 +206,19 @@ class Session(object): @@ -204,15 +206,19 @@ class Session(object):
204 self.project_status = config.get('session', 'status') 206 self.project_status = config.get('session', 'status')
205 self.debug = config.get('session','debug') 207 self.debug = config.get('session','debug')
206 self.language = config.get('session','language') 208 self.language = config.get('session','language')
  209 +
207 self.recent_projects = eval(config.get('project','recent_projects')) 210 self.recent_projects = eval(config.get('project','recent_projects'))
208 self.homedir = config.get('paths','homedir') 211 self.homedir = config.get('paths','homedir')
209 self.tempdir = config.get('paths','tempdir') 212 self.tempdir = config.get('paths','tempdir')
210 self.last_dicom_folder = config.get('paths','last_dicom_folder') 213 self.last_dicom_folder = config.get('paths','last_dicom_folder')
211 self.last_dicom_folder = self.last_dicom_folder.decode('utf-8') 214 self.last_dicom_folder = self.last_dicom_folder.decode('utf-8')
212 - return True  
213 215
214 - except(ConfigParser.NoSectionError, ConfigParser.NoOptionError,  
215 - ConfigParser.MissingSectionHeaderError, ConfigParser.ParsingError): 216 + self.surface_interpolation = config.get('session', 'surface_interpolation')
  217 + self.rendering = config.get('session', 'rendering')
  218 + #return True
  219 +
  220 + except(ConfigParser.NoSectionError, ConfigParser.MissingSectionHeaderError,
  221 + ConfigParser.ParsingError):
216 222
217 if (self.RecoveryConfigFile()): 223 if (self.RecoveryConfigFile()):
218 self.ReadSession() 224 self.ReadSession()
@@ -220,6 +226,14 @@ class Session(object): @@ -220,6 +226,14 @@ class Session(object):
220 else: 226 else:
221 return False 227 return False
222 228
  229 + except(ConfigParser.NoOptionError):
  230 + #Added to fix new version compatibility
  231 + self.surface_interpolation = 0
  232 + self.rendering = 0
  233 +
  234 + self.CreateSessionFile()
  235 + return True
  236 +
223 237
224 class WriteSession(Thread): 238 class WriteSession(Thread):
225 239
@@ -249,6 +263,8 @@ class WriteSession(Thread): @@ -249,6 +263,8 @@ class WriteSession(Thread):
249 config.set('session', 'status', self.session.project_status) 263 config.set('session', 'status', self.session.project_status)
250 config.set('session','debug', self.session.debug) 264 config.set('session','debug', self.session.debug)
251 config.set('session', 'language', self.session.language) 265 config.set('session', 'language', self.session.language)
  266 + config.set('session', 'surface_interpolation', self.session.surface_interpolation)
  267 + config.set('session', 'rendering', self.session.rendering)
252 268
253 config.add_section('project') 269 config.add_section('project')
254 config.set('project', 'recent_projects', self.session.recent_projects) 270 config.set('project', 'recent_projects', self.session.recent_projects)