Skip to content

Commit

Permalink
update images
Browse files Browse the repository at this point in the history
  • Loading branch information
scottshambaugh committed Dec 28, 2023
1 parent 260ba13 commit 720ce01
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 20 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ axstereo.set_xlabel('X Label')
(line_left, line_right) = axstereo.plot(x, y, z)
```

For 2D plots and anaglyphs, the focal plane can be set with the `z_zero` parameter. This is the z value that will be "on the page" when viewing the stereogram.
For 2D plots and anaglyphs, the focal plane can be set with the `zzero` parameter. This is the z value that will be "on the page" when viewing the stereogram.

```python
axstereo = AxesAnaglyph(z_zero=min(z)) # data will float above the page
axstereo = AxesAnaglyph(z_zero=None) # page will be at the midpoint of the data range (default)
axstereo = AxesAnaglyph(z_zero=max(z)) # data will sink below the page
axstereo = AxesAnaglyph(zzero=min(z)) # data will float above the page
axstereo = AxesAnaglyph(zzero=None) # page will be at the midpoint of the data range (default)
axstereo = AxesAnaglyph(zzero=max(z)) # data will sink below the page
```
<p float="left" align="center">
<img width="750" height="250" src="https://raw.githubusercontent.com/scottshambaugh/mpl_stereo/main/docs/trefoil_anaglyph_z_zero.png">
<img width="750" height="250" src="https://raw.githubusercontent.com/scottshambaugh/mpl_stereo/main/docs/trefoil_anaglyph_zzero.png">
</p>

### Animations
Expand Down Expand Up @@ -144,7 +144,7 @@ These are not [*auto*stereograms](https://en.wikipedia.org/wiki/Autostereogram),
By default, the stereograms are set up for "parallel" viewing method as described above. For "cross-eyed" viewing, initialize with a negative `ipd` parameter. An ipd (Inter-Pupilary Distance) of 65 millimeters is the default, so call `AxesStereo2D(ipd=-65)` for the default cross-eyed viewing.

### Derivation of Geometry
Two eyes with separation `IPD` are looking at a point a distance `z` offset from a focal plane at distance `d`, resulting in view angle `θ`. If this point were projected back to the focal plane, it would be offset by `δ` from where it visually appears on that plane. This offset `δ` is used to displace each point in the stereogram for each eye based on its `z` value to achieve the stereoscopic effect. The `eye_balance` parameter reallocates the total relative displacement of `` between the two eyes.
Two eyes with separation `IPD` are looking at a point a distance `z` offset from a focal plane at distance `d`, resulting in view angle `θ`. If this point were projected back to the focal plane, it would be offset by `δ` from where it visually appears on that plane. This offset `δ` is used to displace each point in the stereogram for each eye based on its `z` value to achieve the stereoscopic effect. The `eye_balance` parameter allocates the total relative displacement of `` between the two eyes.

```
θ = arctan((d - z) / (IPD / 2))
Expand Down
27 changes: 15 additions & 12 deletions docs/gen_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@

N_STEPS = 10

def _cmap_norm(z):
return (z - np.min(z)) / np.ptp(z)

def plot_2d_trefoil(savedir=None, show=True):
x, y, z = trefoil()
axstereo = AxesStereo2D()
axstereo = AxesStereo2D(zscale=2)
axstereo.plot(x, y, z, c='k', alpha=0.2)
axstereo.scatter(x, y, z, c=z, cmap='viridis', s=10)
axstereo.fig.set_size_inches(6, 3)
Expand All @@ -32,7 +35,7 @@ def plot_3d_trefoil(savedir=None, show=True):

def plot_anaglyph_trefoil(savedir=None, show=True):
x, y, z = trefoil()
axstereo = AxesAnaglyph()
axstereo = AxesAnaglyph(zscale=2)
axstereo.plot(x, y, z)
axstereo.scatter(x, y, z, s=10)
axstereo.fig.set_size_inches(3.0, 3)
Expand All @@ -49,7 +52,7 @@ def plot_anaglyph_trefoil_zzero(savedir=None, show=True):
'zzero = None\ndata midpoint at page',
'zzero = max(z)\ndata sinks below page')
for ax, zzero, title in zip(axs, zzeros, titles):
axstereo = AxesAnaglyph(ax=ax, zzero=zzero)
axstereo = AxesAnaglyph(ax=ax, zzero=zzero, zscale=2)
axstereo.plot(x, y, z)
axstereo.scatter(x, y, z, s=10)
axstereo.set_title(title)
Expand All @@ -63,10 +66,10 @@ def plot_anaglyph_trefoil_zzero(savedir=None, show=True):
def animate_2d_trefoil(savedir=None, show=True):
x, y, z = trefoil(0, n_steps=N_STEPS)
cmap = matplotlib.colormaps['viridis']
axstereo = AxesStereo2D()
axstereo = AxesStereo2D(zscale=2)
axstereo.plot(x, y, z, c='k', alpha=0.2)
scatter = axstereo.scatter(x, y, z, s=10)
colors = cmap(z)
colors = cmap(_cmap_norm(z))
for scat in scatter:
scat.set_edgecolor(colors)
scat.set_facecolor(colors)
Expand All @@ -76,10 +79,10 @@ def animate(frame):
x, y, z = trefoil(frame, n_steps=N_STEPS)
x, y, z, _ = sort_by_z(x, y, z, kwargs=dict())
offset_left, offset_right, zlim = calc_2d_offsets(axstereo.eye_balance, z,
axstereo.d, axstereo.ipd)
axstereo.d, axstereo.ipd)
scatter[0].set_offsets(np.stack([x + offset_left, y]).T)
scatter[1].set_offsets(np.stack([x - offset_right, y]).T)
colors = cmap(z)
colors = cmap(_cmap_norm(z))
for scat in scatter:
scat.set_edgecolor(colors)
scat.set_facecolor(colors)
Expand All @@ -101,15 +104,15 @@ def animate_3d_trefoil(savedir=None, show=True):
axstereo = AxesStereo3D()
axstereo.plot(x, y, z, c='k', alpha=0.2)
scatter = axstereo.scatter(x, y, z, s=10)
colors = cmap(z)
colors = cmap(_cmap_norm(z))
for scat in scatter:
scat.set_edgecolor(colors)
scat.set_facecolor(colors)
axstereo.fig.set_size_inches(6, 3)

def animate(frame):
x, y, z = trefoil(frame, n_steps=N_STEPS)
colors = cmap(z)
colors = cmap(_cmap_norm(z))
for scat in scatter:
scat._offsets3d = (x, y, z)
scat.set_edgecolor(colors)
Expand All @@ -132,7 +135,7 @@ def gen_logo(savedir=None, show=True):
y = np.roll(y, n_roll)
z = np.roll(z, n_roll)

axstereo = AxesAnaglyph(ipd=150)
axstereo = AxesAnaglyph(ipd=150, zscale=2)
axstereo.plot(x, y, z, linewidth=6)
axstereo.set_xlim(-4.5, 4.5)
axstereo.set_ylim(-4.5, 4.5)
Expand All @@ -158,7 +161,7 @@ def gen_logo_with_text(savedir=None, show=True):
def plot_2d_sun(savedir=None, show=True):
sun_left_data, sun_right_data = sun_left_right()

axstereo = AxesStereo2D()
axstereo = AxesStereo2D(zscale=2)
axstereo.ax_left.imshow(sun_left_data, cmap='gray')
axstereo.ax_right.imshow(sun_right_data, cmap='gray')
axstereo.fig.set_size_inches(6, 3)
Expand All @@ -169,7 +172,7 @@ def plot_2d_sun(savedir=None, show=True):

def plot_anaglyph_sun(savedir=None, show=True):
sun_left_data, sun_right_data = sun_left_right()
axstereo = AxesAnaglyph()
axstereo = AxesAnaglyph(zscale=2)
axstereo.imshow_stereo(sun_left_data, sun_right_data)
axstereo.fig.set_size_inches(3, 3)
if savedir is not None:
Expand Down
Binary file modified docs/mpl_stereo_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/mpl_stereo_logo_with_text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/trefoil_2d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/trefoil_2d_animation.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/trefoil_3d_animation.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/trefoil_anaglyph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/trefoil_anaglyph_z_zero.png
Binary file not shown.
Binary file added docs/trefoil_anaglyph_zzero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/mpl_stereo/AxesStereo.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ def __init__(self,
zscale: Optional[float] = None,
zlim: Optional[tuple[float, float]] = None,
zzero: Optional[float] = None,
colors: list[str] = ['red', 'cyan']):
colors: list[str, str] = ['red', 'cyan']):
"""
A class for creating anaglyph plots, that are viewed with red-cyan
"3D glasses". Note that anaglyph plots need to be 2D. Also, any color
Expand Down Expand Up @@ -672,7 +672,7 @@ def __init__(self,
data float above the page, or set to max(z) to have all the data
sink into the page. If None (default), will be set to the midpoint
of the z range.
colors : list[str]
colors : list[str, str]
Colors for the left and right axes. Default is ['red', 'cyan'].
The color ordering refers to the left and right glasses lens colors.
Because that color prevents that eye from seeing that color data,
Expand Down

0 comments on commit 720ce01

Please sign in to comment.