forked from napari/napari
-
Notifications
You must be signed in to change notification settings - Fork 0
/
surface_texture_and_colors.py
76 lines (63 loc) · 2.13 KB
/
surface_texture_and_colors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
Surface with texture and vertex_colors
======================================
Display a 3D surface with both texture and color maps.
This example demonstrates how surfaces may be colored by:
* setting `vertex_values`, which colors the surface with the selected
`colormap`
* setting `vertex_colors`, which replaces/overrides any color from
`vertex_values`
* setting both `texture` and `texcoords`, which blends a the value from
a texture (image) with the underlying color from `vertex_values` or
`vertex_colors`. Blending is achieved by multiplying the texture color by
the underlying color - an underlying value of "white" will result in the
unaltered texture color.
.. tags:: visualization-nD
"""
import numpy as np
from vispy.io import imread, load_data_file, read_mesh
import napari
# load the model and texture
mesh_path = load_data_file('spot/spot.obj.gz')
vertices, faces, _normals, texcoords = read_mesh(mesh_path)
n = len(vertices)
texture_path = load_data_file('spot/spot.png')
texture = imread(texture_path)
flat_spot = napari.layers.Surface(
(vertices, faces),
translate=(1, 0, 0),
texture=texture,
texcoords=texcoords,
shading="flat",
name="texture only",
)
np.random.seed(0)
plasma_spot = napari.layers.Surface(
(vertices, faces, np.random.random((3, 3, n))),
texture=texture,
texcoords=texcoords,
colormap="plasma",
shading="smooth",
name="vertex_values and texture",
)
rainbow_spot = napari.layers.Surface(
(vertices, faces),
translate=(-1, 0, 0),
texture=texture,
texcoords=texcoords,
# the vertices are _roughly_ in [-1, 1] for this model and RGB values just
# get clipped to [0, 1], adding 0.5 brightens it up a little :)
vertex_colors=vertices + 0.5,
shading="none",
name="vertex_colors and texture",
)
# create the viewer and window
viewer = napari.Viewer(ndisplay=3)
viewer.add_layer(flat_spot)
viewer.add_layer(plasma_spot)
viewer.add_layer(rainbow_spot)
viewer.camera.center = (0.0, 0.0, 0.0)
viewer.camera.angles = (25.0, -50.0, -125.0)
viewer.camera.zoom = 150
if __name__ == '__main__':
napari.run()