-
Notifications
You must be signed in to change notification settings - Fork 123
/
test_visual_voxels.py
139 lines (79 loc) · 2.89 KB
/
test_visual_voxels.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import numpy as np
import pytest
from math import sqrt, sin, cos
import k3d
from .plot_compare import *
color_map = (0xffff00, 0xff0000, 0x00ff00)
def r(x, y, z, width=100, height=100, length=100):
r = sqrt((x - width / 2) * (x - width / 2) + (y - height / 2) * (y - height / 2) + (
z - length / 2) * (z - length / 2))
r += sin(x / 2) * 3
r += cos(y / 10) * 5
return r
def f(x, y, z, width=100, height=100, length=100):
return 0 if r(x, y, z, width, height, length) > width / 2 else (
1 if z + sin(x / 20) * 10 > length / 2 else 2)
voxels = np.array(
[[[f(x, y, z, 100, 100, 100) for x in range(100)] for y in range(100)] for z in range(100)])
def test_voxels():
global color_map, voxels
prepare()
obj = k3d.voxels(voxels.astype(np.uint8), color_map, outlines=False)
pytest.plot += obj
compare('voxels')
obj.opacity = 0.5
compare('voxels_dynamic_opacity')
def test_voxels_sparse():
global color_map, voxels
prepare()
sparse_data = []
for val in np.unique(voxels):
if val != 0:
z, y, x = np.where(voxels == val)
sparse_data.append(
np.dstack((x, y, z, np.full(x.shape, val))).reshape(-1, 4).astype(np.uint16))
sparse_data = np.vstack(sparse_data)
obj = k3d.sparse_voxels(sparse_data, (100, 100, 100), color_map, outlines=False)
pytest.plot += obj
compare('voxels_sparse')
obj.opacity = 0.5
compare('voxels_sparse_dynamic_opacity')
def test_voxels_wireframe():
global color_map, voxels
prepare()
obj = k3d.voxels(voxels.astype(np.uint8), color_map, outlines=False, wireframe=True)
pytest.plot += obj
compare('voxels_wireframe')
def test_voxels_outline():
global color_map, voxels
prepare()
obj = k3d.voxels(voxels.astype(np.uint8), color_map, outlines=True)
pytest.plot += obj
compare('voxels_outline')
obj.outlines_color = 0xff0000
compare('voxels_outline_dynamic_outlines_color')
def test_voxels_outline_opacity():
global color_map, voxels
prepare()
obj = k3d.voxels(voxels.astype(np.uint8), color_map, outlines=True, opacity=0.5)
pytest.plot += obj
compare('voxels_outline_opacity')
def test_voxels_outline_clipping_plane():
global color_map, voxels
prepare()
obj = k3d.voxels(voxels.astype(np.uint8), color_map, outlines=True)
pytest.plot += obj
pytest.plot.clipping_planes = [
[-1, 0, -1, 50]
]
compare('voxels_outline_clipping_plane')
def test_voxels_box():
global color_map, voxels
prepare()
width, height, length = 200, 50, 100
box_voxels = voxels = np.array(
[[[f(x, y, z, width, height, length) for x in range(width)] for y in range(height)] for z in
range(length)])
obj = k3d.voxels(box_voxels.astype(np.uint8), color_map, outlines=True)
pytest.plot += obj
compare('voxels_box')