enthought / enthought/mayavi

Mapping HSV color scheme to a sphere

Open
#484 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.4k
Forks
316
Avg merge
7h 44m
Merged PRs (30d)
5

Description

Hello, I am trying to map HSV color scheme to a sphere created with mlab.mesh from coordinates calculated by corresponding formulas. So, I need to assign to each point at mesh a corresponding color from HSV, at each point the color can be calculated by azimuth and elevation angles at this point and hsv_to_rgb method from matplotlib.

I was trying to map HSV assuming that Value = Saturation = 1.0, by defining custom LUT and passing the array of azimuthal angles calculated at each point as scalars to mlab.mesh, it works as expected.

```
import numpy as np
from mayavi import mlab
from matplotlib.colors import hsv_to_rgb

np.set_printoptions(precision=2)
np.set_printoptions(suppress=True)

r_num = 10
azth_num = 61

# Make sphere
phi, theta = np.meshgrid(np.linspace(0., np.pi, num=r_num, endpoint=True), \
np.linspace(0, 2*np.pi, num=azth_num, endpoint=True))

x = np.sin(phi) * np.sin(theta)
y = np.sin(phi) * np.cos(theta)
z = np.cos(phi)

azth = np.arctan2(y, x)
azth[np.where(azth < 0)] += 2*np.pi

def _create_lut_hsv():
lut = hsv_to_rgb(np.array([np.linspace(0., 1., num=100, endpoint=True), \
np.ones((100,)), \
np.ones((100,))]).T)
lut = np.hstack((lut, np.ones((100,1))))

return lut * 255

# Display
mlab.figure(1, bgcolor=(1, 1, 1), fgcolor=(0, 0, 0), size=(600, 500))
msh = mlab.mesh(x, y, z, scalars=azth)
msh.module_manager.scalar_lut_manager.lut.table = _create_lut_hsv()
mlab.view()
mlab.show()
```

However, when I am trying to introduce variation along either Value or Saturation by calculating unique index for each point as idx_point_at_meridian * angle_at_meridian which are ascending unique indices at a sphere surface. Then, we create a LUT as a sequence of colors obtained along meridians of HSV.

It is possible to define a 2D colormap or explicitly specify RGB color for each point of a mesh?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.