Commit 5de709ee1731a30b619e071f616a231b75b5ac22

Authored by tfmoraes
1 parent 01a03174

ENH: Using wx events instead of pubsub messages in clut_raycasting. FIX: fix a e…

…rror when altering color in clut_raycasting
invesalius/data/viewer_volume.py
@@ -669,4 +669,4 @@ class SlicePlane: @@ -669,4 +669,4 @@ class SlicePlane:
669 self.plane_y.SetSliceIndex(number) 669 self.plane_y.SetSliceIndex(number)
670 else: 670 else:
671 self.plane_z.SetPlaneOrientationToZAxes() 671 self.plane_z.SetPlaneOrientationToZAxes()
672 - self.plane_z.SetSliceIndex(number)  
673 \ No newline at end of file 672 \ No newline at end of file
  673 + self.plane_z.SetSliceIndex(number)
invesalius/data/volume.py
@@ -125,7 +125,7 @@ class Volume(): @@ -125,7 +125,7 @@ class Volume():
125 if self.exist: 125 if self.exist:
126 self.__load_preset() 126 self.__load_preset()
127 self.volume.SetVisibility(1) 127 self.volume.SetVisibility(1)
128 - ps.Publisher().sendMessage('Render volume viewer') 128 + #ps.Publisher().sendMessage('Render volume viewer')
129 else: 129 else:
130 self.LoadVolume() 130 self.LoadVolume()
131 self.exist = 1 131 self.exist = 1
@@ -140,10 +140,16 @@ class Volume(): @@ -140,10 +140,16 @@ class Volume():
140 if self.config['advancedCLUT']: 140 if self.config['advancedCLUT']:
141 self.Create16bColorTable(self.scale) 141 self.Create16bColorTable(self.scale)
142 self.CreateOpacityTable(self.scale) 142 self.CreateOpacityTable(self.scale)
  143 + self.CalculateWWWL()
  144 + ww = self.ww
  145 + wl = self.wl
  146 + ps.Publisher().sendMessage('Set volume window and level text',
  147 + (ww, wl))
143 else: 148 else:
144 self.Create8bColorTable(self.scale) 149 self.Create8bColorTable(self.scale)
145 self.Create8bOpacityTable(self.scale) 150 self.Create8bOpacityTable(self.scale)
146 151
  152 +
147 def __load_preset(self): 153 def __load_preset(self):
148 # Update colour table 154 # Update colour table
149 self.__update_colour_table() 155 self.__update_colour_table()
@@ -185,7 +191,11 @@ class Volume(): @@ -185,7 +191,11 @@ class Volume():
185 def SetWWWL(self, ww, wl): 191 def SetWWWL(self, ww, wl):
186 192
187 if self.config['advancedCLUT']: 193 if self.config['advancedCLUT']:
188 - curve = self.config['16bitClutCurves'][self.curve] 194 + try:
  195 + curve = self.config['16bitClutCurves'][self.curve]
  196 + except IndexError:
  197 + self.curve = 0
  198 + curve = self.config['16bitClutCurves'][self.curve]
189 199
190 p1 = curve[0] 200 p1 = curve[0]
191 p2 = curve[-1] 201 p2 = curve[-1]
@@ -210,7 +220,6 @@ class Volume(): @@ -210,7 +220,6 @@ class Volume():
210 self.config['ww'] = ww 220 self.config['ww'] = ww
211 221
212 self.__update_colour_table() 222 self.__update_colour_table()
213 - ps.Publisher().sendMessage('Render volume viewer')  
214 223
215 def CalculateWWWL(self): 224 def CalculateWWWL(self):
216 """ 225 """
@@ -220,7 +229,7 @@ class Volume(): @@ -220,7 +229,7 @@ class Volume():
220 first_point = curve[0]['x'] 229 first_point = curve[0]['x']
221 last_point = curve[-1]['x'] 230 last_point = curve[-1]['x']
222 self.ww = last_point - first_point 231 self.ww = last_point - first_point
223 - self.wl = first_point + self.ww 232 + self.wl = first_point + self.ww / 2.0
224 233
225 def Refresh(self, pubsub_evt): 234 def Refresh(self, pubsub_evt):
226 self.__update_colour_table() 235 self.__update_colour_table()
@@ -457,8 +466,8 @@ class Volume(): @@ -457,8 +466,8 @@ class Volume():
457 self.volume_mapper = volume_mapper 466 self.volume_mapper = volume_mapper
458 467
459 # TODO: Look to this 468 # TODO: Look to this
460 - #volume_mapper = vtk.vtkVolumeTextureMapper2D()  
461 - #volume_mapper.SetInput(image2.GetOutput()) 469 + #volume_mapper_hw = vtk.vtkVolumeTextureMapper3D()
  470 + #volume_mapper_hw.SetInput(image2)
462 471
463 #Cut Plane 472 #Cut Plane
464 #CutPlane(image2, volume_mapper) 473 #CutPlane(image2, volume_mapper)
@@ -495,7 +504,7 @@ class Volume(): @@ -495,7 +504,7 @@ class Volume():
495 volume.SetMapper(volume_mapper) 504 volume.SetMapper(volume_mapper)
496 volume.SetProperty(volume_properties) 505 volume.SetProperty(volume_properties)
497 volume.AddObserver("ProgressEvent", lambda obj,evt: 506 volume.AddObserver("ProgressEvent", lambda obj,evt:
498 - update_progress(volume, "Volume ...")) 507 + update_progress(volume, "Volume ..."))
499 self.volume = volume 508 self.volume = volume
500 509
501 colour = self.GetBackgroundColour() 510 colour = self.GetBackgroundColour()
invesalius/gui/default_viewers.py
@@ -255,6 +255,7 @@ class VolumeInteraction(wx.Panel): @@ -255,6 +255,7 @@ class VolumeInteraction(wx.Panel):
255 255
256 def OnPointChanged(self, evt): 256 def OnPointChanged(self, evt):
257 ps.Publisher.sendMessage('Set raycasting refresh', None) 257 ps.Publisher.sendMessage('Set raycasting refresh', None)
  258 + ps.Publisher.sendMessage('Set raycasting curve', evt.GetCurve())
258 ps.Publisher().sendMessage('Render volume viewer', None) 259 ps.Publisher().sendMessage('Render volume viewer', None)
259 260
260 def OnCurveSelected(self, evt): 261 def OnCurveSelected(self, evt):
invesalius/gui/widgets/clut_raycasting.py
@@ -150,7 +150,7 @@ class CLUTRaycastingWidget(wx.Panel): @@ -150,7 +150,7 @@ class CLUTRaycastingWidget(wx.Panel):
150 if point: 150 if point:
151 colour = wx.GetColourFromUser(self) 151 colour = wx.GetColourFromUser(self)
152 if colour.IsOk(): 152 if colour.IsOk():
153 - i,j = self.point_dragged 153 + i,j = point
154 r, g, b = [x/255.0 for x in colour.Get()] 154 r, g, b = [x/255.0 for x in colour.Get()]
155 self.colours[i][j]['red'] = r 155 self.colours[i][j]['red'] = r
156 self.colours[i][j]['green'] = g 156 self.colours[i][j]['green'] = g