-
Notifications
You must be signed in to change notification settings - Fork 123
/
test_visual_mip.py
84 lines (57 loc) · 2 KB
/
test_visual_mip.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
import numpy as np
import pytest
import vtk
from vtk.util import numpy_support
import k3d
from .plot_compare import prepare, compare
def test_mip():
prepare()
reader = vtk.vtkXMLImageDataReader()
reader.SetFileName('./test/assets/volume.vti')
reader.Update()
vti = reader.GetOutput()
x, y, z = vti.GetDimensions()
volume_data = numpy_support.vtk_to_numpy(
vti.GetPointData().GetArray(0)
).reshape(-1, y, x).astype(np.float32)
volume = k3d.mip(volume_data, samples=512)
pytest.plot += volume
compare('mip')
def test_mip_opacity_function():
prepare()
reader = vtk.vtkXMLImageDataReader()
reader.SetFileName('./test/assets/volume.vti')
reader.Update()
vti = reader.GetOutput()
x, y, z = vti.GetDimensions()
volume_data = numpy_support.vtk_to_numpy(
vti.GetPointData().GetArray(0)
).reshape(-1, y, x).astype(np.float32)
volume = k3d.mip(volume_data, opacity_function=[0, 0.0, 0.2, 0.5, 1, 1.0], samples=512)
pytest.plot += volume
compare('mip_opacity_function')
def test_mip_mask():
prepare()
reader = vtk.vtkMetaImageReader()
reader.SetFileName('./test/assets/heart.mhd')
reader.Update()
vti = reader.GetOutput()
reader = vtk.vtkMetaImageReader()
reader.SetFileName('./test/assets/mask.mhd')
reader.Update()
mask = reader.GetOutput()
bounds = vti.GetBounds()
x, y, z = vti.GetDimensions()
volume_data = numpy_support.vtk_to_numpy(
vti.GetPointData().GetArray(0)
).reshape(-1, y, x).astype(np.float32)
x, y, z = mask.GetDimensions()
mask_data = numpy_support.vtk_to_numpy(
mask.GetPointData().GetArray(0)
).reshape(-1, y, x).astype(np.uint8)
volume = k3d.mip(volume_data, mask=mask_data, mask_opacities=[1.0, 1.0],
color_range=[0, 700], alpha_coef=200, samples=128, bounds=bounds)
pytest.plot += volume
compare('mip_heart')
volume.mask_opacities = [0.025, 1.0]
compare('mip_heart_dynamic_mask_opacities')