From 21804c8b2c1cf0d2f207a04528cb430bd7d94fba Mon Sep 17 00:00:00 2001 From: Saranjeet Singh Saluja Date: Sun, 31 Jul 2022 14:54:40 -0400 Subject: [PATCH 01/10] Added Colorpicker to elements.py --- fury/ui/elements.py | 224 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 223 insertions(+), 1 deletion(-) diff --git a/fury/ui/elements.py b/fury/ui/elements.py index 12d41afbe..b2a5eaa9e 100644 --- a/fury/ui/elements.py +++ b/fury/ui/elements.py @@ -874,7 +874,6 @@ def _setup(self): self.handles[1].on_left_mouse_button_released = \ self.handle_release_callback - def _get_actors(self): """Get the actors composing this UI component.""" return (self.track.actors + self.handles[0].actors + @@ -2839,6 +2838,7 @@ def left_button_clicked(self, i_ren, _obj, _list_box_item): def resize(self, size): self.background.resize(size) + class FileMenu2D(UI): """A menu to select files in the current folder. @@ -3484,3 +3484,225 @@ def left_button_dragged(self, i_ren, _obj, element): mouse_position = self.clamp_mouse_position(i_ren.event.position) self.handle_mouse_drag(mouse_position) i_ren.force_render() + + +class ColorPicker(UI): + """ A color picker that uses the HSV color model. + It consists of a vertical bar that selects the hue and + a square that selects the saturation and value for the selected hue. + """ + + def __init__(self, side=100, position=(0, 0)): + """ Initialize the color picker. + Parameters + ---------- + side : int + The side length of the square(and height of the hue bar) in pixels. + position : (float, float) + Coordinates (x, y) of the lower-left corner of the sqaure. + """ + super(ColorPicker, self).__init__(position) + self.side = side + self.pointer.position = self.ColorSelectionSquare.center + self.position = position + self.current_hue = 0 + self.current_saturation = 0.5 + self.current_value = 0.5 + # Offer some standard hooks to the user. + self.on_change = lambda color_picker, r, g, b: None + + def _setup(self): + """ Setup this UI component. + """ + # Setup the hue bar + self.HueBar = vtk.vtkScalarBarActor() + self.HueBar.GetPositionCoordinate().SetCoordinateSystemToDisplay() + self.HueBar.GetPosition2Coordinate().SetCoordinateSystemToDisplay() + self.HueBar.SetNumberOfLabels(0) + hueLut = vtk.vtkLookupTable() + hueLut.SetTableRange(0, 1) + hueLut.SetHueRange(0, 1) + hueLut.SetSaturationRange(1, 1) + hueLut.SetValueRange(1, 1) + hueLut.Build() + self.HueBar.SetLookupTable(hueLut) + self.add_callback(self.HueBar, "MouseMoveEvent", + self.hue_select_callback) + # Setup colors for the square + colors = vtk.vtkUnsignedCharArray() + colors.SetNumberOfComponents(3) + colors.SetName("Colors") + colors.InsertNextTuple3(*self.hsv2rgb(0, 0, 0)) + colors.InsertNextTuple3(*self.hsv2rgb(0, 1, 0)) + colors.InsertNextTuple3(*self.hsv2rgb(0, 1, 1)) + colors.InsertNextTuple3(*self.hsv2rgb(0, 0, 1)) + # Setup the square + self.ColorSelectionSquare = Rectangle2D() + self.ColorSelectionSquare._polygonPolyData.GetPointData().\ + SetScalars(colors) + if VTK_MAJOR_VERSION <= 5: + self.ColorSelectionSquare._polygonPolyData.Update() + self.ColorSelectionSquare.on_left_mouse_button_dragged = \ + self.color_select_callback + # Setup the circle pointer + self.pointer = Disk2D(outer_radius=1) + + def _get_actors(self): + """ Get the actors composing this UI component. + """ + return self.ColorSelectionSquare.actors + self.HueBar +\ + self.pointer.actors + + def _add_to_renderer(self, ren): + """ Add all subcomponents or VTK props that compose this UI component. + Parameters + ---------- + ren : renderer + """ + self.ColorSelectionSquare.add_to_renderer(ren) + self.pointer.add_to_renderer(ren) + ren.add(self.HueBar) + + def _get_size(self): + return (6*self.side/5, self.side) + + @property + def side(self): + return self.HueBar.GetPosition2()[1] + + @side.setter + def side(self, side): + self.HueBar.SetPosition2(side / 5, side) + self.ColorSelectionSquare.resize((side, side)) + self.pointer.outer_radius = side/50 + self.pointer.inner_radius = side/50 - 1 + + @property + def current_hue(self): + color = self.ColorSelectionSquare._polygonPolyData.GetPointData().\ + GetScalars().GetTuple(2) + return self.rgb2hsv(*color)[0] + + @current_hue.setter + def current_hue(self, hue): + colors = vtk.vtkUnsignedCharArray() + colors.SetNumberOfComponents(3) + colors.SetName("Colors") + colors.InsertNextTuple3(*self.hsv2rgb(hue, 0, 0)) + colors.InsertNextTuple3(*self.hsv2rgb(hue, 1, 0)) + colors.InsertNextTuple3(*self.hsv2rgb(hue, 1, 1)) + colors.InsertNextTuple3(*self.hsv2rgb(hue, 0, 1)) + self.ColorSelectionSquare._polygonPolyData.GetPointData().\ + SetScalars(colors) + if VTK_MAJOR_VERSION <= 5: + self.ColorSelectionSquare._polygonPolyData.Update() + + def rgb2hsv(self, R, G, B): + """ Function to convert given RGB value to HSV + Parameters + ---------- + R : float[0-255] + Red value. + G : float[0-255] + Green value. + B : float[0-255] + Blue value. + """ + (r, g, b) = (R/255, G/255, B/255) + cmax = max(r, g, b) + cmin = min(r, g, b) + delta = cmax - cmin + if delta == 0: + H = 0 + elif cmax == r: + H = 60*(((g-b)/delta) % 6) + elif cmax == g: + H = 60*(((b-r)/delta)+2) + elif cmax == b: + H = 60*(((r-g)/delta)+4) + if cmax == 0: + S = 0 + else: + S = delta/cmax + V = cmax + return H, S, V + + def hsv2rgb(self, H, S, V): + """ Function to convert given HSV value to RGB + Parameters + ---------- + H : float[0-360] + Hue. + S : float[0-1] + Saturation. + V : float[0-1] + Value. + """ + C = V * S + X = C * (1 - abs((H / 60) % 2 - 1)) + m = V - C + if H < 60: + (r, g, b) = (C, X, 0) + elif H < 120: + (r, g, b) = (X, C, 0) + elif H < 180: + (r, g, b) = (0, C, X) + elif H < 240: + (r, g, b) = (0, X, C) + elif H < 300: + (r, g, b) = (X, 0, C) + else: + (r, g, b) = (C, 0, X) + (R, G, B) = ((r+m)*255, (g+m)*255, (b+m)*255) + return R, G, B + + def _set_position(self, coords): + """ Position the lower-left corner of this UI component. + Parameters + ---------- + coords: (float, float) + Absolute pixel coordinates (x, y). + """ + offset = coords - self.position + self.ColorSelectionSquare.position = coords + self.pointer.center += offset + self.HueBar.SetPosition(coords[0] + self.side, coords[1]) + + def hue_select_callback(self, i_ren, obj, color_picker): + """ A callback to select the hue from the hue bar. + Parameters + ---------- + i_ren: :class:`CustomInteractorStyle` + obj: :class:`vtkActor` + The picked actor + color_picker: :class:`ColorPicker` + """ + FractionalHue = (i_ren.event.position[1] - self.position[1])/self.side + self.current_hue = FractionalHue * 360 + self.on_change( + self, *self.hsv2rgb(self.current_hue, self.current_saturation, + self.current_value)) + i_ren.force_render() + i_ren.event.abort() + + def color_select_callback(self, i_ren, obj, rectangle2d): + """ A callback to select the hue and saturation from the sqaure. + Parameters + ---------- + i_ren: :class:`CustomInteractorStyle` + obj: :class:`vtkActor` + The picked actor + rectangle2d: :class:`Rectangle2D` + """ + coords = i_ren.event.position + # Ensure coords are within the square + coords = np.maximum(coords, self.position) + coords = np.minimum(coords, self.position + self.side) + self.pointer.center = coords + relative_coords = coords - self.position + self.current_saturation, self.current_value = relative_coords/self.side + self.on_change( + self, *self.hsv2rgb(self.current_hue, self.current_saturation, + self.current_value)) + i_ren.force_render() + i_ren.event.abort() From ff7eaa3f4acb51a8776931443f971ae5bf175486 Mon Sep 17 00:00:00 2001 From: Saranjeet Singh Saluja Date: Sun, 31 Jul 2022 15:36:24 -0400 Subject: [PATCH 02/10] Removed colorpicker from elements.py and Added to core.py --- fury/ui/core.py | 222 ++++++++++++++++++++++++++++++++++++++++++++ fury/ui/elements.py | 222 -------------------------------------------- 2 files changed, 222 insertions(+), 222 deletions(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index 46f34b91b..b845ce35f 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -1287,3 +1287,225 @@ def next_icon(self): """ self.next_icon_id() self.set_icon(self.icons[self.current_icon_id][1]) + + +class ColorPicker(UI): + """ A color picker that uses the HSV color model. + It consists of a vertical bar that selects the hue and + a square that selects the saturation and value for the selected hue. + """ + + def __init__(self, side=100, position=(0, 0)): + """ Initialize the color picker. + Parameters + ---------- + side : int + The side length of the square(and height of the hue bar) in pixels. + position : (float, float) + Coordinates (x, y) of the lower-left corner of the sqaure. + """ + super(ColorPicker, self).__init__(position) + self.side = side + self.pointer.position = self.ColorSelectionSquare.center + self.position = position + self.current_hue = 0 + self.current_saturation = 0.5 + self.current_value = 0.5 + # Offer some standard hooks to the user. + self.on_change = lambda color_picker, r, g, b: None + + def _setup(self): + """ Setup this UI component. + """ + # Setup the hue bar + self.HueBar = vtk.vtkScalarBarActor() + self.HueBar.GetPositionCoordinate().SetCoordinateSystemToDisplay() + self.HueBar.GetPosition2Coordinate().SetCoordinateSystemToDisplay() + self.HueBar.SetNumberOfLabels(0) + hueLut = vtk.vtkLookupTable() + hueLut.SetTableRange(0, 1) + hueLut.SetHueRange(0, 1) + hueLut.SetSaturationRange(1, 1) + hueLut.SetValueRange(1, 1) + hueLut.Build() + self.HueBar.SetLookupTable(hueLut) + self.add_callback(self.HueBar, "MouseMoveEvent", + self.hue_select_callback) + # Setup colors for the square + colors = vtk.vtkUnsignedCharArray() + colors.SetNumberOfComponents(3) + colors.SetName("Colors") + colors.InsertNextTuple3(*self.hsv2rgb(0, 0, 0)) + colors.InsertNextTuple3(*self.hsv2rgb(0, 1, 0)) + colors.InsertNextTuple3(*self.hsv2rgb(0, 1, 1)) + colors.InsertNextTuple3(*self.hsv2rgb(0, 0, 1)) + # Setup the square + self.ColorSelectionSquare = Rectangle2D() + self.ColorSelectionSquare._polygonPolyData.GetPointData().\ + SetScalars(colors) + if VTK_MAJOR_VERSION <= 5: + self.ColorSelectionSquare._polygonPolyData.Update() + self.ColorSelectionSquare.on_left_mouse_button_dragged = \ + self.color_select_callback + # Setup the circle pointer + self.pointer = Disk2D(outer_radius=1) + + def _get_actors(self): + """ Get the actors composing this UI component. + """ + return self.ColorSelectionSquare.actors + self.HueBar +\ + self.pointer.actors + + def _add_to_renderer(self, ren): + """ Add all subcomponents or VTK props that compose this UI component. + Parameters + ---------- + ren : renderer + """ + self.ColorSelectionSquare.add_to_renderer(ren) + self.pointer.add_to_renderer(ren) + ren.add(self.HueBar) + + def _get_size(self): + return (6*self.side/5, self.side) + + @property + def side(self): + return self.HueBar.GetPosition2()[1] + + @side.setter + def side(self, side): + self.HueBar.SetPosition2(side / 5, side) + self.ColorSelectionSquare.resize((side, side)) + self.pointer.outer_radius = side/50 + self.pointer.inner_radius = side/50 - 1 + + @property + def current_hue(self): + color = self.ColorSelectionSquare._polygonPolyData.GetPointData().\ + GetScalars().GetTuple(2) + return self.rgb2hsv(*color)[0] + + @current_hue.setter + def current_hue(self, hue): + colors = vtk.vtkUnsignedCharArray() + colors.SetNumberOfComponents(3) + colors.SetName("Colors") + colors.InsertNextTuple3(*self.hsv2rgb(hue, 0, 0)) + colors.InsertNextTuple3(*self.hsv2rgb(hue, 1, 0)) + colors.InsertNextTuple3(*self.hsv2rgb(hue, 1, 1)) + colors.InsertNextTuple3(*self.hsv2rgb(hue, 0, 1)) + self.ColorSelectionSquare._polygonPolyData.GetPointData().\ + SetScalars(colors) + if VTK_MAJOR_VERSION <= 5: + self.ColorSelectionSquare._polygonPolyData.Update() + + def rgb2hsv(self, R, G, B): + """ Function to convert given RGB value to HSV + Parameters + ---------- + R : float[0-255] + Red value. + G : float[0-255] + Green value. + B : float[0-255] + Blue value. + """ + (r, g, b) = (R/255, G/255, B/255) + cmax = max(r, g, b) + cmin = min(r, g, b) + delta = cmax - cmin + if delta == 0: + H = 0 + elif cmax == r: + H = 60*(((g-b)/delta) % 6) + elif cmax == g: + H = 60*(((b-r)/delta)+2) + elif cmax == b: + H = 60*(((r-g)/delta)+4) + if cmax == 0: + S = 0 + else: + S = delta/cmax + V = cmax + return H, S, V + + def hsv2rgb(self, H, S, V): + """ Function to convert given HSV value to RGB + Parameters + ---------- + H : float[0-360] + Hue. + S : float[0-1] + Saturation. + V : float[0-1] + Value. + """ + C = V * S + X = C * (1 - abs((H / 60) % 2 - 1)) + m = V - C + if H < 60: + (r, g, b) = (C, X, 0) + elif H < 120: + (r, g, b) = (X, C, 0) + elif H < 180: + (r, g, b) = (0, C, X) + elif H < 240: + (r, g, b) = (0, X, C) + elif H < 300: + (r, g, b) = (X, 0, C) + else: + (r, g, b) = (C, 0, X) + (R, G, B) = ((r+m)*255, (g+m)*255, (b+m)*255) + return R, G, B + + def _set_position(self, coords): + """ Position the lower-left corner of this UI component. + Parameters + ---------- + coords: (float, float) + Absolute pixel coordinates (x, y). + """ + offset = coords - self.position + self.ColorSelectionSquare.position = coords + self.pointer.center += offset + self.HueBar.SetPosition(coords[0] + self.side, coords[1]) + + def hue_select_callback(self, i_ren, obj, color_picker): + """ A callback to select the hue from the hue bar. + Parameters + ---------- + i_ren: :class:`CustomInteractorStyle` + obj: :class:`vtkActor` + The picked actor + color_picker: :class:`ColorPicker` + """ + FractionalHue = (i_ren.event.position[1] - self.position[1])/self.side + self.current_hue = FractionalHue * 360 + self.on_change( + self, *self.hsv2rgb(self.current_hue, self.current_saturation, + self.current_value)) + i_ren.force_render() + i_ren.event.abort() + + def color_select_callback(self, i_ren, obj, rectangle2d): + """ A callback to select the hue and saturation from the sqaure. + Parameters + ---------- + i_ren: :class:`CustomInteractorStyle` + obj: :class:`vtkActor` + The picked actor + rectangle2d: :class:`Rectangle2D` + """ + coords = i_ren.event.position + # Ensure coords are within the square + coords = np.maximum(coords, self.position) + coords = np.minimum(coords, self.position + self.side) + self.pointer.center = coords + relative_coords = coords - self.position + self.current_saturation, self.current_value = relative_coords/self.side + self.on_change( + self, *self.hsv2rgb(self.current_hue, self.current_saturation, + self.current_value)) + i_ren.force_render() + i_ren.event.abort() diff --git a/fury/ui/elements.py b/fury/ui/elements.py index b2a5eaa9e..aa9972f6a 100644 --- a/fury/ui/elements.py +++ b/fury/ui/elements.py @@ -3484,225 +3484,3 @@ def left_button_dragged(self, i_ren, _obj, element): mouse_position = self.clamp_mouse_position(i_ren.event.position) self.handle_mouse_drag(mouse_position) i_ren.force_render() - - -class ColorPicker(UI): - """ A color picker that uses the HSV color model. - It consists of a vertical bar that selects the hue and - a square that selects the saturation and value for the selected hue. - """ - - def __init__(self, side=100, position=(0, 0)): - """ Initialize the color picker. - Parameters - ---------- - side : int - The side length of the square(and height of the hue bar) in pixels. - position : (float, float) - Coordinates (x, y) of the lower-left corner of the sqaure. - """ - super(ColorPicker, self).__init__(position) - self.side = side - self.pointer.position = self.ColorSelectionSquare.center - self.position = position - self.current_hue = 0 - self.current_saturation = 0.5 - self.current_value = 0.5 - # Offer some standard hooks to the user. - self.on_change = lambda color_picker, r, g, b: None - - def _setup(self): - """ Setup this UI component. - """ - # Setup the hue bar - self.HueBar = vtk.vtkScalarBarActor() - self.HueBar.GetPositionCoordinate().SetCoordinateSystemToDisplay() - self.HueBar.GetPosition2Coordinate().SetCoordinateSystemToDisplay() - self.HueBar.SetNumberOfLabels(0) - hueLut = vtk.vtkLookupTable() - hueLut.SetTableRange(0, 1) - hueLut.SetHueRange(0, 1) - hueLut.SetSaturationRange(1, 1) - hueLut.SetValueRange(1, 1) - hueLut.Build() - self.HueBar.SetLookupTable(hueLut) - self.add_callback(self.HueBar, "MouseMoveEvent", - self.hue_select_callback) - # Setup colors for the square - colors = vtk.vtkUnsignedCharArray() - colors.SetNumberOfComponents(3) - colors.SetName("Colors") - colors.InsertNextTuple3(*self.hsv2rgb(0, 0, 0)) - colors.InsertNextTuple3(*self.hsv2rgb(0, 1, 0)) - colors.InsertNextTuple3(*self.hsv2rgb(0, 1, 1)) - colors.InsertNextTuple3(*self.hsv2rgb(0, 0, 1)) - # Setup the square - self.ColorSelectionSquare = Rectangle2D() - self.ColorSelectionSquare._polygonPolyData.GetPointData().\ - SetScalars(colors) - if VTK_MAJOR_VERSION <= 5: - self.ColorSelectionSquare._polygonPolyData.Update() - self.ColorSelectionSquare.on_left_mouse_button_dragged = \ - self.color_select_callback - # Setup the circle pointer - self.pointer = Disk2D(outer_radius=1) - - def _get_actors(self): - """ Get the actors composing this UI component. - """ - return self.ColorSelectionSquare.actors + self.HueBar +\ - self.pointer.actors - - def _add_to_renderer(self, ren): - """ Add all subcomponents or VTK props that compose this UI component. - Parameters - ---------- - ren : renderer - """ - self.ColorSelectionSquare.add_to_renderer(ren) - self.pointer.add_to_renderer(ren) - ren.add(self.HueBar) - - def _get_size(self): - return (6*self.side/5, self.side) - - @property - def side(self): - return self.HueBar.GetPosition2()[1] - - @side.setter - def side(self, side): - self.HueBar.SetPosition2(side / 5, side) - self.ColorSelectionSquare.resize((side, side)) - self.pointer.outer_radius = side/50 - self.pointer.inner_radius = side/50 - 1 - - @property - def current_hue(self): - color = self.ColorSelectionSquare._polygonPolyData.GetPointData().\ - GetScalars().GetTuple(2) - return self.rgb2hsv(*color)[0] - - @current_hue.setter - def current_hue(self, hue): - colors = vtk.vtkUnsignedCharArray() - colors.SetNumberOfComponents(3) - colors.SetName("Colors") - colors.InsertNextTuple3(*self.hsv2rgb(hue, 0, 0)) - colors.InsertNextTuple3(*self.hsv2rgb(hue, 1, 0)) - colors.InsertNextTuple3(*self.hsv2rgb(hue, 1, 1)) - colors.InsertNextTuple3(*self.hsv2rgb(hue, 0, 1)) - self.ColorSelectionSquare._polygonPolyData.GetPointData().\ - SetScalars(colors) - if VTK_MAJOR_VERSION <= 5: - self.ColorSelectionSquare._polygonPolyData.Update() - - def rgb2hsv(self, R, G, B): - """ Function to convert given RGB value to HSV - Parameters - ---------- - R : float[0-255] - Red value. - G : float[0-255] - Green value. - B : float[0-255] - Blue value. - """ - (r, g, b) = (R/255, G/255, B/255) - cmax = max(r, g, b) - cmin = min(r, g, b) - delta = cmax - cmin - if delta == 0: - H = 0 - elif cmax == r: - H = 60*(((g-b)/delta) % 6) - elif cmax == g: - H = 60*(((b-r)/delta)+2) - elif cmax == b: - H = 60*(((r-g)/delta)+4) - if cmax == 0: - S = 0 - else: - S = delta/cmax - V = cmax - return H, S, V - - def hsv2rgb(self, H, S, V): - """ Function to convert given HSV value to RGB - Parameters - ---------- - H : float[0-360] - Hue. - S : float[0-1] - Saturation. - V : float[0-1] - Value. - """ - C = V * S - X = C * (1 - abs((H / 60) % 2 - 1)) - m = V - C - if H < 60: - (r, g, b) = (C, X, 0) - elif H < 120: - (r, g, b) = (X, C, 0) - elif H < 180: - (r, g, b) = (0, C, X) - elif H < 240: - (r, g, b) = (0, X, C) - elif H < 300: - (r, g, b) = (X, 0, C) - else: - (r, g, b) = (C, 0, X) - (R, G, B) = ((r+m)*255, (g+m)*255, (b+m)*255) - return R, G, B - - def _set_position(self, coords): - """ Position the lower-left corner of this UI component. - Parameters - ---------- - coords: (float, float) - Absolute pixel coordinates (x, y). - """ - offset = coords - self.position - self.ColorSelectionSquare.position = coords - self.pointer.center += offset - self.HueBar.SetPosition(coords[0] + self.side, coords[1]) - - def hue_select_callback(self, i_ren, obj, color_picker): - """ A callback to select the hue from the hue bar. - Parameters - ---------- - i_ren: :class:`CustomInteractorStyle` - obj: :class:`vtkActor` - The picked actor - color_picker: :class:`ColorPicker` - """ - FractionalHue = (i_ren.event.position[1] - self.position[1])/self.side - self.current_hue = FractionalHue * 360 - self.on_change( - self, *self.hsv2rgb(self.current_hue, self.current_saturation, - self.current_value)) - i_ren.force_render() - i_ren.event.abort() - - def color_select_callback(self, i_ren, obj, rectangle2d): - """ A callback to select the hue and saturation from the sqaure. - Parameters - ---------- - i_ren: :class:`CustomInteractorStyle` - obj: :class:`vtkActor` - The picked actor - rectangle2d: :class:`Rectangle2D` - """ - coords = i_ren.event.position - # Ensure coords are within the square - coords = np.maximum(coords, self.position) - coords = np.minimum(coords, self.position + self.side) - self.pointer.center = coords - relative_coords = coords - self.position - self.current_saturation, self.current_value = relative_coords/self.side - self.on_change( - self, *self.hsv2rgb(self.current_hue, self.current_saturation, - self.current_value)) - i_ren.force_render() - i_ren.event.abort() From 0e9ed4b961d6d4653aa13e7afc2b8bb6c72593f5 Mon Sep 17 00:00:00 2001 From: Saranjeet Singh Saluja Date: Mon, 1 Aug 2022 09:03:04 -0400 Subject: [PATCH 03/10] Added ColorPicker to __all__ --- fury/ui/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index b845ce35f..5f3bdb86a 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -1,6 +1,6 @@ """UI core module that describe UI abstract class.""" -__all__ = ["Rectangle2D", "Disk2D", "TextBlock2D", "Button2D"] +__all__ = ["Rectangle2D", "Disk2D", "TextBlock2D", "Button2D", "ColorPicker"] import abc from warnings import warn From 8ac3b946d59837946912608cd45bddd326b3ba5d Mon Sep 17 00:00:00 2001 From: Saranjeet Singh Saluja Date: Wed, 3 Aug 2022 18:47:54 -0400 Subject: [PATCH 04/10] Changed _add_to_renderer to _add_to_scene --- fury/ui/core.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index 5f3bdb86a..4e983e451 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -1356,15 +1356,25 @@ def _get_actors(self): return self.ColorSelectionSquare.actors + self.HueBar +\ self.pointer.actors - def _add_to_renderer(self, ren): - """ Add all subcomponents or VTK props that compose this UI component. - Parameters - ---------- - ren : renderer - """ - self.ColorSelectionSquare.add_to_renderer(ren) - self.pointer.add_to_renderer(ren) - ren.add(self.HueBar) + def _add_to_scene(self, scene): + """Add all subcomponents or VTK props that compose this UI component. + + Parameters + ---------- + scene : scene + """ + self.ColorSelectionSquare.add(scene) + self.pointer.add(scene) + scene.add(self.HueBar) + # def _add_to_renderer(self, ren): + # """ Add all subcomponents or VTK props that compose this UI component. + # Parameters + # ---------- + # ren : renderer + # """ + # self.ColorSelectionSquare.add_to_renderer(ren) + # self.pointer.add_to_renderer(ren) + # ren.add(self.HueBar) def _get_size(self): return (6*self.side/5, self.side) From d7be3082464725f344b60809a87847a586ce2a05 Mon Sep 17 00:00:00 2001 From: Saranjeet Singh Saluja Date: Wed, 3 Aug 2022 18:49:22 -0400 Subject: [PATCH 05/10] Resolved Indentation Error --- fury/ui/core.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index 4e983e451..bab8e4057 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -1356,16 +1356,16 @@ def _get_actors(self): return self.ColorSelectionSquare.actors + self.HueBar +\ self.pointer.actors - def _add_to_scene(self, scene): + def _add_to_scene(self, scene): """Add all subcomponents or VTK props that compose this UI component. Parameters ---------- scene : scene """ - self.ColorSelectionSquare.add(scene) - self.pointer.add(scene) - scene.add(self.HueBar) + self.ColorSelectionSquare.add(scene) + self.pointer.add(scene) + scene.add(self.HueBar) # def _add_to_renderer(self, ren): # """ Add all subcomponents or VTK props that compose this UI component. # Parameters From 7b71cf9e3466dfa5e86cef89bad2f8915a4cdad9 Mon Sep 17 00:00:00 2001 From: Saranjeet Singh Saluja Date: Wed, 3 Aug 2022 18:50:12 -0400 Subject: [PATCH 06/10] Resolved Indentation Error --- fury/ui/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index bab8e4057..0b6a58e38 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -1356,7 +1356,7 @@ def _get_actors(self): return self.ColorSelectionSquare.actors + self.HueBar +\ self.pointer.actors - def _add_to_scene(self, scene): + def _add_to_scene(self, scene): """Add all subcomponents or VTK props that compose this UI component. Parameters From 397eb118f380ad2477593e57438b41d7cbaf9f22 Mon Sep 17 00:00:00 2001 From: Saranjeet Singh Saluja Date: Wed, 3 Aug 2022 18:50:45 -0400 Subject: [PATCH 07/10] Resolved Indentation Error --- fury/ui/core.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index 0b6a58e38..accae7b65 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -1357,15 +1357,15 @@ def _get_actors(self): self.pointer.actors def _add_to_scene(self, scene): - """Add all subcomponents or VTK props that compose this UI component. - - Parameters - ---------- - scene : scene - """ - self.ColorSelectionSquare.add(scene) - self.pointer.add(scene) - scene.add(self.HueBar) + """Add all subcomponents or VTK props that compose this UI component. + + Parameters + ---------- + scene : scene + """ + self.ColorSelectionSquare.add(scene) + self.pointer.add(scene) + scene.add(self.HueBar) # def _add_to_renderer(self, ren): # """ Add all subcomponents or VTK props that compose this UI component. # Parameters From 5dd26e9f9f4eaa94bf75f338982d257f6b1c799c Mon Sep 17 00:00:00 2001 From: Saranjeet Singh Saluja Date: Wed, 3 Aug 2022 18:54:27 -0400 Subject: [PATCH 08/10] Removed colorpicker from core.py to elements.py --- fury/ui/core.py | 234 +------------------------------------------- fury/ui/elements.py | 234 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 234 insertions(+), 234 deletions(-) diff --git a/fury/ui/core.py b/fury/ui/core.py index accae7b65..46f34b91b 100644 --- a/fury/ui/core.py +++ b/fury/ui/core.py @@ -1,6 +1,6 @@ """UI core module that describe UI abstract class.""" -__all__ = ["Rectangle2D", "Disk2D", "TextBlock2D", "Button2D", "ColorPicker"] +__all__ = ["Rectangle2D", "Disk2D", "TextBlock2D", "Button2D"] import abc from warnings import warn @@ -1287,235 +1287,3 @@ def next_icon(self): """ self.next_icon_id() self.set_icon(self.icons[self.current_icon_id][1]) - - -class ColorPicker(UI): - """ A color picker that uses the HSV color model. - It consists of a vertical bar that selects the hue and - a square that selects the saturation and value for the selected hue. - """ - - def __init__(self, side=100, position=(0, 0)): - """ Initialize the color picker. - Parameters - ---------- - side : int - The side length of the square(and height of the hue bar) in pixels. - position : (float, float) - Coordinates (x, y) of the lower-left corner of the sqaure. - """ - super(ColorPicker, self).__init__(position) - self.side = side - self.pointer.position = self.ColorSelectionSquare.center - self.position = position - self.current_hue = 0 - self.current_saturation = 0.5 - self.current_value = 0.5 - # Offer some standard hooks to the user. - self.on_change = lambda color_picker, r, g, b: None - - def _setup(self): - """ Setup this UI component. - """ - # Setup the hue bar - self.HueBar = vtk.vtkScalarBarActor() - self.HueBar.GetPositionCoordinate().SetCoordinateSystemToDisplay() - self.HueBar.GetPosition2Coordinate().SetCoordinateSystemToDisplay() - self.HueBar.SetNumberOfLabels(0) - hueLut = vtk.vtkLookupTable() - hueLut.SetTableRange(0, 1) - hueLut.SetHueRange(0, 1) - hueLut.SetSaturationRange(1, 1) - hueLut.SetValueRange(1, 1) - hueLut.Build() - self.HueBar.SetLookupTable(hueLut) - self.add_callback(self.HueBar, "MouseMoveEvent", - self.hue_select_callback) - # Setup colors for the square - colors = vtk.vtkUnsignedCharArray() - colors.SetNumberOfComponents(3) - colors.SetName("Colors") - colors.InsertNextTuple3(*self.hsv2rgb(0, 0, 0)) - colors.InsertNextTuple3(*self.hsv2rgb(0, 1, 0)) - colors.InsertNextTuple3(*self.hsv2rgb(0, 1, 1)) - colors.InsertNextTuple3(*self.hsv2rgb(0, 0, 1)) - # Setup the square - self.ColorSelectionSquare = Rectangle2D() - self.ColorSelectionSquare._polygonPolyData.GetPointData().\ - SetScalars(colors) - if VTK_MAJOR_VERSION <= 5: - self.ColorSelectionSquare._polygonPolyData.Update() - self.ColorSelectionSquare.on_left_mouse_button_dragged = \ - self.color_select_callback - # Setup the circle pointer - self.pointer = Disk2D(outer_radius=1) - - def _get_actors(self): - """ Get the actors composing this UI component. - """ - return self.ColorSelectionSquare.actors + self.HueBar +\ - self.pointer.actors - - def _add_to_scene(self, scene): - """Add all subcomponents or VTK props that compose this UI component. - - Parameters - ---------- - scene : scene - """ - self.ColorSelectionSquare.add(scene) - self.pointer.add(scene) - scene.add(self.HueBar) - # def _add_to_renderer(self, ren): - # """ Add all subcomponents or VTK props that compose this UI component. - # Parameters - # ---------- - # ren : renderer - # """ - # self.ColorSelectionSquare.add_to_renderer(ren) - # self.pointer.add_to_renderer(ren) - # ren.add(self.HueBar) - - def _get_size(self): - return (6*self.side/5, self.side) - - @property - def side(self): - return self.HueBar.GetPosition2()[1] - - @side.setter - def side(self, side): - self.HueBar.SetPosition2(side / 5, side) - self.ColorSelectionSquare.resize((side, side)) - self.pointer.outer_radius = side/50 - self.pointer.inner_radius = side/50 - 1 - - @property - def current_hue(self): - color = self.ColorSelectionSquare._polygonPolyData.GetPointData().\ - GetScalars().GetTuple(2) - return self.rgb2hsv(*color)[0] - - @current_hue.setter - def current_hue(self, hue): - colors = vtk.vtkUnsignedCharArray() - colors.SetNumberOfComponents(3) - colors.SetName("Colors") - colors.InsertNextTuple3(*self.hsv2rgb(hue, 0, 0)) - colors.InsertNextTuple3(*self.hsv2rgb(hue, 1, 0)) - colors.InsertNextTuple3(*self.hsv2rgb(hue, 1, 1)) - colors.InsertNextTuple3(*self.hsv2rgb(hue, 0, 1)) - self.ColorSelectionSquare._polygonPolyData.GetPointData().\ - SetScalars(colors) - if VTK_MAJOR_VERSION <= 5: - self.ColorSelectionSquare._polygonPolyData.Update() - - def rgb2hsv(self, R, G, B): - """ Function to convert given RGB value to HSV - Parameters - ---------- - R : float[0-255] - Red value. - G : float[0-255] - Green value. - B : float[0-255] - Blue value. - """ - (r, g, b) = (R/255, G/255, B/255) - cmax = max(r, g, b) - cmin = min(r, g, b) - delta = cmax - cmin - if delta == 0: - H = 0 - elif cmax == r: - H = 60*(((g-b)/delta) % 6) - elif cmax == g: - H = 60*(((b-r)/delta)+2) - elif cmax == b: - H = 60*(((r-g)/delta)+4) - if cmax == 0: - S = 0 - else: - S = delta/cmax - V = cmax - return H, S, V - - def hsv2rgb(self, H, S, V): - """ Function to convert given HSV value to RGB - Parameters - ---------- - H : float[0-360] - Hue. - S : float[0-1] - Saturation. - V : float[0-1] - Value. - """ - C = V * S - X = C * (1 - abs((H / 60) % 2 - 1)) - m = V - C - if H < 60: - (r, g, b) = (C, X, 0) - elif H < 120: - (r, g, b) = (X, C, 0) - elif H < 180: - (r, g, b) = (0, C, X) - elif H < 240: - (r, g, b) = (0, X, C) - elif H < 300: - (r, g, b) = (X, 0, C) - else: - (r, g, b) = (C, 0, X) - (R, G, B) = ((r+m)*255, (g+m)*255, (b+m)*255) - return R, G, B - - def _set_position(self, coords): - """ Position the lower-left corner of this UI component. - Parameters - ---------- - coords: (float, float) - Absolute pixel coordinates (x, y). - """ - offset = coords - self.position - self.ColorSelectionSquare.position = coords - self.pointer.center += offset - self.HueBar.SetPosition(coords[0] + self.side, coords[1]) - - def hue_select_callback(self, i_ren, obj, color_picker): - """ A callback to select the hue from the hue bar. - Parameters - ---------- - i_ren: :class:`CustomInteractorStyle` - obj: :class:`vtkActor` - The picked actor - color_picker: :class:`ColorPicker` - """ - FractionalHue = (i_ren.event.position[1] - self.position[1])/self.side - self.current_hue = FractionalHue * 360 - self.on_change( - self, *self.hsv2rgb(self.current_hue, self.current_saturation, - self.current_value)) - i_ren.force_render() - i_ren.event.abort() - - def color_select_callback(self, i_ren, obj, rectangle2d): - """ A callback to select the hue and saturation from the sqaure. - Parameters - ---------- - i_ren: :class:`CustomInteractorStyle` - obj: :class:`vtkActor` - The picked actor - rectangle2d: :class:`Rectangle2D` - """ - coords = i_ren.event.position - # Ensure coords are within the square - coords = np.maximum(coords, self.position) - coords = np.minimum(coords, self.position + self.side) - self.pointer.center = coords - relative_coords = coords - self.position - self.current_saturation, self.current_value = relative_coords/self.side - self.on_change( - self, *self.hsv2rgb(self.current_hue, self.current_saturation, - self.current_value)) - i_ren.force_render() - i_ren.event.abort() diff --git a/fury/ui/elements.py b/fury/ui/elements.py index aa9972f6a..221c16367 100644 --- a/fury/ui/elements.py +++ b/fury/ui/elements.py @@ -3,7 +3,7 @@ __all__ = ["TextBox2D", "LineSlider2D", "LineDoubleSlider2D", "RingSlider2D", "RangeSlider", "Checkbox", "Option", "RadioButton", "ComboBox2D", "ListBox2D", "ListBoxItem2D", "FileMenu2D", - "DrawShape", "DrawPanel"] + "DrawShape", "DrawPanel", "ColorPicker"] import os from collections import OrderedDict @@ -3484,3 +3484,235 @@ def left_button_dragged(self, i_ren, _obj, element): mouse_position = self.clamp_mouse_position(i_ren.event.position) self.handle_mouse_drag(mouse_position) i_ren.force_render() + + +class ColorPicker(UI): + """ A color picker that uses the HSV color model. + It consists of a vertical bar that selects the hue and + a square that selects the saturation and value for the selected hue. + """ + + def __init__(self, side=100, position=(0, 0)): + """ Initialize the color picker. + Parameters + ---------- + side : int + The side length of the square(and height of the hue bar) in pixels. + position : (float, float) + Coordinates (x, y) of the lower-left corner of the sqaure. + """ + super(ColorPicker, self).__init__(position) + self.side = side + self.pointer.position = self.ColorSelectionSquare.center + self.position = position + self.current_hue = 0 + self.current_saturation = 0.5 + self.current_value = 0.5 + # Offer some standard hooks to the user. + self.on_change = lambda color_picker, r, g, b: None + + def _setup(self): + """ Setup this UI component. + """ + # Setup the hue bar + self.HueBar = vtk.vtkScalarBarActor() + self.HueBar.GetPositionCoordinate().SetCoordinateSystemToDisplay() + self.HueBar.GetPosition2Coordinate().SetCoordinateSystemToDisplay() + self.HueBar.SetNumberOfLabels(0) + hueLut = vtk.vtkLookupTable() + hueLut.SetTableRange(0, 1) + hueLut.SetHueRange(0, 1) + hueLut.SetSaturationRange(1, 1) + hueLut.SetValueRange(1, 1) + hueLut.Build() + self.HueBar.SetLookupTable(hueLut) + self.add_callback(self.HueBar, "MouseMoveEvent", + self.hue_select_callback) + # Setup colors for the square + colors = vtk.vtkUnsignedCharArray() + colors.SetNumberOfComponents(3) + colors.SetName("Colors") + colors.InsertNextTuple3(*self.hsv2rgb(0, 0, 0)) + colors.InsertNextTuple3(*self.hsv2rgb(0, 1, 0)) + colors.InsertNextTuple3(*self.hsv2rgb(0, 1, 1)) + colors.InsertNextTuple3(*self.hsv2rgb(0, 0, 1)) + # Setup the square + self.ColorSelectionSquare = Rectangle2D() + self.ColorSelectionSquare._polygonPolyData.GetPointData().\ + SetScalars(colors) + if VTK_MAJOR_VERSION <= 5: + self.ColorSelectionSquare._polygonPolyData.Update() + self.ColorSelectionSquare.on_left_mouse_button_dragged = \ + self.color_select_callback + # Setup the circle pointer + self.pointer = Disk2D(outer_radius=1) + + def _get_actors(self): + """ Get the actors composing this UI component. + """ + return self.ColorSelectionSquare.actors + self.HueBar +\ + self.pointer.actors + + def _add_to_scene(self, scene): + """Add all subcomponents or VTK props that compose this UI component. + + Parameters + ---------- + scene : scene + """ + self.ColorSelectionSquare.add(scene) + self.pointer.add(scene) + scene.add(self.HueBar) + # def _add_to_renderer(self, ren): + # """ Add all subcomponents or VTK props that compose this UI component. + # Parameters + # ---------- + # ren : renderer + # """ + # self.ColorSelectionSquare.add_to_renderer(ren) + # self.pointer.add_to_renderer(ren) + # ren.add(self.HueBar) + + def _get_size(self): + return (6*self.side/5, self.side) + + @property + def side(self): + return self.HueBar.GetPosition2()[1] + + @side.setter + def side(self, side): + self.HueBar.SetPosition2(side / 5, side) + self.ColorSelectionSquare.resize((side, side)) + self.pointer.outer_radius = side/50 + self.pointer.inner_radius = side/50 - 1 + + @property + def current_hue(self): + color = self.ColorSelectionSquare._polygonPolyData.GetPointData().\ + GetScalars().GetTuple(2) + return self.rgb2hsv(*color)[0] + + @current_hue.setter + def current_hue(self, hue): + colors = vtk.vtkUnsignedCharArray() + colors.SetNumberOfComponents(3) + colors.SetName("Colors") + colors.InsertNextTuple3(*self.hsv2rgb(hue, 0, 0)) + colors.InsertNextTuple3(*self.hsv2rgb(hue, 1, 0)) + colors.InsertNextTuple3(*self.hsv2rgb(hue, 1, 1)) + colors.InsertNextTuple3(*self.hsv2rgb(hue, 0, 1)) + self.ColorSelectionSquare._polygonPolyData.GetPointData().\ + SetScalars(colors) + if VTK_MAJOR_VERSION <= 5: + self.ColorSelectionSquare._polygonPolyData.Update() + + def rgb2hsv(self, R, G, B): + """ Function to convert given RGB value to HSV + Parameters + ---------- + R : float[0-255] + Red value. + G : float[0-255] + Green value. + B : float[0-255] + Blue value. + """ + (r, g, b) = (R/255, G/255, B/255) + cmax = max(r, g, b) + cmin = min(r, g, b) + delta = cmax - cmin + if delta == 0: + H = 0 + elif cmax == r: + H = 60*(((g-b)/delta) % 6) + elif cmax == g: + H = 60*(((b-r)/delta)+2) + elif cmax == b: + H = 60*(((r-g)/delta)+4) + if cmax == 0: + S = 0 + else: + S = delta/cmax + V = cmax + return H, S, V + + def hsv2rgb(self, H, S, V): + """ Function to convert given HSV value to RGB + Parameters + ---------- + H : float[0-360] + Hue. + S : float[0-1] + Saturation. + V : float[0-1] + Value. + """ + C = V * S + X = C * (1 - abs((H / 60) % 2 - 1)) + m = V - C + if H < 60: + (r, g, b) = (C, X, 0) + elif H < 120: + (r, g, b) = (X, C, 0) + elif H < 180: + (r, g, b) = (0, C, X) + elif H < 240: + (r, g, b) = (0, X, C) + elif H < 300: + (r, g, b) = (X, 0, C) + else: + (r, g, b) = (C, 0, X) + (R, G, B) = ((r+m)*255, (g+m)*255, (b+m)*255) + return R, G, B + + def _set_position(self, coords): + """ Position the lower-left corner of this UI component. + Parameters + ---------- + coords: (float, float) + Absolute pixel coordinates (x, y). + """ + offset = coords - self.position + self.ColorSelectionSquare.position = coords + self.pointer.center += offset + self.HueBar.SetPosition(coords[0] + self.side, coords[1]) + + def hue_select_callback(self, i_ren, obj, color_picker): + """ A callback to select the hue from the hue bar. + Parameters + ---------- + i_ren: :class:`CustomInteractorStyle` + obj: :class:`vtkActor` + The picked actor + color_picker: :class:`ColorPicker` + """ + FractionalHue = (i_ren.event.position[1] - self.position[1])/self.side + self.current_hue = FractionalHue * 360 + self.on_change( + self, *self.hsv2rgb(self.current_hue, self.current_saturation, + self.current_value)) + i_ren.force_render() + i_ren.event.abort() + + def color_select_callback(self, i_ren, obj, rectangle2d): + """ A callback to select the hue and saturation from the sqaure. + Parameters + ---------- + i_ren: :class:`CustomInteractorStyle` + obj: :class:`vtkActor` + The picked actor + rectangle2d: :class:`Rectangle2D` + """ + coords = i_ren.event.position + # Ensure coords are within the square + coords = np.maximum(coords, self.position) + coords = np.minimum(coords, self.position + self.side) + self.pointer.center = coords + relative_coords = coords - self.position + self.current_saturation, self.current_value = relative_coords/self.side + self.on_change( + self, *self.hsv2rgb(self.current_hue, self.current_saturation, + self.current_value)) + i_ren.force_render() + i_ren.event.abort() From 2a68d252858ba7d99e666d1ee10215580d882127 Mon Sep 17 00:00:00 2001 From: Saranjeet Singh Saluja Date: Wed, 3 Aug 2022 19:00:19 -0400 Subject: [PATCH 09/10] Removed position parameter from super.. --- fury/ui/elements.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fury/ui/elements.py b/fury/ui/elements.py index 221c16367..b32aa9ed6 100644 --- a/fury/ui/elements.py +++ b/fury/ui/elements.py @@ -3501,7 +3501,7 @@ def __init__(self, side=100, position=(0, 0)): position : (float, float) Coordinates (x, y) of the lower-left corner of the sqaure. """ - super(ColorPicker, self).__init__(position) + super(ColorPicker, self).__init__() self.side = side self.pointer.position = self.ColorSelectionSquare.center self.position = position From 7dc25e0a11a125fb483b589adba5e6560e267bca Mon Sep 17 00:00:00 2001 From: Saranjeet Singh Saluja Date: Thu, 4 Aug 2022 17:35:27 -0400 Subject: [PATCH 10/10] Updated old functions to newer updated versions - ColorPicker --- fury/ui/elements.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/fury/ui/elements.py b/fury/ui/elements.py index b32aa9ed6..0f82e5d17 100644 --- a/fury/ui/elements.py +++ b/fury/ui/elements.py @@ -20,6 +20,8 @@ from fury.ui.core import Button2D from fury.utils import (set_polydata_vertices, vertices_from_actor, update_actor) +# this line was changed +from fury.lib import ScalarBarActor, LookupTable, UnsignedCharArray, VTK_VERSION class TextBox2D(UI): @@ -3492,7 +3494,7 @@ class ColorPicker(UI): a square that selects the saturation and value for the selected hue. """ - def __init__(self, side=100, position=(0, 0)): + def __init__(self, position=(0, 0)): """ Initialize the color picker. Parameters ---------- @@ -3501,8 +3503,8 @@ def __init__(self, side=100, position=(0, 0)): position : (float, float) Coordinates (x, y) of the lower-left corner of the sqaure. """ - super(ColorPicker, self).__init__() - self.side = side + super(ColorPicker, self).__init__(position) + self.side = 100 self.pointer.position = self.ColorSelectionSquare.center self.position = position self.current_hue = 0 @@ -3515,11 +3517,12 @@ def _setup(self): """ Setup this UI component. """ # Setup the hue bar - self.HueBar = vtk.vtkScalarBarActor() + # this line was changed + self.HueBar = ScalarBarActor() self.HueBar.GetPositionCoordinate().SetCoordinateSystemToDisplay() self.HueBar.GetPosition2Coordinate().SetCoordinateSystemToDisplay() self.HueBar.SetNumberOfLabels(0) - hueLut = vtk.vtkLookupTable() + hueLut = LookupTable() # this line was changed hueLut.SetTableRange(0, 1) hueLut.SetHueRange(0, 1) hueLut.SetSaturationRange(1, 1) @@ -3529,7 +3532,7 @@ def _setup(self): self.add_callback(self.HueBar, "MouseMoveEvent", self.hue_select_callback) # Setup colors for the square - colors = vtk.vtkUnsignedCharArray() + colors = UnsignedCharArray() # this line was changed colors.SetNumberOfComponents(3) colors.SetName("Colors") colors.InsertNextTuple3(*self.hsv2rgb(0, 0, 0)) @@ -3540,8 +3543,8 @@ def _setup(self): self.ColorSelectionSquare = Rectangle2D() self.ColorSelectionSquare._polygonPolyData.GetPointData().\ SetScalars(colors) - if VTK_MAJOR_VERSION <= 5: - self.ColorSelectionSquare._polygonPolyData.Update() + # if int(VTK_VERSION) <= 5: + # self.ColorSelectionSquare._polygonPolyData.Update() self.ColorSelectionSquare.on_left_mouse_button_dragged = \ self.color_select_callback # Setup the circle pointer @@ -3560,8 +3563,8 @@ def _add_to_scene(self, scene): ---------- scene : scene """ - self.ColorSelectionSquare.add(scene) - self.pointer.add(scene) + self.ColorSelectionSquare._add_to_scene(scene) # this line was changed + self.pointer._add_to_scene(scene) # this line was changed scene.add(self.HueBar) # def _add_to_renderer(self, ren): # """ Add all subcomponents or VTK props that compose this UI component. @@ -3595,7 +3598,7 @@ def current_hue(self): @current_hue.setter def current_hue(self, hue): - colors = vtk.vtkUnsignedCharArray() + colors = UnsignedCharArray() # this line was changed colors.SetNumberOfComponents(3) colors.SetName("Colors") colors.InsertNextTuple3(*self.hsv2rgb(hue, 0, 0)) @@ -3604,8 +3607,8 @@ def current_hue(self, hue): colors.InsertNextTuple3(*self.hsv2rgb(hue, 0, 1)) self.ColorSelectionSquare._polygonPolyData.GetPointData().\ SetScalars(colors) - if VTK_MAJOR_VERSION <= 5: - self.ColorSelectionSquare._polygonPolyData.Update() + # if int(VTK_VERSION) <= 5: # this line was changed + # self.ColorSelectionSquare._polygonPolyData.Update() def rgb2hsv(self, R, G, B): """ Function to convert given RGB value to HSV