def render(self, camera, zbuffer=None): """Renders an image using the provided camera Parameters ---------- camera: :class:`yt.visualization.volume_rendering.camera.Camera` instance A volume rendering camera. Can be any type of camera. zbuffer: :class:`yt.visualization.volume_rendering.zbuffer_array.Zbuffer` instance A zbuffer array. This is used for opaque sources to determine the z position of the source relative to other sources. Only useful if you are manually calling render on multiple sources. Scene.render uses this internally. Returns ------- A :class:`yt.data_objects.image_array.ImageArray` instance containing the rendered image. """ vertices = self.positions if zbuffer is None: empty = camera.lens.new_image(camera) z = np.empty(empty.shape[:2], dtype='float64') empty[:] = 0.0 z[:] = np.inf zbuffer = ZBuffer(empty, z) else: empty = zbuffer.rgba z = zbuffer.z # DRAW SOME LINES camera.lens.setup_box_properties(camera) px, py, dz = camera.lens.project_to_plane(camera, vertices) px = px.astype('int64') py = py.astype('int64') if len(px.shape) == 1: zlines(empty, z, px, py, dz, self.colors.astype('float64'), self.color_stride) else: # For stereo-lens, two sets of pos for each eye are contained # in px...pz zlines(empty, z, px[0, :], py[0, :], dz[0, :], self.colors.astype('float64'), self.color_stride) zlines(empty, z, px[1, :], py[1, :], dz[1, :], self.colors.astype('float64'), self.color_stride) self.zbuffer = zbuffer return zbuffer
def render(self, camera, zbuffer=None): """Renders an image using the provided camera Parameters ---------- camera: :class:`yt.visualization.volume_rendering.camera.Camera` instance A volume rendering camera. Can be any type of camera. zbuffer: :class:`yt.visualization.volume_rendering.zbuffer_array.Zbuffer` instance A zbuffer array. This is used for opaque sources to determine the z position of the source relative to other sources. Only useful if you are manually calling render on multiple sources. Scene.render uses this internally. Returns ------- A :class:`yt.data_objects.image_array.ImageArray` instance containing the rendered image. """ camera.lens.setup_box_properties(camera) center = camera.focus # Get positions at the focus positions = np.zeros([6, 3]) positions[:] = center # Create vectors in the x,y,z directions for i in range(3): positions[2 * i + 1, i] += camera.width.in_units('code_length').d[i] / 16.0 # Project to the image plane px, py, dz = camera.lens.project_to_plane(camera, positions) if len(px.shape) == 1: dpx = px[1::2] - px[::2] dpy = py[1::2] - py[::2] # Set the center of the coordinates to be in the lower left of the image lpx = camera.resolution[0] / 8 lpy = camera.resolution[ 1] - camera.resolution[1] / 8 # Upside-downsies # Offset the pixels according to the projections above px[::2] = lpx px[1::2] = lpx + dpx py[::2] = lpy py[1::2] = lpy + dpy dz[:] = 0.0 else: # For stereo-lens, two sets of pos for each eye are contained in px...pz dpx = px[:, 1::2] - px[:, ::2] dpy = py[:, 1::2] - py[:, ::2] lpx = camera.resolution[0] / 16 lpy = camera.resolution[ 1] - camera.resolution[1] / 8 # Upside-downsies # Offset the pixels according to the projections above px[:, ::2] = lpx px[:, 1::2] = lpx + dpx px[1, :] += camera.resolution[0] / 2 py[:, ::2] = lpy py[:, 1::2] = lpy + dpy dz[:, :] = 0.0 # Create a zbuffer if needed if zbuffer is None: empty = camera.lens.new_image(camera) z = np.empty(empty.shape[:2], dtype='float64') empty[:] = 0.0 z[:] = np.inf zbuffer = ZBuffer(empty, z) else: empty = zbuffer.rgba z = zbuffer.z # Draw the vectors px = px.astype('int64') py = py.astype('int64') if len(px.shape) == 1: zlines(empty, z, px, py, dz, self.colors.astype('float64'), self.color_stride) else: # For stereo-lens, two sets of pos for each eye are contained # in px...pz zlines(empty, z, px[0, :], py[0, :], dz[0, :], self.colors.astype('float64'), self.color_stride) zlines(empty, z, px[1, :], py[1, :], dz[1, :], self.colors.astype('float64'), self.color_stride) # Set the new zbuffer self.zbuffer = zbuffer return zbuffer