def __init__(self, mode="perspective", theta=0, phi=0, scale=1): """ mode : str camera mode ("ortho" or "perspective") theta: float angle around z axis (degrees) phi: float angle around x axis (degrees) scale: float scale factor view : array (4x4) """ self.trackball = Trackball(theta, phi) self.aperture = 35 self.aspect = 1 self.near = 1 self.far = 100 self.mode = mode self.scale = scale self.zoom = 1 self.zoom_max = 5.0 self.zoom_min = 0.1 self.view = glm.translate(0, 0, -3) @ glm.scale(scale) if mode == "ortho": self.proj = glm.ortho(-1, +1, -1, +1, self.near, self.far) else: self.proj = glm.perspective(self.aperture, self.aspect, self.near, self.far) self.transform = self.proj @ self.view @ self.trackball.model.T
# Model loading vertices, faces = obj_load("data/bunny.obj") ax = subplot(221) ax.axis("off") camera = Camera("perspective", -20, 0, 1.5) mesh = Mesh(ax, camera.transform, vertices, faces, linewidths=.5, cmap=plt.get_cmap("magma"), edgecolors=(0, 0, 0, 0.25)) camera.connect(ax, mesh.update) ortho = glm.ortho(-1, +1, -1, +1, 1, 100) @ glm.scale(2) ax = subplot(222) camera = ortho @ glm.xrotate(90) mesh = Mesh(ax, camera, vertices, faces, facecolors=white, edgecolors=black, linewidths=.25) ax.text(.99, .99, "Orthographic (XZ)", transform=ax.transAxes, ha="right",
import matplotlib.pyplot as plt import nibabel as nb fig = plt.figure(figsize=(6, 6)) ax = fig.add_axes([0, 0, 1, 1], xlim=[-1, +1], ylim=[-1, +1], aspect=1) ax.axis("off") vertices, faces = nb.freesurfer.io.read_geometry('data/lh.pial') vertices = glm.fit_unit_cube(vertices) facecolors = lighting(vertices[faces], direction=(-1, 0, 0.25), color=(1.0, 0.5, 0.5), specular=True) camera = glm.ortho(-1, +1, -1, +1, 1, 100) camera = camera @ glm.scale(1.9) @ glm.yrotate(90) @ glm.xrotate(270) start = time.time() Mesh(ax, camera, vertices, faces, facecolors=facecolors, linewidths=0, mode="front") elapsed = time.time() - start text = "{0} vertices, {1} faces rendered in {2:.2f} second(s) with matplotlib" text = text.format(len(vertices), len(faces), elapsed) ax.text(0, 0,