Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging empty tensor point cloud fails #7091

Open
3 tasks done
conanomori opened this issue Dec 9, 2024 · 2 comments
Open
3 tasks done

Merging empty tensor point cloud fails #7091

conanomori opened this issue Dec 9, 2024 · 2 comments
Labels
bug Not a build issue, this is likely a bug.

Comments

@conanomori
Copy link

Checklist

Describe the issue

I am trying to merge 2 tensor point clouds but am getting at index error. One point cloud is empty, while another has points. I am trying to do this as I am dynamically merging point clouds from scratch

I have tried both + notation and append function (which I assume performs the same operation, but there is no description in the docs) and both methods fail.

The legacy format accounted for this and allowed you to merge empty point clouds.

Steps to reproduce the bug

import open3d as o3d
import open3d.core as o3c

# legacy point cloud merges successfully with empty point cloud
pcd_1 = o3d.geometry.PointCloud()
pcd_2 = o3d.geometry.PointCloud()
pcd_2.points = o3d.utility.Vector3dVector([[0, 0, 0], [1, 1, 1]])
pcd_1 += pcd_2

# tensor point cloud fails to merge with empty
pcd_3 = o3d.t.geometry.PointCloud()
pcd_4 = o3d.t.geometry.PointCloud(o3c.Tensor([[0, 0, 0], [1, 1, 1]], o3c.float32))
pcd_3 += pcd_4

Error message

IndexError: invalid unordered_map<K, T> key

Expected behavior

Empty tensor point clouds successfully merges with other point clouds without fail

Open3D, Python and System information

- Operating system: Windows 10 64-bit
- Python version: Python 3.11.9
- Open3D version: 0.18.0
- System architecture: x86
- Is this a remote workstation?: no
- How did you install Open3D?: pip
- Compiler version (if built from source): N/A

Additional information

No response

@conanomori conanomori added the bug Not a build issue, this is likely a bug. label Dec 9, 2024
@nicolaloi
Copy link
Contributor

I will have a look at this issue.

@nicolaloi
Copy link
Contributor

nicolaloi commented Jan 14, 2025

I have found the problem, and unfortunately, it occurs in many other t.PointCloud methods.

This specific issue is caused by this line:

int64_t length = GetPointPositions().GetLength();

In general, the error occurs when you call a method (on an empty tensor PointCloud) containing a call to GetPointPositions() (which are many).

The reason is that a tensor point cloud created with the constructor PointCloud() or PointCloud(device) does not set the positions attribute in its TensorMap, and the internal call to GetPointPositions() will raise a map index error.

The problem might be solved by setting the positions attribute to an empty tensor in the constructor of the empty PointCloud: SetPointPositions(core::Tensor::Empty({0, 3}, core::Float32, device_)). However, this would cause errors if the user is using a different dtype. For example in this merging issue, if pcd_4 is created with the o3c.float64 dtype, an error will occur because the empty point cloud pcd_3 will have o3c.float32 dtype, and vice versa.

@ssheorey @benjaminum do you have any ideas? I could open a PR to fix this specific merging issue (if positions is not set, set it as an empty tensor with the same dtype as the other point cloud), but the other PointCloud methods require a deeper fix. Or at least, I can add a descriptive log error in GetPointPositions() if the positions attribute is not set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not a build issue, this is likely a bug.
Projects
None yet
Development

No branches or pull requests

2 participants