Commit 8fa40bf2cf6da2dff74f47600652a27fddd19b8b
1 parent
508c5f6e
Exists in
master
and in
68 other branches
ENH: Plotting clut raycasting widget histogram in log scale
Showing
2 changed files
with
30 additions
and
11 deletions
Show diff stats
invesalius/data/volume.py
invesalius/gui/widgets/clut_raycasting.py
| ... | ... | @@ -11,6 +11,10 @@ import wx.lib.wxcairo |
| 11 | 11 | |
| 12 | 12 | FONT_COLOUR = (1, 1, 1) |
| 13 | 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 | 18 | BACKGROUND_TEXT_COLOUR_RGBA = (1, 0, 0, 0.5) |
| 15 | 19 | GRADIENT_RGBA = 0.75 |
| 16 | 20 | RADIUS = 5 |
| ... | ... | @@ -33,6 +37,7 @@ class CLUTRaycastingWidget(wx.Panel): |
| 33 | 37 | self.end = 2000 |
| 34 | 38 | self.padding = 10 |
| 35 | 39 | self.to_render = False |
| 40 | + self.to_draw_points = 0 | |
| 36 | 41 | self.histogram_pixel_points = [[0,0]] |
| 37 | 42 | self.histogram_array = [100,100] |
| 38 | 43 | self.CreatePixelArray() |
| ... | ... | @@ -208,7 +213,8 @@ class CLUTRaycastingWidget(wx.Panel): |
| 208 | 213 | dc = wx.BufferedPaintDC(self) |
| 209 | 214 | dc.SetBackground(wx.Brush('Black')) |
| 210 | 215 | dc.Clear() |
| 211 | - self.Render(dc) | |
| 216 | + if self.to_draw_points: | |
| 217 | + self.Render(dc) | |
| 212 | 218 | |
| 213 | 219 | def OnSize(self, evt): |
| 214 | 220 | print "Resizing" |
| ... | ... | @@ -287,15 +293,20 @@ class CLUTRaycastingWidget(wx.Panel): |
| 287 | 293 | ctx.move_to(x + RADIUS + 1, y - RADIUS - 1 - fheight) |
| 288 | 294 | ctx.show_text("Value: %6d" % value) |
| 289 | 295 | |
| 290 | - def _draw_histogram(self, ctx): | |
| 296 | + def _draw_histogram(self, ctx, height): | |
| 291 | 297 | # The histogram |
| 292 | - ctx.set_source_rgb(0.5, 0.5, 0.5) | |
| 293 | 298 | x,y = self.histogram_pixel_points[0] |
| 294 | 299 | print "=>", x,y |
| 295 | 300 | ctx.move_to(x,y) |
| 296 | - ctx.set_line_width(0.5) | |
| 301 | + ctx.set_line_width(HISTOGRAM_LINE_WIDTH) | |
| 297 | 302 | for x,y in self.histogram_pixel_points: |
| 298 | 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 | 310 | ctx.stroke() |
| 300 | 311 | |
| 301 | 312 | def _draw_selection_curve(self, ctx, width): |
| ... | ... | @@ -314,7 +325,8 @@ class CLUTRaycastingWidget(wx.Panel): |
| 314 | 325 | height -= self.padding |
| 315 | 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 | 330 | self._draw_gradient(ctx, height) |
| 319 | 331 | self._draw_curves(ctx) |
| 320 | 332 | self._draw_points(ctx) |
| ... | ... | @@ -328,14 +340,18 @@ class CLUTRaycastingWidget(wx.Panel): |
| 328 | 340 | width -= self.padding |
| 329 | 341 | height -= self.padding |
| 330 | 342 | y_init = 0 |
| 331 | - y_end = max(self.histogram_array) | |
| 343 | + y_end = math.log(max(self.histogram_array)) | |
| 332 | 344 | print y_end |
| 333 | 345 | proportion_x = width * 1.0 / (self.end - self.init) |
| 334 | 346 | proportion_y = height * 1.0 / (y_end - y_init) |
| 335 | 347 | print ":) ", y_end, proportion_y |
| 336 | 348 | self.histogram_pixel_points = [] |
| 337 | 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 | 355 | x = self.init+ i |
| 340 | 356 | x = (x + abs(self.init)) * proportion_x |
| 341 | 357 | y = height - y * proportion_y |
| ... | ... | @@ -376,9 +392,13 @@ class CLUTRaycastingWidget(wx.Panel): |
| 376 | 392 | print x,y |
| 377 | 393 | |
| 378 | 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 | 403 | def SetHistrogramArray(self, h_array): |
| 384 | 404 | self.histogram_array = h_array | ... | ... |