diff --git a/cpp/open3d/t/geometry/RaycastingScene.cpp b/cpp/open3d/t/geometry/RaycastingScene.cpp index 4774beeafa4..8218b6bf93c 100644 --- a/cpp/open3d/t/geometry/RaycastingScene.cpp +++ b/cpp/open3d/t/geometry/RaycastingScene.cpp @@ -868,7 +868,8 @@ RaycastingScene::ListIntersections(const core::Tensor& rays, // generate results structure std::unordered_map result; - shape[0] = shape[0] + 1; + shape.clear(); + shape.push_back(num_rays + 1); result["ray_splits"] = core::Tensor(shape, core::UInt32); uint32_t* ptr = result["ray_splits"].GetDataPtr(); ptr[0] = 0; diff --git a/cpp/open3d/t/geometry/RaycastingScene.h b/cpp/open3d/t/geometry/RaycastingScene.h index f18e4ae3e62..1d81688d658 100644 --- a/cpp/open3d/t/geometry/RaycastingScene.h +++ b/cpp/open3d/t/geometry/RaycastingScene.h @@ -105,11 +105,13 @@ class RaycastingScene { const int nthreads = 0); /// \brief Computes the closest points on the surfaces of the scene. - /// \param query_points A tensor with >=2 dims, shape {.., 3} and Dtype - /// Float32 describing the query points. {..} can be any number of - /// dimensions, e.g., to organize the query_point to create a 3D grid the - /// shape can be {depth, height, width, 3}. The last dimension must be 3 and - /// has the format [x, y, z]. + /// \param rays A tensor with >=2 dims, shape {.., 6}, and Dtype Float32 + /// describing the rays. + /// {..} can be any number of dimensions, e.g., to organize rays for + /// creating an image the shape can be {height, width, 6}; + /// The last dimension must be 6 and has the format [ox, oy, oz, dx, dy, dz] + /// with [ox,oy,oz] as the origin and [dx,dy,dz] as the direction. It is not + /// necessary to normalize the direction. /// \param nthreads The number of threads to use. Set to 0 for automatic. /// \return The returned dictionary contains: /// - \b points A tensor with the closest surface points. The shape @@ -126,26 +128,29 @@ class RaycastingScene { const core::Tensor &rays, const int nthreads = 0); /// \brief Lists the intersections of the rays with the scene - /// \param query_points A tensor with >=2 dims, shape {.., 3} and Dtype - /// Float32 describing the query points. {..} can be any number of - /// dimensions, e.g., to organize the query_point to create a 3D grid the - /// shape can be {depth, height, width, 3}. The last dimension must be 3 and - /// has the format [x, y, z]. + /// \param rays A tensor with >=2 dims, shape {.., 6}, and Dtype Float32 + /// describing the rays; {..} can be any number of dimensions. + /// The last dimension must be 6 and has the format [ox, oy, oz, dx, dy, dz] + /// with [ox,oy,oz] as the origin and [dx,dy,dz] as the direction. It is not + /// necessary to normalize the direction although it should be normalised if + /// t_hit is to be calculated in coordinate units. /// \param nthreads The number of threads to use. Set to 0 for automatic. - /// \return The returned dictionary contains: - /// - \b ray_ids A tensor with ray IDs. The shape is {..}. + /// \return The returned dictionary contains: /// /// - \b ray_splits A tensor with ray intersection splits. Can be /// used to iterate over all intersections for each ray. The shape - /// is {..}. + /// is {num_rays + 1}. + /// - \b ray_ids A tensor with ray IDs. The shape is + /// {num_intersections}. + /// - \b t_hit A tensor with the distance to the hit. The shape is + /// {num_intersections}. /// - \b geometry_ids A tensor with the geometry IDs. The shape is - /// {..}. + /// {num_intersections}. /// - \b primitive_ids A tensor with the primitive IDs, which - /// corresponds to the triangle index. The shape is {..}. + /// corresponds to the triangle index. The shape is + /// {num_intersections}. /// - \b primitive_uvs A tensor with the barycentric coordinates of /// the intersection points within the triangles. The shape is - /// {.., 2}. - /// - \b t_hit A tensor with the distance to the hit. The shape is - /// {..}. + /// {num_intersections, 2}. std::unordered_map ComputeClosestPoints( const core::Tensor &query_points, const int nthreads = 0); diff --git a/cpp/pybind/t/geometry/raycasting_scene.cpp b/cpp/pybind/t/geometry/raycasting_scene.cpp index 8f7355600ae..e7f6dcecbd5 100644 --- a/cpp/pybind/t/geometry/raycasting_scene.cpp +++ b/cpp/pybind/t/geometry/raycasting_scene.cpp @@ -231,9 +231,7 @@ Lists the intersections of the rays with the scene:: Args: rays (open3d.core.Tensor): A tensor with >=2 dims, shape {.., 6}, and Dtype - Float32 describing the rays. - {..} can be any number of dimensions, e.g., to organize rays for - creating an image the shape can be {height, width, 6}. + Float32 describing the rays; {..} can be any number of dimensions. The last dimension must be 6 and has the format [ox, oy, oz, dx, dy, dz] with [ox,oy,oz] as the origin and [dx,dy,dz] as the direction. It is not necessary to normalize the direction although it should be normalised if @@ -244,25 +242,26 @@ Lists the intersections of the rays with the scene:: Returns: The returned dictionary contains + ray_splits + A tensor with ray intersection splits. Can be used to iterate over all intersections for each ray. The shape is {num_rays + 1}. + ray_ids - A tensor with ray IDs. The shape is {..}. + A tensor with ray IDs. The shape is {num_intersections}. - ray_splits - A tensor with ray intersection splits. Can be used to iterate over all intersections for each ray. The shape is {..}. + t_hit + A tensor with the distance to the hit. The shape is {num_intersections}. geometry_ids - A tensor with the geometry IDs. The shape is {..}. + A tensor with the geometry IDs. The shape is {num_intersections}. primitive_ids A tensor with the primitive IDs, which corresponds to the triangle - index. The shape is {..}. + index. The shape is {num_intersections}. primitive_uvs A tensor with the barycentric coordinates of the intersection points within - the triangles. The shape is {.., 2}. - - t_hit - A tensor with the distance to the hit. The shape is {..}. + the triangles. The shape is {num_intersections, 2}. + An example of using ray_splits:: diff --git a/python/test/t/geometry/test_raycasting_scene.py b/python/test/t/geometry/test_raycasting_scene.py index 9b930a877da..3ce024a2b29 100644 --- a/python/test/t/geometry/test_raycasting_scene.py +++ b/python/test/t/geometry/test_raycasting_scene.py @@ -305,11 +305,10 @@ def test_output_shapes(shape): ans = scene.list_intersections(rays) nx = np.sum(scene.count_intersections(rays).numpy()).tolist() for k, v in ans.items(): - alt_shape = np.copy(shape) if k == 'ray_splits': - alt_shape[0] = shape[0] + 1 + alt_shape = [np.prod(rays.shape[:-1]) + 1] else: - alt_shape[0] = nx + alt_shape = [nx] #use np.append otherwise issues if alt_shape = [0] and last_dim[k] = [] expected_shape = np.append(alt_shape, last_dim[k]).tolist() assert list(