Commit 1d21c8fcd975794acd327c94af6b3370393020ba

Authored by tatiana
1 parent d1fe1aa7

FIX: Last mask threshold when project is opened

invesalius/control.py
@@ -86,7 +86,6 @@ class Controller(): @@ -86,7 +86,6 @@ class Controller():
86 self.progress_dialog = dialog.ProgressDialog( 86 self.progress_dialog = dialog.ProgressDialog(
87 maximum = data[1]) 87 maximum = data[1])
88 else: 88 else:
89 - print data[0]  
90 if not(self.progress_dialog.Update(data[0],message)): 89 if not(self.progress_dialog.Update(data[0],message)):
91 self.progress_dialog.Close() 90 self.progress_dialog.Close()
92 self.progress_dialog = None 91 self.progress_dialog = None
@@ -120,9 +119,7 @@ class Controller(): @@ -120,9 +119,7 @@ class Controller():
120 119
121 if len(patients_groups): 120 if len(patients_groups):
122 group = dcm.SelectLargerDicomGroup(patients_groups) 121 group = dcm.SelectLargerDicomGroup(patients_groups)
123 - print "Group", group.GetHandSortedList()  
124 imagedata, dicom = self.OpenDicomGroup(group, gui=False) 122 imagedata, dicom = self.OpenDicomGroup(group, gui=False)
125 - print "imagedata", imagedata  
126 self.CreateDicomProject(imagedata, dicom) 123 self.CreateDicomProject(imagedata, dicom)
127 # OPTION 2: ANALYZE? 124 # OPTION 2: ANALYZE?
128 else: 125 else:
@@ -204,7 +201,6 @@ class Controller(): @@ -204,7 +201,6 @@ class Controller():
204 201
205 # Create imagedata 202 # Create imagedata
206 filelist = dicom_group.GetFilenameList() 203 filelist = dicom_group.GetFilenameList()
207 - print "filelist", filelist  
208 zspacing = dicom_group.zspacing 204 zspacing = dicom_group.zspacing
209 imagedata = utils.CreateImageData(filelist, zspacing) 205 imagedata = utils.CreateImageData(filelist, zspacing)
210 206
@@ -227,14 +223,13 @@ class Controller(): @@ -227,14 +223,13 @@ class Controller():
227 223
228 thresh_modes = proj.threshold_modes.keys() 224 thresh_modes = proj.threshold_modes.keys()
229 thresh_modes.sort() 225 thresh_modes.sort()
230 - ps.Publisher().sendMessage('Set threshold modes',  
231 - (thresh_modes,const.THRESHOLD_PRESETS_INDEX))  
232 226
233 - # Set default value into slices' default mask  
234 - key= thresh_modes[const.THRESHOLD_PRESETS_INDEX]  
235 - #value = proj.threshold_modes.get_value(key)  
236 - value = proj.threshold_modes[key]  
237 - (min_thresh, max_thresh) = value 227 + default_threshold = const.THRESHOLD_PRESETS_INDEX
  228 + if proj.mask_dict:
  229 + last = max(proj.mask_dict.keys())
  230 + default_threshold = proj.mask_dict[last].threshold_range
  231 + ps.Publisher().sendMessage('Set threshold modes',
  232 + (thresh_modes,default_threshold))
238 233
239 def LoadRaycastingPreset(self, pubsub_evt): 234 def LoadRaycastingPreset(self, pubsub_evt):
240 label = pubsub_evt.data 235 label = pubsub_evt.data
invesalius/data/slice_.py
@@ -216,6 +216,10 @@ class Slice(object): @@ -216,6 +216,10 @@ class Slice(object):
216 else: 216 else:
217 proj = Project() 217 proj = Project()
218 proj.mask_dict[index].threshold_range = threshold_range 218 proj.mask_dict[index].threshold_range = threshold_range
  219 +
  220 + proj = Project()
  221 + proj.mask_dict[self.current_mask.index ].threshold_range = threshold_range
  222 +
219 223
220 def ShowMask(self, index, value): 224 def ShowMask(self, index, value):
221 "Show a mask given its index and 'show' value (0: hide, other: show)" 225 "Show a mask given its index and 'show' value (0: hide, other: show)"
@@ -508,6 +512,8 @@ class Slice(object): @@ -508,6 +512,8 @@ class Slice(object):
508 mask = mask_dict[key] 512 mask = mask_dict[key]
509 513
510 # update gui related to mask 514 # update gui related to mask
  515 + print "__load_masks"
  516 + print 'THRESHOLD_RANGE', mask.threshold_range
511 ps.Publisher().sendMessage('Add mask', 517 ps.Publisher().sendMessage('Add mask',
512 (mask.index, 518 (mask.index,
513 mask.name, 519 mask.name,
invesalius/data/surface.py
@@ -334,7 +334,7 @@ class SurfaceManager(): @@ -334,7 +334,7 @@ class SurfaceManager():
334 334
335 def OnShowSurface(self, pubsub_evt): 335 def OnShowSurface(self, pubsub_evt):
336 index, value = pubsub_evt.data 336 index, value = pubsub_evt.data
337 - print "OnShowSurface", index, value 337 + #print "OnShowSurface", index, value
338 self.ShowActor(index, value) 338 self.ShowActor(index, value)
339 339
340 def ShowActor(self, index, value): 340 def ShowActor(self, index, value):
invesalius/data/viewer_slice.py
@@ -215,7 +215,7 @@ class Viewer(wx.Panel): @@ -215,7 +215,7 @@ class Viewer(wx.Panel):
215 self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) 215 self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))
216 216
217 def __set_mode_zoom(self, pubsub_evt): 217 def __set_mode_zoom(self, pubsub_evt):
218 - print "Zoom" 218 + #print "Zoom"
219 self.append_mode('ZOOM') 219 self.append_mode('ZOOM')
220 self.mouse_pressed = 0 220 self.mouse_pressed = 0
221 ICON_IMAGE = wx.Image(os.path.join(const.ICON_DIR, 221 ICON_IMAGE = wx.Image(os.path.join(const.ICON_DIR,
@@ -735,7 +735,7 @@ class Viewer(wx.Panel): @@ -735,7 +735,7 @@ class Viewer(wx.Panel):
735 'Set slice viewer layout') 735 'Set slice viewer layout')
736 736
737 def ChangeBrushOperation(self, pubsub_evt): 737 def ChangeBrushOperation(self, pubsub_evt):
738 - print pubsub_evt.data 738 + #print pubsub_evt.data
739 self._brush_cursor_op = pubsub_evt.data 739 self._brush_cursor_op = pubsub_evt.data
740 740
741 def __bind_events_wx(self): 741 def __bind_events_wx(self):
@@ -912,10 +912,10 @@ class Viewer(wx.Panel): @@ -912,10 +912,10 @@ class Viewer(wx.Panel):
912 extent = slice_data.actor.GetDisplayExtent() 912 extent = slice_data.actor.GetDisplayExtent()
913 cam = slice_data.renderer.GetActiveCamera() 913 cam = slice_data.renderer.GetActiveCamera()
914 914
915 - print  
916 - print self.orientation  
917 - print x, y, z  
918 - print actor_bound 915 + #print
  916 + #print self.orientation
  917 + #print x, y, z
  918 + #print actor_bound
919 #print "ViewUp", cam.GetViewUp() 919 #print "ViewUp", cam.GetViewUp()
920 #print "Position", cam.GetPosition() 920 #print "Position", cam.GetPosition()
921 #print "Orientation", cam.GetOrientation() 921 #print "Orientation", cam.GetOrientation()
@@ -923,10 +923,10 @@ class Viewer(wx.Panel): @@ -923,10 +923,10 @@ class Viewer(wx.Panel):
923 923
924 vCamera = numpy.array(cam.GetPosition()) - numpy.array(cam.GetFocalPoint()) 924 vCamera = numpy.array(cam.GetPosition()) - numpy.array(cam.GetFocalPoint())
925 n_vCamera = vCamera / numpy.linalg.norm(vCamera) 925 n_vCamera = vCamera / numpy.linalg.norm(vCamera)
926 - print "Normalized", n_vCamera 926 + #print "Normalized", n_vCamera
927 927
928 pos = [j + 0.01 * i for i,j in zip(n_vCamera, (x, y, z))] 928 pos = [j + 0.01 * i for i,j in zip(n_vCamera, (x, y, z))]
929 - print "posicao", pos 929 + #print "posicao", pos
930 930
931 #yz = [x + abs(x * 0.001), y, z] 931 #yz = [x + abs(x * 0.001), y, z]
932 #xz = [x, y - abs(y * 0.001), z] 932 #xz = [x, y - abs(y * 0.001), z]
@@ -988,10 +988,10 @@ class Viewer(wx.Panel): @@ -988,10 +988,10 @@ class Viewer(wx.Panel):
988 slice_number = slice_data.number 988 slice_number = slice_data.number
989 actor_bound = slice_data.actor.GetBounds() 989 actor_bound = slice_data.actor.GetBounds()
990 990
991 - print  
992 - print self.orientation  
993 - print x, y, z  
994 - print actor_bound 991 + #print
  992 + #print self.orientation
  993 + #print x, y, z
  994 + #print actor_bound
995 995
996 yz = [x + abs(x * 0.001), y, z] 996 yz = [x + abs(x * 0.001), y, z]
997 xz = [x, y - abs(y * 0.001), z] 997 xz = [x, y - abs(y * 0.001), z]
@@ -1107,7 +1107,7 @@ class Viewer(wx.Panel): @@ -1107,7 +1107,7 @@ class Viewer(wx.Panel):
1107 evt.Skip() 1107 evt.Skip()
1108 1108
1109 def OnScrollBarRelease(self, evt): 1109 def OnScrollBarRelease(self, evt):
1110 - print "OnScrollBarRelease" 1110 + #print "OnScrollBarRelease"
1111 self.UpdateSlice3D(self.pos) 1111 self.UpdateSlice3D(self.pos)
1112 evt.Skip() 1112 evt.Skip()
1113 1113
invesalius/gui/data_notebook.py
@@ -172,6 +172,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): @@ -172,6 +172,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin):
172 172
173 def EditMaskThreshold(self, pubsub_evt): 173 def EditMaskThreshold(self, pubsub_evt):
174 index, threshold_range = pubsub_evt.data 174 index, threshold_range = pubsub_evt.data
  175 + print "EditMaskThreshold", threshold_range
175 self.SetStringItem(index, 2, str(threshold_range)) 176 self.SetStringItem(index, 2, str(threshold_range))
176 177
177 def EditMaskColour(self, pubsub_evt): 178 def EditMaskColour(self, pubsub_evt):
invesalius/gui/task_slice.py
@@ -325,8 +325,14 @@ class MaskProperties(wx.Panel): @@ -325,8 +325,14 @@ class MaskProperties(wx.Panel):
325 def SetThresholdModes(self, pubsub_evt): 325 def SetThresholdModes(self, pubsub_evt):
326 (thresh_modes_names, default_thresh) = pubsub_evt.data 326 (thresh_modes_names, default_thresh) = pubsub_evt.data
327 self.combo_thresh.SetItems(thresh_modes_names) 327 self.combo_thresh.SetItems(thresh_modes_names)
328 - self.combo_thresh.SetSelection(default_thresh)  
329 - (thresh_min, thresh_max) = self.threshold_modes[thresh_modes_names[default_thresh]] 328 + if isinstance(default_thresh, int):
  329 + self.combo_thresh.SetSelection(default_thresh)
  330 + (thresh_min, thresh_max) =\
  331 + self.threshold_modes[thresh_modes_names[default_thresh]]
  332 + else:
  333 + self.combo_thresh.SetSelection(3)
  334 + thresh_min, thresh_max = default_thresh
  335 +
330 self.gradient.SetMinValue(thresh_min) 336 self.gradient.SetMinValue(thresh_min)
331 self.gradient.SetMaxValue(thresh_max) 337 self.gradient.SetMaxValue(thresh_max)
332 338
@@ -349,6 +355,7 @@ class MaskProperties(wx.Panel): @@ -349,6 +355,7 @@ class MaskProperties(wx.Panel):
349 def OnSlideChanged(self, evt): 355 def OnSlideChanged(self, evt):
350 thresh_min = self.gradient.GetMinValue() 356 thresh_min = self.gradient.GetMinValue()
351 thresh_max = self.gradient.GetMaxValue() 357 thresh_max = self.gradient.GetMaxValue()
  358 + print "OnSlideChanged", thresh_min, thresh_max
352 if self.bind_evt_gradient: 359 if self.bind_evt_gradient:
353 ps.Publisher().sendMessage('Set threshold values', 360 ps.Publisher().sendMessage('Set threshold values',
354 (thresh_min, thresh_max)) 361 (thresh_min, thresh_max))
invesalius/project.py
@@ -181,14 +181,14 @@ class Project(object): @@ -181,14 +181,14 @@ class Project(object):
181 def OpenPlistProject(self, filename): 181 def OpenPlistProject(self, filename):
182 filelist = Extract(filename, tempfile.gettempdir()) 182 filelist = Extract(filename, tempfile.gettempdir())
183 main_plist = min(filelist, key=lambda x: len(x)) 183 main_plist = min(filelist, key=lambda x: len(x))
184 - print main_plist 184 + #print main_plist
185 project = plistlib.readPlist(main_plist) 185 project = plistlib.readPlist(main_plist)
186 186
187 - print "antes", self.__dict__ 187 + #print "antes", self.__dict__
188 188
189 # Path were extracted project is 189 # Path were extracted project is
190 dirpath = os.path.split(filelist[0])[0] 190 dirpath = os.path.split(filelist[0])[0]
191 - print "* dirpath", dirpath 191 + #print "* dirpath", dirpath
192 192
193 for key in project: 193 for key in project:
194 if key == 'imagedata': 194 if key == 'imagedata':
@@ -220,7 +220,7 @@ class Project(object): @@ -220,7 +220,7 @@ class Project(object):
220 self.surface_dict[s.index] = s 220 self.surface_dict[s.index] = s
221 else: 221 else:
222 setattr(self, key, project[key]) 222 setattr(self, key, project[key])
223 - print "depois", self.__dict__ 223 + #print "depois", self.__dict__
224 224
225 225
226 226
@@ -233,7 +233,7 @@ def Compress(folder, filename): @@ -233,7 +233,7 @@ def Compress(folder, filename):
233 233
234 def Extract(filename, folder): 234 def Extract(filename, folder):
235 tar = tarfile.open(filename, "r:gz") 235 tar = tarfile.open(filename, "r:gz")
236 - tar.list(verbose=True) 236 + #tar.list(verbose=True)
237 tar.extractall(folder) 237 tar.extractall(folder)
238 filelist = [os.path.join(folder, i) for i in tar.getnames()] 238 filelist = [os.path.join(folder, i) for i in tar.getnames()]
239 tar.close() 239 tar.close()
invesalius/reader/dicom_reader.py
@@ -85,13 +85,11 @@ def yGetDicomGroups(directory, recursive=True, gui=True): @@ -85,13 +85,11 @@ def yGetDicomGroups(directory, recursive=True, gui=True):
85 dirpath, dirnames, filenames = os.walk(directory) 85 dirpath, dirnames, filenames = os.walk(directory)
86 nfiles = len(filenames) 86 nfiles = len(filenames)
87 87
88 - print "TOTAL FILES:", nfiles  
89 counter = 0 88 counter = 0
90 grouper = dicom_grouper.DicomPatientGrouper() 89 grouper = dicom_grouper.DicomPatientGrouper()
91 # Retrieve only DICOM files, splited into groups 90 # Retrieve only DICOM files, splited into groups
92 if recursive: 91 if recursive:
93 for dirpath, dirnames, filenames in os.walk(directory): 92 for dirpath, dirnames, filenames in os.walk(directory):
94 - print "@: ",dirpath  
95 for name in filenames: 93 for name in filenames:
96 filepath = str(os.path.join(dirpath, name)) 94 filepath = str(os.path.join(dirpath, name))
97 parser = dicom.Parser() 95 parser = dicom.Parser()
@@ -104,7 +102,6 @@ def yGetDicomGroups(directory, recursive=True, gui=True): @@ -104,7 +102,6 @@ def yGetDicomGroups(directory, recursive=True, gui=True):
104 grouper.AddFile(dcm) 102 grouper.AddFile(dcm)
105 else: 103 else:
106 dirpath, dirnames, filenames = os.walk(directory) 104 dirpath, dirnames, filenames = os.walk(directory)
107 - print "@: ",dirpath  
108 for name in filenames: 105 for name in filenames:
109 filepath = str(os.path.join(dirpath, name)) 106 filepath = str(os.path.join(dirpath, name))
110 parser = dicom.Parser() 107 parser = dicom.Parser()