Commit d03b2c05 authored by Jamie Forth's avatar Jamie Forth

t10 demo code comments

parent 6d514510
......@@ -2027,17 +2027,16 @@ TBC
#+begin_src jupyter-python :exports results
import sys
import numpy as np
import PIL
import vispy
from vispy import app, scene
vispy.use(app='Glfw')
# Create a canvas with a 3D viewport
# Create a canvas with a 3D viewport.
canvas = scene.SceneCanvas()
view = canvas.central_widget.add_view()
## Define a scalar field from which we will generate an isosurface
## Define a scalar field from which we will generate an isosurface.
def psi(i, j, k, offset=(25, 25, 50)):
x = i-offset[0]
y = j-offset[1]
......@@ -2051,24 +2050,26 @@ TBC
data = np.abs(np.fromfunction(psi, (50, 50, 100)))
# Create isosurface visual
# Create isosurface visual.
surface = scene.visuals.Isosurface(data, level=data.max()/4.,
color=(0.5, 0.6, 1, 1), shading='smooth',
parent=view.scene)
surface.transform = scene.transforms.STTransform(translate=(-25, -25, -50))
# Add a 3D axis to keep us oriented
# Add a 3D axis to keep us oriented.
axis = scene.visuals.XYZAxis(parent=view.scene)
# Use a 3D camera
# Manual bounds; Mesh visual does not provide bounds yet
# Note how you can set bounds before assigning the camera to the viewbox
# Use a 3D camera.
# Manual bounds; Mesh visual does not provide bounds yet.
# Note how you can set bounds before assigning the camera to the viewbox.
cam = scene.TurntableCamera(elevation=30, azimuth=30)
cam.set_range((-10, 10), (-10, 10), (-10, 10))
view.camera = cam
canvas.show()
app.run()
if __name__ == '__main__':
canvas.show()
if sys.flags.interactive == 0:
app.run()
#+end_src
****** Example :B_onlyenv:
......@@ -2116,24 +2117,27 @@ TBC
****** Demo :noexport:
#+header: :tangle /tmp/iso-surface-mri.py
#+header: :tangle /tmp/vispy-isosurface-mri.py
#+begin_src jupyter-python
import sys
import numpy as np
import vispy
from vispy import app, visuals, scene
from vispy import app, scene
from vispy.visuals.transforms import STTransform
vispy.use(app='Glfw')
# Prepare canvas
# Prepare canvas.
canvas = scene.SceneCanvas(keys='interactive', size=(800, 600))
# Set up a viewbox to display the image with interactive pan/zoom
# Set up a viewbox to display the image with interactive pan/zoom.
view = canvas.central_widget.add_view()
# Load MRI data.
mri = np.load('/home/jamie/src/python/vispy/demo-data/brain/mri.npz')['data']
mri = np.flipud(np.rollaxis(mri, 1))
surface = scene.visuals.Isosurface(mri, level=mri.mean(),
surface = scene.visuals.Isosurface(mri,
level=mri.mean(), # Choose level to visualise as surface.
color=(0.5, 0.6, 1, 1),
shading='smooth',
parent=view.scene)
......@@ -2144,8 +2148,10 @@ TBC
name='Turntable', elevation=90, azimuth=-80)
view.camera = cam
canvas.show()
app.run()
if __name__ == '__main__':
canvas.show()
if sys.flags.interactive == 0:
app.run()
#+end_src
***** TODO Script :script:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment