def _generate_rays(self): """Generate normalized device coordinate rays for llff.""" if self.split == "test": n_render_poses = self.render_poses.shape[0] self.camtoworlds = np.concatenate([self.render_poses, self.camtoworlds], axis=0) super()._generate_rays() if not self.spherify: ndc_origins, ndc_directions = convert_to_ndc(self.rays.origins, self.rays.directions, self.focal, self.w, self.h) self.rays = utils.Rays( origins=ndc_origins, directions=ndc_directions, viewdirs=self.rays.viewdirs) # Split poses from the dataset and generated poses if self.split == "test": self.camtoworlds = self.camtoworlds[n_render_poses:] split = [np.split(r, [n_render_poses], 0) for r in self.rays] split0, split1 = zip(*split) self.render_rays = utils.Rays(*split0) self.rays = utils.Rays(*split1)
def _generate_rays(self): """Generating rays for all images.""" x, y = np.meshgrid( # pylint: disable=unbalanced-tuple-unpacking np.arange(self.w, dtype=np.float32), # X-Axis (columns) np.arange(self.h, dtype=np.float32), # Y-Axis (rows) indexing="xy") camera_dirs = np.stack([(x - self.w * 0.5) / self.focal, -(y - self.h * 0.5) / self.focal, -np.ones_like(x)], axis=-1) directions = ((camera_dirs[None, Ellipsis, None, :] * self.camtoworlds[:, None, None, :3, :3]).sum(axis=-1)) origins = np.broadcast_to(self.camtoworlds[:, None, None, :3, -1], directions.shape) viewdirs = directions / np.linalg.norm(directions, axis=-1, keepdims=True) self.rays = utils.Rays( origins=origins, directions=directions, viewdirs=viewdirs)