isl-org / isl-org/Open3D

When Saving and Loading VoxelBlockGrid negative indices cause a Seg Fault

Open
#6,795 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
14k
Forks
2.6k
Avg merge
5d 18h
Merged PRs (30d)
6

Description

### Checklist

- [X] I have searched for [similar issues](https://github.com/isl-org/Open3D/issues).
- [x] For Python issues, I have tested with the [latest development wheel](https://www.open3d.org/docs/latest/getting_started.html#development-version-pip).
- [X] I have checked the [release documentation](https://www.open3d.org/docs/release/) and the [latest documentation](https://www.open3d.org/docs/latest/) (for `main` branch).

### Describe the issue

I am working with the tensor implementation of the Voxel Block Grid and I have successfully built a voxel block grid of an object with a series of depth images but when I try to save and load the object I get errors.

The object saves without error but gives [this output](https://github.com/isl-org/Open3D/files/15380590/load_output.txt) when loading which is a series of errors about the a negative index outside of the bounds. Then when I try to use the object and call ray_cast there is a Segmentation fault.

### Steps to reproduce the bug

```cpp
//This is the function I use to build and save the Voxel Block Grid

void create_npz_object_from_mesh(open3d::t::geometry::TriangleMesh mesh,std::string out_file_name, bool create_snapshot_files){
float voxel_size = 3.0/512;
int block_res = 8;
int64_t block_count = 6000;
auto mesh_points_ptr = mesh.ToLegacy().SamplePointsUniformly(5000);
auto pc_ptr = open3d::t::geometry::PointCloud::FromLegacy(mesh_points_ptr->points_,open3d::core::Dtype::Float32,open3d::core::Device("CUDA:0"));
open3d::t::geometry::VoxelBlockGrid voxel_grid({"tsdf","weight"},{open3d::core::Dtype::Float32,open3d::core::Dtype::Float32},
{{1},{1}},voxel_size,block_res,block_count,open3d::core::Device("CUDA:0"));

// Camera Specific; May need to be changed for different objects
auto camera_intrin = open3d::core::Tensor(std::vector{200.0, 0.0, 150.0,0, 200, 150,0, 0, 1},{3,3}).To(open3d::core::Dtype::Float64); int img_width_height = 300;
// Transform matrix of 1.5m in the z
Eigen::Matrix4f transform_mat = Eigen::Matrix4f::Identity();
Eigen::Quaternionf q;
transform_mat(2, 3) = 1.5f; // Sets distance between virtual camera and object
open3d::core::Tensor extrinsic_cam_mat;
float step_size = M_PI/10;
for (float r_x=0;r_x<(2*M_PI-step_size);r_x+=step_size){
for (float r_y=0;r_y<(M_PI-step_size);r_y+=step_size){
q = Eigen::Quaternionf(Eigen::AngleAxisf(r_x, Eigen::Vector3f::UnitX()) *
Eigen::AngleAxisf(r_y, Eigen::Vector3f::UnitY()));
transform_mat.block<3, 3>(0, 0) = q.toRotationMatrix();
extrinsic_cam_mat = open3d::core::eigen_converter::EigenMatrixToTensor(transform_mat).To(open3d::core::Dtype::Float64);
// Note only looking 3m deep when 1.5m away from the object

auto depth_img = pc_ptr.ProjectToDepthImage(img_width_height,img_width_height,camera_intrin,extrinsic_cam_mat);
auto block_coords = voxel_grid.GetUniqueBlockCoordinates(depth_img,camera_intrin,extrinsic_cam_mat);
voxel_grid.Integrate(block_coords,depth_img,camera_intrin,extrinsic_cam_mat);
}
}
voxel_grid.Save(out_file_name);
return;
}

//But when I run

std::shared_ptr voxel_grid = std::make_shared();
voxel_grid->Load("file_name.npz")
```

### Error message

[load_output.txt](https://github.com/isl-org/Open3D/files/15380790/load_output.txt)

### Expected behavior

_No response_

### Open3D, Python and System information

```markdown
- Operating system: Ubuntu 20.04
- Open3D version: 0.18.0
- System architecture: arm64
- Is this a remote workstation?: yes
- How did you install Open3D?: build from source
- Compiler version (if built from source): gcc 9.4.0
```

### Additional information

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.