From 8fa40bf2cf6da2dff74f47600652a27fddd19b8b Mon Sep 17 00:00:00 2001 From: tfmoraes Date: Thu, 13 Aug 2009 19:14:04 +0000 Subject: [PATCH] ENH: Plotting clut raycasting widget histogram in log scale --- invesalius/data/volume.py | 1 - invesalius/gui/widgets/clut_raycasting.py | 40 ++++++++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/invesalius/data/volume.py b/invesalius/data/volume.py index a302026..138ab30 100755 --- a/invesalius/data/volume.py +++ b/invesalius/data/volume.py @@ -289,7 +289,6 @@ class Volume(): self.config['backgroundColorBlueComponent']) return color_background - def BuildTable(): curve_table = p['16bitClutCurves'] color_background = (p['backgroundColorRedComponent'], diff --git a/invesalius/gui/widgets/clut_raycasting.py b/invesalius/gui/widgets/clut_raycasting.py index 8d759a1..a5974f0 100644 --- a/invesalius/gui/widgets/clut_raycasting.py +++ b/invesalius/gui/widgets/clut_raycasting.py @@ -11,6 +11,10 @@ import wx.lib.wxcairo FONT_COLOUR = (1, 1, 1) LINE_COLOUR = (0.5, 0.5, 0.5) +LINE_WIDTH = 2 +HISTOGRAM_LINE_WIDTH = 1 +HISTOGRAM_LINE_COLOUR = (0.5, 0.5, 0.5) +HISTOGRAM_FILL_COLOUR = (0.25, 0.25, 0.25) BACKGROUND_TEXT_COLOUR_RGBA = (1, 0, 0, 0.5) GRADIENT_RGBA = 0.75 RADIUS = 5 @@ -33,6 +37,7 @@ class CLUTRaycastingWidget(wx.Panel): self.end = 2000 self.padding = 10 self.to_render = False + self.to_draw_points = 0 self.histogram_pixel_points = [[0,0]] self.histogram_array = [100,100] self.CreatePixelArray() @@ -208,7 +213,8 @@ class CLUTRaycastingWidget(wx.Panel): dc = wx.BufferedPaintDC(self) dc.SetBackground(wx.Brush('Black')) dc.Clear() - self.Render(dc) + if self.to_draw_points: + self.Render(dc) def OnSize(self, evt): print "Resizing" @@ -287,15 +293,20 @@ class CLUTRaycastingWidget(wx.Panel): ctx.move_to(x + RADIUS + 1, y - RADIUS - 1 - fheight) ctx.show_text("Value: %6d" % value) - def _draw_histogram(self, ctx): + def _draw_histogram(self, ctx, height): # The histogram - ctx.set_source_rgb(0.5, 0.5, 0.5) x,y = self.histogram_pixel_points[0] print "=>", x,y ctx.move_to(x,y) - ctx.set_line_width(0.5) + ctx.set_line_width(HISTOGRAM_LINE_WIDTH) for x,y in self.histogram_pixel_points: ctx.line_to(x,y) + ctx.line_to(0, height) + x,y = self.histogram_pixel_points[0] + ctx.set_source_rgb(*HISTOGRAM_FILL_COLOUR) + ctx.line_to(x, y) + ctx.fill_preserve() + ctx.set_source_rgb(*HISTOGRAM_LINE_COLOUR) ctx.stroke() def _draw_selection_curve(self, ctx, width): @@ -314,7 +325,8 @@ class CLUTRaycastingWidget(wx.Panel): height -= self.padding width -= self.padding - self._draw_histogram(ctx) + self._draw_histogram(ctx, height) + ctx.set_line_width(LINE_WIDTH) self._draw_gradient(ctx, height) self._draw_curves(ctx) self._draw_points(ctx) @@ -328,14 +340,18 @@ class CLUTRaycastingWidget(wx.Panel): width -= self.padding height -= self.padding y_init = 0 - y_end = max(self.histogram_array) + y_end = math.log(max(self.histogram_array)) print y_end proportion_x = width * 1.0 / (self.end - self.init) proportion_y = height * 1.0 / (y_end - y_init) print ":) ", y_end, proportion_y self.histogram_pixel_points = [] for i in xrange(len(self.histogram_array)): - y = self.histogram_array[i] + if self.histogram_array[i]: + y = math.log(self.histogram_array[i]) + else: + y = 0 + print y x = self.init+ i x = (x + abs(self.init)) * proportion_x y = height - y * proportion_y @@ -376,9 +392,13 @@ class CLUTRaycastingWidget(wx.Panel): print x,y def SetRaycastPreset(self, preset): - self.points = preset.data['16bitClutCurves'] - self.colours = preset.data['16bitClutColors'] - self.CreatePixelArray() + if preset.data['advancedCLUT']: + self.to_draw_points = 1 + self.points = preset.data['16bitClutCurves'] + self.colours = preset.data['16bitClutColors'] + self.CreatePixelArray() + else: + self.to_draw_points = 0 def SetHistrogramArray(self, h_array): self.histogram_array = h_array -- libgit2 0.21.2