Debian Codegraph @

examples/02-plot/edl.py

raw
1 """
2 .. _edl_example:
3
4 Eye Dome Lighting
5 ~~~~~~~~~~~~~~~~~
6
7 Eye-Dome Lighting (EDL) is a non-photorealistic, image-based shading technique
8 designed to improve depth perception in scientific visualization images.
9 It darkens each pixel based on how much nearer its neighbors are in screen
10 space, which makes depth ordering readable even on flat-shaded geometry or
11 unshaded point clouds. To learn more, see `this blog post`_.
12
13 .. _this blog post: https://blog.kitware.com/eye-dome-lighting-a-non-photorealistic-shading-technique/
14
15 EDL is most useful when standard Lambertian shading is insufficient, for
16 example:
17
18 * Point clouds, which have no surface normals to shade from.
19 * Dense or intertwined geometry where overlapping surfaces collapse into a
20 visually flat mass.
21 * Noisy or raw-scanned meshes with many features at similar depths.
22
23 """
24
25 # %%
26 # Dense branching geometry
27 # ++++++++++++++++++++++++
28 #
29 # The VTK pine root scan is a classic EDL demonstration dataset: a dense
30 # tangle of fine branching structures where depth ordering is hard to read
31 # without extra shading cues.
32
33 # sphinx_gallery_thumbnail_number = 1
34 import pyvista as pv
35 from pyvista import examples
36
37 # sphinx_gallery_start_ignore
38 # lighting does not seem to work in interactive mode
39 PYVISTA_GALLERY_FORCE_STATIC_IN_DOCUMENT = True
40 # sphinx_gallery_end_ignore
41
42 pine_roots = examples.download_pine_roots()
43 pine_roots.plot(eye_dome_lighting=True, color='tan')
44
45
46 # %%
47 # Compare EDL shading side by side with standard shading. The left panel
48 # is rendered with EDL, the right without. EDL reveals which roots lie in
49 # front of which; without it, they collapse into a flat silhouette.
50
51 pl = pv.Plotter(shape=(1, 2), border=False)
52
53 pl.subplot(0, 0)
54 pl.add_mesh(pine_roots, color='tan')
55 pl.enable_eye_dome_lighting()
56 pl.add_text('Eye-Dome Lighting', font_size=24)
57
58 pl.subplot(0, 1)
59 pl.add_mesh(pine_roots, color='tan')
60 pl.add_text('No Eye-Dome Lighting', font_size=24)
61
62 pl.link_views()
63 pl.show()
64
65
66 # %%
67 # Point cloud
68 # +++++++++++
69 #
70 # EDL was originally motivated by the problem of shading point clouds, which
71 # have no surface normals for traditional lighting. This Lidar point cloud
72 # looks ambiguous without shading hints:
73
74 point_cloud = examples.download_lidar()
75
76 pl = pv.Plotter()
77 pl.add_mesh(point_cloud, color='lightblue', point_size=5)
78 pl.show()
79
80
81 # %%
82 # Enable EDL on the renderer via
83 # :func:`pyvista.Renderer.enable_eye_dome_lighting` and the terrain structure
84 # becomes readable.
85
86 pl = pv.Plotter()
87 pl.add_mesh(point_cloud, color='lightblue', point_size=5)
88 pl.enable_eye_dome_lighting()
89 pl.show()
90
91
92 # %%
93 # EDL also works alongside scalar coloring:
94
95 pl = pv.Plotter()
96 pl.add_mesh(point_cloud, scalars='Elevation', point_size=5)
97 pl.enable_eye_dome_lighting()
98 pl.show()
99 # %%
100 # .. tags:: plot