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

Fix seg fault in t::geometry::TriangleMesh::SelectByIndex for negative index #6489

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/open3d/t/geometry/TriangleMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,7 @@ TriangleMesh TriangleMesh::SelectByIndex(const core::Tensor &indices) const {
"out of range. "
"It is ignored.",
indices_ptr[i]);
continue;
}
vertex_mask_ptr[indices_ptr[i]] = 1;
}
Expand Down
24 changes: 17 additions & 7 deletions cpp/tests/t/geometry/TriangleMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1143,16 +1143,18 @@ TEST_P(TriangleMeshPermuteDevices, SelectByIndex) {

// check basic case
core::Tensor indices = core::Tensor::Init<int64_t>({2, 3, 6, 7});
t::geometry::TriangleMesh selected = box.SelectByIndex(indices);
t::geometry::TriangleMesh selected_basic = box.SelectByIndex(indices);

EXPECT_TRUE(selected.GetVertexPositions().AllClose(expected_verts));
EXPECT_TRUE(selected.GetVertexColors().AllClose(expected_vert_colors));
EXPECT_TRUE(selected_basic.GetVertexPositions().AllClose(expected_verts));
EXPECT_TRUE(
selected.GetVertexAttr("labels").AllClose(expected_vert_labels));
EXPECT_TRUE(selected.GetTriangleIndices().AllClose(expected_tris));
EXPECT_TRUE(selected.GetTriangleNormals().AllClose(expected_tri_normals));
selected_basic.GetVertexColors().AllClose(expected_vert_colors));
EXPECT_TRUE(selected_basic.GetVertexAttr("labels").AllClose(
expected_vert_labels));
EXPECT_TRUE(selected_basic.GetTriangleIndices().AllClose(expected_tris));
EXPECT_TRUE(
selected.GetTriangleAttr("labels").AllClose(expected_tri_labels));
selected_basic.GetTriangleNormals().AllClose(expected_tri_normals));
EXPECT_TRUE(selected_basic.GetTriangleAttr("labels").AllClose(
expected_tri_labels));

// check duplicated indices case
core::Tensor indices_duplicate =
Expand All @@ -1172,6 +1174,14 @@ TEST_P(TriangleMeshPermuteDevices, SelectByIndex) {
EXPECT_TRUE(selected_duplicate.GetTriangleAttr("labels").AllClose(
expected_tri_labels));

core::Tensor indices_negative =
core::Tensor::Init<int64_t>({2, -4, 3, 6, 7});
t::geometry::TriangleMesh selected_negative =
box.SelectByIndex(indices_negative);
EXPECT_TRUE(
selected_negative.GetVertexPositions().AllClose(expected_verts));
EXPECT_TRUE(selected_negative.GetTriangleIndices().AllClose(expected_tris));

// select with empty triangles as result
// set the expected value
core::Tensor expected_verts_no_tris = core::Tensor::Init<float>(
Expand Down
Loading