Skip to content

Commit

Permalink
Overhaul all the visual classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Oct 29, 2023
1 parent d0a2db1 commit 34b6b8e
Show file tree
Hide file tree
Showing 11 changed files with 1,906 additions and 273 deletions.
61 changes: 47 additions & 14 deletions colour_visuals/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,22 @@
import numpy as np
import pygfx as gfx
from colour.hints import LiteralColourspaceModel
from colour.models import COLOURSPACE_MODELS, COLOURSPACE_MODELS_AXIS_LABELS
from colour.models import COLOURSPACE_MODELS_AXIS_LABELS
from colour.plotting import (
CONSTANTS_COLOUR_STYLE,
colourspace_model_axis_reorder,
)
from colour.utilities import as_int_array, validate_method
from colour.utilities import as_int_array

from colour_visuals.common import (
DEFAULT_FLOAT_DTYPE_WGPU,
unlatexify,
)
from colour_visuals.visual import (
MixinPropertyModel,
MixinPropertySize,
Visual,
)

__author__ = "Colour Developers"
__copyright__ = "Copyright 2023 Colour Developers"
Expand All @@ -35,7 +40,7 @@
__all__ = ["VisualAxes"]


class VisualAxes(gfx.Group):
class VisualAxes(MixinPropertyModel, MixinPropertySize, Visual):
"""
Create an axes visual.
Expand All @@ -47,6 +52,16 @@ class VisualAxes(gfx.Group):
size
Size of the axes.
Attributes
----------
- :attr:`~colour_visuals.VisualAxes.model`
- :attr:`~colour_visuals.VisualAxes.size`
Methods
-------
- :meth:`~colour_visuals.VisualAxes.__init__`
- :meth:`~colour_visuals.VisualAxes.update`
Examples
--------
>>> import os
Expand Down Expand Up @@ -80,8 +95,24 @@ def __init__(
):
super().__init__()

size = int(size)
model = validate_method(model, tuple(COLOURSPACE_MODELS))
self._axes_helper = None
self._x_text = None
self._y_text = None
self._z_text = None

with self.block_update():
self.model = model
self.size = size

self.update()

def update(self):
"""Update the visual."""

if self._is_update_blocked:
return

self.clear()

axes_positions = np.array(
[
Expand All @@ -94,7 +125,7 @@ def __init__(
],
dtype=DEFAULT_FLOAT_DTYPE_WGPU,
)
axes_positions *= size
axes_positions *= int(self._size)

axes_colours = np.array(
[
Expand All @@ -114,8 +145,10 @@ def __init__(
)
self.add(self._axes_helper)

labels = np.array(COLOURSPACE_MODELS_AXIS_LABELS[model])[
as_int_array(colourspace_model_axis_reorder([0, 1, 2], model))
labels = np.array(COLOURSPACE_MODELS_AXIS_LABELS[self._model])[
as_int_array(
colourspace_model_axis_reorder([0, 1, 2], self._model)
)
]

self._x_text = gfx.Text(
Expand All @@ -125,9 +158,9 @@ def __init__(
screen_space=True,
anchor="Middle-Center",
),
gfx.TextMaterial(color=np.array([1, 0, 0])), # pyright: ignore
gfx.TextMaterial(color=np.array([1, 0, 0])),
)
self._x_text.local.position = np.array([1.1, 0, 0])
self._x_text.local.position = np.array([1 * self._size * 1.05, 0, 0])
self.add(self._x_text)

self._y_text = gfx.Text(
Expand All @@ -137,9 +170,9 @@ def __init__(
screen_space=True,
anchor="Middle-Center",
),
gfx.TextMaterial(color=np.array([0, 1, 0])), # pyright: ignore
gfx.TextMaterial(color=np.array([0, 1, 0])),
)
self._y_text.local.position = np.array([0, 1.1, 0])
self._y_text.local.position = np.array([0, 1 * self._size * 1.05, 0])
self.add(self._y_text)

self._z_text = gfx.Text(
Expand All @@ -149,9 +182,9 @@ def __init__(
screen_space=True,
anchor="Middle-Center",
),
gfx.TextMaterial(color=np.array([0, 0, 1])), # pyright: ignore
gfx.TextMaterial(color=np.array([0, 0, 1])),
)
self._z_text.local.position = np.array([0, 0, 1.1])
self._z_text.local.position = np.array([0, 0, 1 * self._size * 1.05])
self.add(self._z_text)


Expand Down
1 change: 1 addition & 0 deletions colour_visuals/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"unlatexify",
]


DEFAULT_FLOAT_DTYPE_WGPU = np.float32
"""Default int number dtype."""

Expand Down
Loading

0 comments on commit 34b6b8e

Please sign in to comment.