Skip to content

Commit

Permalink
correcting shape handling and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrishastin committed Nov 2, 2023
1 parent 20878e2 commit 26b4236
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 34 deletions.
3 changes: 2 additions & 1 deletion cpp/open3d/t/geometry/RaycastingScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,8 @@ RaycastingScene::ListIntersections(const core::Tensor& rays,

// generate results structure
std::unordered_map<std::string, core::Tensor> 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<uint32_t>();
ptr[0] = 0;
Expand Down
41 changes: 23 additions & 18 deletions cpp/open3d/t/geometry/RaycastingScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<std::string, core::Tensor> ComputeClosestPoints(
const core::Tensor &query_points, const int nthreads = 0);

Expand Down
23 changes: 11 additions & 12 deletions cpp/pybind/t/geometry/raycasting_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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::
Expand Down
5 changes: 2 additions & 3 deletions python/test/t/geometry/test_raycasting_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 26b4236

Please sign in to comment.