-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvis01b_plot_shapes_pipe00_and_final.py
76 lines (62 loc) · 2.32 KB
/
vis01b_plot_shapes_pipe00_and_final.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
###########################
# Plot in 3D #
###########################
import numpy as np
import os
import vedo
import matplotlib.pyplot as plt
# ==== colors ====
def get_colors(num, cmap, minval=0.0, maxval=1.0, endpoint=True):
'''
:param num: How many colors to return
:param minval, maxval: truncate colormap by choosing numbers between 0 and 1 (untruncated = [0,1])
:param cmap: e.g. 'jet' 'viridis' 'RdBu_r' 'hsv'
:return:
'''
if isinstance(cmap, str):
cmap = plt.get_cmap(cmap) #
return cmap(np.linspace(minval, maxval, num, endpoint=endpoint))
colors = get_colors(42, 'hsv')
# ===== pipe0 =====
# + rescale for comparison
scale = 10 / 170.258 # New legnth [um] / old length [px]
folder = 'res/pipe00' #
iframes_raw = list(range(1, 18, 2)) + [18] + list(range(21, 42, 2))
shapes = []
for iframe_raw in iframes_raw:
xname = os.path.join(folder, 'x-{}.dat'.format(iframe_raw))
yname = os.path.join(folder, 'y-{}.dat'.format(iframe_raw))
zname = os.path.join(folder, 'z-{}.dat'.format(iframe_raw))
xx = scale * np.loadtxt(xname)
yy = scale * np.loadtxt(yname)
zz = scale * np.loadtxt(zname)
cc = colors[iframe_raw] # shapes are starting from 1
c = tuple(cc[:3]) # discard opacity
shape = vedo.Tube(list(zip(zz, xx, yy)), r=0.125, c=c)
shapes += [shape]
# ===== final =====
# + shift
folder = 'res/pipe_final' #
iframes_raw = list(range(20))
x = np.loadtxt(os.path.join(folder, 'x-data'))
y = np.loadtxt(os.path.join(folder, 'y-data'))
z = np.loadtxt(os.path.join(folder, 'z-data'))
# Add shapes
# Shift them and rescale for easier comparison
x0, y0 = 20, 0
for iframe_raw, xx, yy, zz in zip(iframes_raw, x, y, z):
cc = colors[iframe_raw] # shapes are starting from 1
c = tuple(cc[:3]) # discard opacity
shape = vedo.Tube(list(zip(xx + x0, yy + y0, zz)), r=0.125, c=c)
shapes += [shape]
# Add plane
plane = vedo.Plane(pos=(0, 0, 0), normal=(0, 0, 1), sx=50).alpha(0.5)
shapes += [plane]
# Plot
size = 256 * np.array([4, 3]) # window size # 256
offscreen = False # Hide
interactive = False # should be false to execute the whole script
plotter = vedo.plotter.Plotter(pos=(100, 0), interactive=interactive,
size=size, offscreen=offscreen, axes=4)
plotter.add(shapes, render=False)
plotter.show(interactive=True).close()