Skip to content

Commit

Permalink
Fix seg fault in t::geometry::TriangleMesh::SelectByIndex for negativ…
Browse files Browse the repository at this point in the history
…e index (#6489)

And add a C++ test.
  • Loading branch information
nsaiapova authored Nov 14, 2023
1 parent 9cf5df2 commit 9b45f01
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
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

0 comments on commit 9b45f01

Please sign in to comment.