Skip to content

Commit 753569d

Browse files
committed
Squashed commit of the following:
Color animation: press "a" key to flash the colored regions briefly
1 parent 6f086d4 commit 753569d

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ limited to manifold (closed surface) meshes, but can diff anything that
7272
can be rendered, including open surfaces, curves, and points.
7373

7474

75+
### Color animation
76+
77+
Small areas of difference may be difficult to spot under some
78+
circumstances, especially for people with some form of
79+
colorblindness. To help highlight areas of difference, you can press
80+
the "a" key and the colored areas will flash briefly.
81+
82+
<img src="examples/animation.mov" width="30%">
83+
84+
This feature was inspired by the much more sophisticated color
85+
animations for enhancing color vision provided by
86+
[ColorPhi](https://www.colorphi.com).
87+
88+
7589
### Object alignment
7690

7791
In some cases two objects to be compared may be shifted relative to
@@ -127,7 +141,9 @@ above schemes are named "1", "2", and "3" respectively.
127141
### API
128142

129143
The `diff3d` module provides a simple API if you want to integrate it
130-
into your own program. See the code for details.
144+
into your own program. As this is an early version of the program,
145+
I'll try to maintain the stability of these APIs, but I can't
146+
guarantee it. See the code for details.
131147

132148
* `diff3d.from_files` opens a window displaying the diff between two files
133149

@@ -138,3 +154,11 @@ into your own program. See the code for details.
138154
using `pyvista.PolyData.from_regular_faces`
139155

140156
* You can align two meshes without displaying them using `diff3d.align3d`.
157+
158+
159+
### Discussions and Issues
160+
161+
If you would like to report an issue, ask a question, or make a
162+
suggestion you do so through the
163+
[Discussions](https://github.com/bdlucas1/diff3d/discussions) and
164+
[Issues](https://github.com/bdlucas1/diff3d/issues) pages.

diff3d.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 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):
33

44
import pyvista
55

@@ -12,7 +12,7 @@ def from_files(path1, path2, scheme="1", title=None, align=False, width_pcts=Non
1212
title = (path1, path2) if path2 else path1
1313
o1 = load(path1)
1414
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)
1616

1717

1818
# display a window showing the diff between to pyvista objects
@@ -56,12 +56,36 @@ def convert(o):
5656
# completely opaque doesn't work
5757
alpha = min(alpha, 0.99)
5858

59+
# add the meshes
5960
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)
6263
else:
6364
pl.add_mesh(o1)
6465

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+
6589
pl.show()
6690

6791

@@ -236,7 +260,10 @@ def cli():
236260
parser.add_argument("--widths", nargs="*", type=float)
237261
args = parser.parse_args()
238262

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+
)
240267

241268
if __name__ == "__main__":
242269
cli()

examples/animation.mov

530 KB
Binary file not shown.

0 commit comments

Comments
 (0)