Args: extrinsic intrinsic [4 4] [3 3)] N_samples: same as D int depth_values: [B D] Returns: [3 N_rays N_samples]
(H,W, tgt_to_world, world_to_ref, intrinsic, near_fars_ref, near_fars, N_samples, pad=0, ref_idx=0, use_cpu=False, chunk=-1, idx=-1)
| 241 | return ray_coordinate_world, ray_dir_world, colors, ray_coordinate_ref, depth_candidates, rays_os, rays_depths, ndc_parameters |
| 242 | |
| 243 | def build_rays_test(H,W, tgt_to_world, world_to_ref, intrinsic, near_fars_ref, near_fars, N_samples, pad=0, ref_idx=0, use_cpu=False, chunk=-1, idx=-1): |
| 244 | ''' |
| 245 | |
| 246 | Args: |
| 247 | extrinsic intrinsic [4 4] [3 3)] |
| 248 | N_samples: same as D int |
| 249 | depth_values: [B D] |
| 250 | |
| 251 | Returns: |
| 252 | [3 N_rays N_samples] |
| 253 | ''' |
| 254 | |
| 255 | device = torch.device("cpu") if use_cpu else tgt_to_world.device |
| 256 | if use_cpu: |
| 257 | tgt_to_world,world_to_ref = tgt_to_world.clone().to(device),world_to_ref.clone().to(device) |
| 258 | intrinsic, near_fars_ref, near_fars = intrinsic.clone().to(device),near_fars_ref.clone().to(device),near_fars.clone().to(device) |
| 259 | inv_scale = torch.tensor([W - 1, H - 1]).to(device) |
| 260 | |
| 261 | |
| 262 | ray_coordinate_world, ray_dir_world, colors, depth_candidates = [],[],[],[] |
| 263 | rays_os, rays_ds = [],[] |
| 264 | |
| 265 | intrinsic_render = intrinsic if intrinsic.dim()==2 else intrinsic.mean(0) |
| 266 | rays_o, rays_d, pixel_coordinates = get_rays_mvs(H, W, intrinsic_render, tgt_to_world, isRandom=False, chunk=chunk, idx=idx) |
| 267 | ray_samples = H * W if chunk < 0 else pixel_coordinates.shape[-1] |
| 268 | |
| 269 | |
| 270 | # direction |
| 271 | ray_dir_world.append(rays_d) # toward camera [N_rays 3] |
| 272 | |
| 273 | # position |
| 274 | rays_o = rays_o.reshape(1,3) |
| 275 | rays_o = rays_o.expand(ray_samples, -1) |
| 276 | rays_os.append(rays_o) |
| 277 | |
| 278 | # travel along the rays |
| 279 | near, far = near_fars[0], near_fars[1] |
| 280 | t_vals = torch.linspace(0., 1., steps=N_samples).to(device) |
| 281 | depth_candidate = near * (1. - t_vals) + far * (t_vals) |
| 282 | depth_candidate = depth_candidate.expand([ray_samples, N_samples]) |
| 283 | point_samples = rays_o.unsqueeze(1) + depth_candidate.unsqueeze(-1) * rays_d.unsqueeze(1) # [3 ray_samples N_samples] |
| 284 | depth_candidates.append(depth_candidate) # [ray_samples N_rays] |
| 285 | |
| 286 | # position |
| 287 | near, far = near_fars_ref[ref_idx, 0], near_fars_ref[ref_idx, 1] |
| 288 | ray_coordinate_world.append(point_samples) # [ray_samples N_samples 3] xyz in [0,1] |
| 289 | ray_coordinate_ref = get_ndc_coordinate(world_to_ref, intrinsic, point_samples, inv_scale, near=near, far=far, pad=pad) |
| 290 | |
| 291 | ndc_parameters = {'w2c_ref': world_to_ref, 'intrinsic_ref': intrinsic, 'inv_scale': inv_scale, 'near': near, 'far': far} |
| 292 | depth_candidates = torch.cat(depth_candidates, dim=0) |
| 293 | ray_dir_world = torch.cat(ray_dir_world, dim=0) |
| 294 | ray_coordinate_world = torch.cat(ray_coordinate_world, dim=0) |
| 295 | rays_os = torch.cat(rays_os, dim=0) |
| 296 | |
| 297 | return ray_coordinate_world, ray_dir_world,ray_coordinate_ref, depth_candidates, rays_os, ndc_parameters |
| 298 | |
| 299 | |
| 300 | def build_color_volume(point_samples, pose_ref, imgs, img_feat=None, downscale=1.0, with_mask=False): |
no test coverage detected