1
1
# load files and display a window showing the diff
2
- def from_files (path1 , path2 , scheme = "1" , title = None , align = False , width_pcts = None ):
2
+ def from_files (path1 , path2 , title = None , ** kwargs ):
3
3
4
4
import pyvista
5
5
@@ -12,7 +12,7 @@ def from_files(path1, path2, scheme="1", title=None, align=False, width_pcts=Non
12
12
title = (path1 , path2 ) if path2 else path1
13
13
o1 = load (path1 )
14
14
o2 = load (path2 ) if path2 else None
15
- diff (o1 , o2 , scheme = scheme , title = title , align = align , width_pcts = width_pcts )
15
+ diff (o1 , o2 , ** kwargs )
16
16
17
17
18
18
# display a window showing the diff between to pyvista objects
@@ -56,12 +56,36 @@ def convert(o):
56
56
# completely opaque doesn't work
57
57
alpha = min (alpha , 0.99 )
58
58
59
+ # add the meshes
59
60
if o2 :
60
- pl .add_mesh (convert (o1 ), color = color1 , opacity = alpha , ** kwargs )
61
- pl .add_mesh (convert (o2 ), color = color2 , opacity = alpha , ** kwargs )
61
+ a1 = pl .add_mesh (convert (o1 ), color = color1 , opacity = alpha , ** kwargs )
62
+ a2 = pl .add_mesh (convert (o2 ), color = color2 , opacity = alpha , ** kwargs )
62
63
else :
63
64
pl .add_mesh (o1 )
64
65
66
+ # animate (flash) the colors when commanded
67
+ def animate ():
68
+ import time
69
+ secs , hertz = 0.5 , 8 # tune
70
+ frames_per_cycle = 2 # we're simply alternating
71
+ cs1 = [color1 , color2 ]
72
+ cs2 = [color2 , color1 ]
73
+ start = time .time ()
74
+ def set_colors (i ):
75
+ j = (i + 1 ) % frames_per_cycle
76
+ a1 .prop .color = cs1 [j ]
77
+ a2 .prop .color = cs2 [j ]
78
+ frame_rate = hertz * frames_per_cycle
79
+ sleep_time = (start + i / frame_rate ) - time .time ()
80
+ #print(f"{i}, {time.time():.3f} sleep_time {sleep_time:.3f}")
81
+ if sleep_time > 0 :
82
+ time .sleep (sleep_time )
83
+ frames = int (secs * hertz ) * frames_per_cycle
84
+ pl .add_timer_event (frames , 0 , set_colors )
85
+
86
+ # flash colors on press of "a" key
87
+ pl .add_key_event ("a" , animate )
88
+
65
89
pl .show ()
66
90
67
91
@@ -236,7 +260,10 @@ def cli():
236
260
parser .add_argument ("--widths" , nargs = "*" , type = float )
237
261
args = parser .parse_args ()
238
262
239
- from_files (args .file1 , args .file2 , scheme = args .scheme , align = args .align , width_pcts = args .widths )
263
+ from_files (
264
+ args .file1 , args .file2 , scheme = args .scheme ,
265
+ align = args .align , width_pcts = args .widths
266
+ )
240
267
241
268
if __name__ == "__main__" :
242
269
cli ()
0 commit comments