How to use a mask for mesh sections of mayavi?

I use python and mayavi2 for 3D building. I draw a sphere using the mesh command, and now I want to color some of the sphere panels with a different color. This seems to be a variant of the mask, but I can't get it to work (I just get the whole color of the sphere).

http://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html#mayavi.mlab.mesh "mask: an array of boolean masks to suppress some data points"

I use:

mesh(X,Y,Z, color = (1,1,1), opacity=0.5)

to paint the whole sphere white and then

mesh(X,Y,Z, color = (1,0,1), mask = active_region, opacity=0.5) 

for coloring some parts of the purple color where

active_region = [[False False False False False False  True]
                 [False False False False False False  True]
                 [False False False False False  True  True]
                 [False False False  True  True  True  True]
                 [False False  True  True  True  True  True]
                 [False False False  True  True  True  True]
                 [False False False False False False  True]]

but this leads to a completely purple sphere. X, Y and Z are all arrays with form (7,7), like active_region. What am I doing wrong?

+4
1

, . :

import numpy as np
m = mesh(X,Y,Z, mask=active_region, opacity=0.5)
m.mlab_source = ones_like(X)

, Nan, . , , .

, :

import numpy as np
phi, theta = np.mgrid[0:np.pi:100j, 0:2 * np.pi:100j]
x = np.sin(phi) * np.cos(theta)
y = np.sin(phi) * np.sin(theta)
z = np.cos(phi)
mask = np.zeros_like(x).astype(bool)
mask[::5] = True
mask[:,::5] = True

from mayavi import mlab
mlab.mesh(x, y, z, scalars=z, mask=mask)

, , , , . , z, , ones_like(X).

, VTK 5.6, , , VTK 5.10, :

m = mlab.mesh(x, y, z, scalars=scalars, mask=mask)
m.module_manager.scalar_lut_manager.lut.nan_color = 0, 0, 0, 0

scalar=z . , " " , " lut". , :

scalars = np.ones_like(x)
m = mlab.mesh(x, y, z, scalars=scalars, mask=mask)
m.module_manager.scalar_lut_manager.lut_mode = 'file'
m.module_manager.scalar_lut_manager.file_name = '/path/to/your.lut'

LUT malarky, numpy, Python.

m = mlab.mesh(x, y, z, scalars=z, mask=mask)
# Lets make some colors:
#    this is an array of (R, G, B, A) values (each in range 0-255), there should
#    be at least 2 colors in the array.
colors = np.zeros((2, 4), dtype='uint8')
# Set the green value to constant.
colors[:,1] = 255
# the alpha value to fully opaque.
colors[:,3] = 255
# Now use this colormap.
m.module_manager.scalar_lut_manager.lut.table = colors

, 2 , . 2 .

.

+3

All Articles