# -*- coding: utf-8 -*-
"""
Gamut View
==========
Defines the *Gamut View* related objects:
- :class:`GamutView`
"""
from __future__ import division, unicode_literals
from collections import OrderedDict, namedtuple
import numpy as np
from vispy.scene.widgets import Label, ViewBox, Widget
from vispy.scene.visuals import GridLines
from colour import RGB_COLOURSPACES
from colour.utilities import is_string
from colour_analysis.cameras import OrbitCamera
from colour_analysis.constants import REFERENCE_COLOURSPACES
from colour_analysis.utilities import Cycle
from colour_analysis.visuals import (
RGB_colourspace_volume_visual, RGB_scatter_visual, axis_visual,
spectral_locus_visual, pointer_gamut_visual, pointer_gamut_hull_visual)
__author__ = 'Colour Developers'
__copyright__ = 'Copyright (C) 2013-2021 - Colour Developers'
__license__ = 'New BSD License - https://opensource.org/licenses/BSD-3-Clause'
__maintainer__ = 'Colour Developers'
__email__ = 'colour-developers@colour-science.org'
__status__ = 'Production'
__all__ = [
'CameraPreset', 'RGB_ColourspaceVisualPreset', 'GridVisualPreset',
'AxisPreset', 'GamutView'
]
CameraPreset = namedtuple(
'CameraPreset',
('name', 'description', 'reference_colourspace', 'fov', 'elevation',
'azimuth', 'distance', 'translate_speed', 'depth_value', 'center', 'up'))
"""
Defines a camera settings preset.
CameraPreset : namedtuple
"""
RGB_ColourspaceVisualPreset = namedtuple(
'RGB_ColourspaceVisualPreset',
('name', 'description', 'segments', 'uniform_colour', 'uniform_opacity',
'wireframe', 'wireframe_colour', 'wireframe_opacity'))
"""
Defines a *RGB* colourspace volume visual style preset.
RGB_ColourspaceVisualPreset : namedtuple
"""
GridVisualPreset = namedtuple('GridVisualPreset',
('name', 'description', 'uniform_colour'))
"""
Defines a grid visual style preset.
GridVisualPreset : namedtuple
"""
AxisPreset = namedtuple(
'AxisPreset', ('name', 'description', 'reference_colourspace', 'scale'))
"""
Defines an axis visual style preset.
AxisPreset : namedtuple
"""
class GamutView(ViewBox):
"""
Defines the *Gamut View*.
Parameters
----------
scene_canvas : SceneCanvas, optional
Current `vispy.scene.SceneCanvas` instance.
image : array_like, optional
Image to use in the view interactions.
input_colourspace : unicode, optional
**{'ITU-R BT.709', 'ACES2065-1', 'ACEScc', 'ACEScg', 'ACESproxy',
'ALEXA Wide Gamut', 'Adobe RGB (1998)', 'Adobe Wide Gamut RGB',
'Apple RGB', 'Best RGB', 'Beta RGB', 'CIE RGB', 'Cinema Gamut',
'ColorMatch RGB', 'DCI-P3', 'DCI-P3+', 'DRAGONcolor', 'DRAGONcolor2',
'Don RGB 4', 'ECI RGB v2', 'ERIMM RGB', 'Ekta Space PS 5', 'Max RGB',
'NTSC', 'Pal/Secam', 'ProPhoto RGB', 'REDcolor', 'REDcolor2',
'REDcolor3', 'REDcolor4', 'RIMM RGB', 'ROMM RGB', 'ITU-R BT.2020',
'Russell RGB', 'S-Gamut', 'S-Gamut3', 'S-Gamut3.Cine', 'SMPTE-C RGB',
'V-Gamut', 'Xtreme RGB', 'sRGB'}**,
:class:`colour.RGB_Colourspace` class instance name defining `image`
argument colourspace.
reference_colourspace : unicode, optional
**{'CIE XYZ', 'CIE xyY', 'CIE Lab', 'CIE Luv', 'CIE UCS', 'CIE UVW',
'IPT', 'Hunter Lab', 'Hunter Rdab'}**,
Reference colourspace to use for colour conversions / transformations.
correlate_colourspace : unicode, optional
See `input_colourspace` argument for possible values, default value is
*ACEScg*.
:class:`colour.RGB_Colourspace` class instance name defining the
comparison / correlate colourspace.
Other Parameters
----------------
\\**kwargs : dict, optional
Keywords arguments passed to
:class:`vispy.scene.widgets.viewbox.Viewbox` class constructor.
Attributes
----------
scene_canvas
image
input_colourspace
reference_colourspace
correlate_colourspace
settings
Methods
-------
toggle_input_colourspace_visual_visibility_action
cycle_input_colourspace_visual_style_action
toggle_correlate_colourspace_visual_visibility_action
cycle_correlate_colourspace_visual_style_action
toggle_RGB_scatter_visual_visibility_action
cycle_RGB_scatter_visual_style_action
toggle_pointer_gamut_visual_visibility_action
cycle_pointer_gamut_visual_style_action
toggle_spectral_locus_visual_visibility_action
cycle_spectral_locus_visual_style_action
toggle_axis_visual_visibility_action
decrease_colourspace_visual_resolution_action
increase_colourspace_visual_resolution_action
"""
def __init__(self,
scene_canvas=None,
image=None,
input_colourspace='ITU-R BT.709',
reference_colourspace='CIE xyY',
correlate_colourspace='ACEScg',
settings=None,
**kwargs):
self._initialised = False
ViewBox.__init__(self, **kwargs)
self.unfreeze()
self._scene_canvas = scene_canvas
self._image = None
self.image = image
self._input_colourspace = None
self.input_colourspace = input_colourspace
self._reference_colourspace = None
self.reference_colourspace = reference_colourspace
self._correlate_colourspace = None
self.correlate_colourspace = correlate_colourspace
self._settings = None
self.settings = settings
self._camera_presets = {}
self._visuals_style_presets = OrderedDict()
self._axis_presets = {}
self._grid = None
self._label = None
self._colourspace_visual_resolution = 16
self._colourspace_visual_resolution_limits = (1, 64)
self._input_colourspace_visual = None
self._correlate_colourspace_visual = None
self._RGB_scatter_visual = None
self._pointer_gamut_visual = None
self._pointer_gamut_hull_visual = None
self._spectral_locus_visual = None
self._grid_visual = None
self._axis_visual = None
self._visuals = ('RGB_scatter_visual', 'input_colourspace_visual',
'correlate_colourspace_visual',
'pointer_gamut_visual', 'pointer_gamut_hull_visual',
'spectral_locus_visual', 'grid_visual', 'axis_visual')
self._visuals_visibility = None
self._create_presets()
self._create_visuals()
self._attach_visuals()
self._create_camera()
self._create_label()
self._initialised = True
@property
def scene_canvas(self):
"""
Property for **self.scene_canvas** attribute.
Returns
-------
SceneCanvas
"""
return self._scene_canvas
@property
def image(self):
"""
Property for **self._image** private attribute.
Returns
-------
array_like
self._image.
"""
return self._image
@image.setter
def image(self, value):
"""
Setter for **self._image** private attribute.
Parameters
----------
value : array_like
Attribute value.
"""
if value is not None:
assert isinstance(value, (tuple, list, np.ndarray, np.matrix)), ((
'"{0}" attribute: "{1}" is not a "tuple", "list", "ndarray" '
'or "matrix" instance!').format('image', value))
self._image = value
if self._initialised:
self._store_visuals_visibility()
self._detach_visuals()
self._create_RGB_scatter_visual(self._image)
self._attach_visuals()
self._restore_visuals_visibility()
self._label_text()
@property
def input_colourspace(self):
"""
Property for **self._input_colourspace**