Commit 8fa40bf2cf6da2dff74f47600652a27fddd19b8b

Authored by tfmoraes
1 parent 508c5f6e

ENH: Plotting clut raycasting widget histogram in log scale

invesalius/data/volume.py
@@ -289,7 +289,6 @@ class Volume(): @@ -289,7 +289,6 @@ class Volume():
289 self.config['backgroundColorBlueComponent']) 289 self.config['backgroundColorBlueComponent'])
290 return color_background 290 return color_background
291 291
292 -  
293 def BuildTable(): 292 def BuildTable():
294 curve_table = p['16bitClutCurves'] 293 curve_table = p['16bitClutCurves']
295 color_background = (p['backgroundColorRedComponent'], 294 color_background = (p['backgroundColorRedComponent'],
invesalius/gui/widgets/clut_raycasting.py
@@ -11,6 +11,10 @@ import wx.lib.wxcairo @@ -11,6 +11,10 @@ import wx.lib.wxcairo
11 11
12 FONT_COLOUR = (1, 1, 1) 12 FONT_COLOUR = (1, 1, 1)
13 LINE_COLOUR = (0.5, 0.5, 0.5) 13 LINE_COLOUR = (0.5, 0.5, 0.5)
  14 +LINE_WIDTH = 2
  15 +HISTOGRAM_LINE_WIDTH = 1
  16 +HISTOGRAM_LINE_COLOUR = (0.5, 0.5, 0.5)
  17 +HISTOGRAM_FILL_COLOUR = (0.25, 0.25, 0.25)
14 BACKGROUND_TEXT_COLOUR_RGBA = (1, 0, 0, 0.5) 18 BACKGROUND_TEXT_COLOUR_RGBA = (1, 0, 0, 0.5)
15 GRADIENT_RGBA = 0.75 19 GRADIENT_RGBA = 0.75
16 RADIUS = 5 20 RADIUS = 5
@@ -33,6 +37,7 @@ class CLUTRaycastingWidget(wx.Panel): @@ -33,6 +37,7 @@ class CLUTRaycastingWidget(wx.Panel):
33 self.end = 2000 37 self.end = 2000
34 self.padding = 10 38 self.padding = 10
35 self.to_render = False 39 self.to_render = False
  40 + self.to_draw_points = 0
36 self.histogram_pixel_points = [[0,0]] 41 self.histogram_pixel_points = [[0,0]]
37 self.histogram_array = [100,100] 42 self.histogram_array = [100,100]
38 self.CreatePixelArray() 43 self.CreatePixelArray()
@@ -208,7 +213,8 @@ class CLUTRaycastingWidget(wx.Panel): @@ -208,7 +213,8 @@ class CLUTRaycastingWidget(wx.Panel):
208 dc = wx.BufferedPaintDC(self) 213 dc = wx.BufferedPaintDC(self)
209 dc.SetBackground(wx.Brush('Black')) 214 dc.SetBackground(wx.Brush('Black'))
210 dc.Clear() 215 dc.Clear()
211 - self.Render(dc) 216 + if self.to_draw_points:
  217 + self.Render(dc)
212 218
213 def OnSize(self, evt): 219 def OnSize(self, evt):
214 print "Resizing" 220 print "Resizing"
@@ -287,15 +293,20 @@ class CLUTRaycastingWidget(wx.Panel): @@ -287,15 +293,20 @@ class CLUTRaycastingWidget(wx.Panel):
287 ctx.move_to(x + RADIUS + 1, y - RADIUS - 1 - fheight) 293 ctx.move_to(x + RADIUS + 1, y - RADIUS - 1 - fheight)
288 ctx.show_text("Value: %6d" % value) 294 ctx.show_text("Value: %6d" % value)
289 295
290 - def _draw_histogram(self, ctx): 296 + def _draw_histogram(self, ctx, height):
291 # The histogram 297 # The histogram
292 - ctx.set_source_rgb(0.5, 0.5, 0.5)  
293 x,y = self.histogram_pixel_points[0] 298 x,y = self.histogram_pixel_points[0]
294 print "=>", x,y 299 print "=>", x,y
295 ctx.move_to(x,y) 300 ctx.move_to(x,y)
296 - ctx.set_line_width(0.5) 301 + ctx.set_line_width(HISTOGRAM_LINE_WIDTH)
297 for x,y in self.histogram_pixel_points: 302 for x,y in self.histogram_pixel_points:
298 ctx.line_to(x,y) 303 ctx.line_to(x,y)
  304 + ctx.line_to(0, height)
  305 + x,y = self.histogram_pixel_points[0]
  306 + ctx.set_source_rgb(*HISTOGRAM_FILL_COLOUR)
  307 + ctx.line_to(x, y)
  308 + ctx.fill_preserve()
  309 + ctx.set_source_rgb(*HISTOGRAM_LINE_COLOUR)
299 ctx.stroke() 310 ctx.stroke()
300 311
301 def _draw_selection_curve(self, ctx, width): 312 def _draw_selection_curve(self, ctx, width):
@@ -314,7 +325,8 @@ class CLUTRaycastingWidget(wx.Panel): @@ -314,7 +325,8 @@ class CLUTRaycastingWidget(wx.Panel):
314 height -= self.padding 325 height -= self.padding
315 width -= self.padding 326 width -= self.padding
316 327
317 - self._draw_histogram(ctx) 328 + self._draw_histogram(ctx, height)
  329 + ctx.set_line_width(LINE_WIDTH)
318 self._draw_gradient(ctx, height) 330 self._draw_gradient(ctx, height)
319 self._draw_curves(ctx) 331 self._draw_curves(ctx)
320 self._draw_points(ctx) 332 self._draw_points(ctx)
@@ -328,14 +340,18 @@ class CLUTRaycastingWidget(wx.Panel): @@ -328,14 +340,18 @@ class CLUTRaycastingWidget(wx.Panel):
328 width -= self.padding 340 width -= self.padding
329 height -= self.padding 341 height -= self.padding
330 y_init = 0 342 y_init = 0
331 - y_end = max(self.histogram_array) 343 + y_end = math.log(max(self.histogram_array))
332 print y_end 344 print y_end
333 proportion_x = width * 1.0 / (self.end - self.init) 345 proportion_x = width * 1.0 / (self.end - self.init)
334 proportion_y = height * 1.0 / (y_end - y_init) 346 proportion_y = height * 1.0 / (y_end - y_init)
335 print ":) ", y_end, proportion_y 347 print ":) ", y_end, proportion_y
336 self.histogram_pixel_points = [] 348 self.histogram_pixel_points = []
337 for i in xrange(len(self.histogram_array)): 349 for i in xrange(len(self.histogram_array)):
338 - y = self.histogram_array[i] 350 + if self.histogram_array[i]:
  351 + y = math.log(self.histogram_array[i])
  352 + else:
  353 + y = 0
  354 + print y
339 x = self.init+ i 355 x = self.init+ i
340 x = (x + abs(self.init)) * proportion_x 356 x = (x + abs(self.init)) * proportion_x
341 y = height - y * proportion_y 357 y = height - y * proportion_y
@@ -376,9 +392,13 @@ class CLUTRaycastingWidget(wx.Panel): @@ -376,9 +392,13 @@ class CLUTRaycastingWidget(wx.Panel):
376 print x,y 392 print x,y
377 393
378 def SetRaycastPreset(self, preset): 394 def SetRaycastPreset(self, preset):
379 - self.points = preset.data['16bitClutCurves']  
380 - self.colours = preset.data['16bitClutColors']  
381 - self.CreatePixelArray() 395 + if preset.data['advancedCLUT']:
  396 + self.to_draw_points = 1
  397 + self.points = preset.data['16bitClutCurves']
  398 + self.colours = preset.data['16bitClutColors']
  399 + self.CreatePixelArray()
  400 + else:
  401 + self.to_draw_points = 0
382 402
383 def SetHistrogramArray(self, h_array): 403 def SetHistrogramArray(self, h_array):
384 self.histogram_array = h_array 404 self.histogram_array = h_array