Sample a set of points (with color) on the mesh. Args: mesh: a triangle mesh representing the surface. We assume it only have one texture map cam_pose: a dictionary containing: - intrinsic_matrix: the (3,3) intrinsic matri
(
mesh: o3d.geometry.TriangleMesh,
cam_pose: T.Dict[str, T.Any],
texture_maps: T.List[np.ndarray] = None,
)
| 22 | |
| 23 | |
| 24 | def sample_point_cloud_with_ray_tracing( |
| 25 | mesh: o3d.geometry.TriangleMesh, |
| 26 | cam_pose: T.Dict[str, T.Any], |
| 27 | texture_maps: T.List[np.ndarray] = None, |
| 28 | ) -> T.Dict[str, T.Any]: |
| 29 | """ |
| 30 | Sample a set of points (with color) on the mesh. |
| 31 | |
| 32 | Args: |
| 33 | mesh: |
| 34 | a triangle mesh representing the surface. |
| 35 | We assume it only have one texture map |
| 36 | cam_pose: |
| 37 | a dictionary containing: |
| 38 | - intrinsic_matrix: the (3,3) intrinsic matrix |
| 39 | - extrinsic_matrix: the (4,4) homogeneous matrix (from world to local) |
| 40 | - width_px: number of pixels of the sensor |
| 41 | - height_px: number of pixels of the sensor |
| 42 | texture_maps: |
| 43 | a list of texture maps (h, w, c) that we want to get the values using uv_mapping |
| 44 | For example, if it is the rgb albedo, it is be retrieved with |
| 45 | :py:`texture = np.asarray(mesh.textures[0]) / 255. # (h,w,3)`. |
| 46 | It can also be surface normals, features, etc. |
| 47 | If `None`, not uv interpolation is performed. |
| 48 | Returns: |
| 49 | raycast_results: |
| 50 | the output of `RaycastingScene` |
| 51 | uv_outputs: |
| 52 | a list of uv-interpolated values from each texture map. |
| 53 | """ |
| 54 | |
| 55 | # set up the raycasting scene |
| 56 | mesh_t = o3d.t.geometry.TriangleMesh.from_legacy(mesh) |
| 57 | scene = o3d.t.geometry.RaycastingScene() |
| 58 | mesh_id = scene.add_triangles(mesh_t) |
| 59 | |
| 60 | # create the pinhole camera rays |
| 61 | rays = o3d.t.geometry.RaycastingScene.create_rays_pinhole( |
| 62 | intrinsic_matrix=cam_pose['intrinsic_matrix'], |
| 63 | extrinsic_matrix=cam_pose['extrinsic_matrix'], |
| 64 | width_px=cam_pose['width_px'], |
| 65 | height_px=cam_pose['height_px'], |
| 66 | ) |
| 67 | |
| 68 | # cast the rays, get the intersections |
| 69 | raycast_results = scene.cast_rays(rays) |
| 70 | # if the ray does not hit the mesh, it goes to inf |
| 71 | hit_map = 1 - np.isinf(raycast_results['t_hit'].numpy()) # (h',w') |
| 72 | |
| 73 | if texture_maps is None or len(texture_maps) == 0: |
| 74 | return dict( |
| 75 | hits=hit_map, # (h', w') 1: hit, 0: not hit |
| 76 | rays=rays, # (h', w', 6) x, y, z, dx, dy, dz |
| 77 | raycast_results=raycast_results, |
| 78 | uv_outputs=[], |
| 79 | ) |
| 80 | |
| 81 | uv_outputs = interp_texture_map_from_ray_tracing_results( |
nothing calls this directly
no test coverage detected