@@ -1212,5 +1212,127 @@ TEST_P(TriangleMeshPermuteDevices, SelectByIndex) {
12121212 box_untouched.GetTriangleIndices ()));
12131213}
12141214
1215+ TEST_P (TriangleMeshPermuteDevices, RemoveUnreferencedVertices) {
1216+ t::geometry::TriangleMesh mesh_empty;
1217+
1218+ // check completely empty mesh
1219+ EXPECT_TRUE (mesh_empty.RemoveUnreferencedVertices ().IsEmpty ());
1220+
1221+ // check mesh w/o triangles
1222+ core::Tensor vertices_no_tris_orig =
1223+ core::Tensor::Ones ({2 , 3 }, core::Float32, mesh_empty.GetDevice ());
1224+ mesh_empty.SetVertexPositions (vertices_no_tris_orig);
1225+ EXPECT_TRUE (mesh_empty.RemoveUnreferencedVertices ().IsEmpty ());
1226+
1227+ // Torus
1228+ core::Tensor verts = core::Tensor::Init<double >({
1229+ {0 , 0 , 0 }, /* 0 */
1230+ {3.0 , 0.0 , 0.0 },
1231+ {1.5 , 0.0 , 0.866025 },
1232+ {1 , 2 , 3 }, /* 3 */
1233+ {1.5 , 0.0 , -0.866025 },
1234+ {1.5 , 2.59808 , 0.0 },
1235+ {0.75 , 1.29904 , 0.866025 },
1236+ {0.75 , 1.29904 , -0.866025 },
1237+ {-1.5 , 2.59808 , 0 },
1238+ {-0.75 , 1.29904 , 0.866025 },
1239+ {-0.75 , 1.29904 , -0.866025 },
1240+ {-3.0 , 0.0 , 0.0 },
1241+ {-1.5 , 0.0 , 0.866025 },
1242+ {-1.5 , 0.0 , -0.866025 },
1243+ {-1.5 , -2.59808 , 0.0 },
1244+ {-0.75 , -1.29904 , 0.866025 },
1245+ {-0.75 , -1.29904 , -0.866025 },
1246+ {4 , 5 , 6 }, /* 17 */
1247+ {1.5 , -2.59808 , 0.0 },
1248+ {0.75 , -1.29904 , 0.866025 },
1249+ {0.75 , -1.29904 , -0.866025 },
1250+ {7 , 8 , 9 } /* 21 */
1251+ });
1252+
1253+ core::Tensor tris = core::Tensor::Init<int32_t >(
1254+ {{5 , 6 , 1 }, {1 , 6 , 2 }, {6 , 7 , 2 }, {2 , 7 , 4 },
1255+ {7 , 5 , 4 }, {4 , 5 , 1 }, {8 , 9 , 5 }, {5 , 9 , 6 },
1256+ {9 , 10 , 6 }, {6 , 10 , 7 }, {10 , 8 , 7 }, {7 , 8 , 5 },
1257+ {11 , 12 , 8 }, {8 , 12 , 9 }, {12 , 13 , 9 }, {9 , 13 , 10 },
1258+ {13 , 11 , 10 }, {10 , 11 , 8 }, {14 , 15 , 11 }, {11 , 15 , 12 },
1259+ {15 , 16 , 12 }, {12 , 16 , 13 }, {16 , 14 , 13 }, {13 , 14 , 11 },
1260+ {18 , 19 , 14 }, {14 , 19 , 15 }, {19 , 20 , 15 }, {15 , 20 , 16 },
1261+ {20 , 18 , 16 }, {16 , 18 , 14 }, {1 , 2 , 18 }, {18 , 2 , 19 },
1262+ {2 , 4 , 19 }, {19 , 4 , 20 }, {4 , 1 , 20 }, {20 , 1 , 18 }});
1263+ t::geometry::TriangleMesh torus{verts, tris};
1264+ core::Tensor vertex_colors = core::Tensor::Init<float >(
1265+ {{0.0 , 0.0 , 0.0 }, {1.0 , 1.0 , 1.0 }, {2.0 , 2.0 , 2.0 },
1266+ {3.0 , 3.0 , 3.0 }, {4.0 , 4.0 , 4.0 }, {5.0 , 5.0 , 5.0 },
1267+ {6.0 , 6.0 , 6.0 }, {7.0 , 7.0 , 7.0 }, {8.0 , 8.0 , 8.0 },
1268+ {9.0 , 9.0 , 9.0 }, {10.0 , 10.0 , 10.0 }, {11.0 , 11.0 , 11.0 },
1269+ {12.0 , 12.0 , 12.0 }, {13.0 , 13.0 , 13.0 }, {14.0 , 14.0 , 14.0 },
1270+ {15.0 , 15.0 , 15.0 }, {16.0 , 16.0 , 16.0 }, {17.0 , 17.0 , 17.0 },
1271+ {18.0 , 18.0 , 18.0 }, {19.0 , 19.0 , 19.0 }, {20.0 , 20.0 , 20.0 },
1272+ {21.0 , 21.0 , 21.0 }});
1273+ core::Tensor vertex_labels =
1274+ core::Tensor::Init<float >(
1275+ {{0.0 , 0.0 , 0.0 }, {1.0 , 1.0 , 1.0 }, {2.0 , 2.0 , 2.0 },
1276+ {3.0 , 3.0 , 3.0 }, {4.0 , 4.0 , 4.0 }, {5.0 , 5.0 , 5.0 },
1277+ {6.0 , 6.0 , 6.0 }, {7.0 , 7.0 , 7.0 }, {8.0 , 8.0 , 8.0 },
1278+ {9.0 , 9.0 , 9.0 }, {10.0 , 10.0 , 10.0 }, {11.0 , 11.0 , 11.0 },
1279+ {12.0 , 12.0 , 12.0 }, {13.0 , 13.0 , 13.0 }, {14.0 , 14.0 , 14.0 },
1280+ {15.0 , 15.0 , 15.0 }, {16.0 , 16.0 , 16.0 }, {17.0 , 17.0 , 17.0 },
1281+ {18.0 , 18.0 , 18.0 }, {19.0 , 19.0 , 19.0 }, {20.0 , 20.0 , 20.0 },
1282+ {21.0 , 21.0 , 21.0 }}) *
1283+ 10 ;
1284+
1285+ core::Tensor triangle_labels =
1286+ core::Tensor::Init<float >(
1287+ {{0.0 , 0.0 , 0.0 }, {1.0 , 1.0 , 1.0 },
1288+ {2.0 , 2.0 , 2.0 }, {3.0 , 3.0 , 3.0 },
1289+ {4.0 , 4.0 , 4.0 }, {5.0 , 5.0 , 5.0 },
1290+ {6.0 , 6.0 , 6.0 }, {7.0 , 7.0 , 7.0 },
1291+ {8.0 , 8.0 , 8.0 }, {9.0 , 9.0 , 9.0 },
1292+ {10.0 , 10.0 , 10.0 }, {11.0 , 11.0 , 11.0 },
1293+ {12.0 , 12.0 , 12.0 }, {13.0 , 13.0 , 13.0 },
1294+ {14.0 , 14.0 , 14.0 }, {15.0 , 15.0 , 15.0 },
1295+ {16.0 , 16.0 , 16.0 }, {17.0 , 17.0 , 17.0 },
1296+ {18.0 , 18.0 , 18.0 }, {19.0 , 19.0 , 19.0 },
1297+ {20.0 , 20.0 , 20.0 }, {21.0 , 21.0 , 21.0 },
1298+ {22.0 , 22.0 , 22.0 }, {23.0 , 23.0 , 23.0 },
1299+ {24.0 , 24.0 , 24.0 }, {25.0 , 25.0 , 25.0 },
1300+ {26.0 , 26.0 , 26.0 }, {27.0 , 27.0 , 27.0 },
1301+ {28.0 , 28.0 , 28.0 }, {29.0 , 29.0 , 29.0 },
1302+ {30.0 , 30.0 , 30.0 }, {31.0 , 31.0 , 31.0 },
1303+ {32.0 , 32.0 , 32.0 }, {33.0 , 33.0 , 33.0 },
1304+ {34.0 , 34.0 , 34.0 }, {35.0 , 35.0 , 35.0 }}) *
1305+ 100 ;
1306+ torus.SetVertexColors (vertex_colors);
1307+ torus.SetVertexAttr (" labels" , vertex_labels);
1308+ torus.ComputeVertexNormals ();
1309+ torus.ComputeTriangleNormals ();
1310+
1311+ // set the expected value
1312+ core::Tensor verts_mask = core::Tensor::Init<bool >(
1313+ {0 , 1 , 1 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 1 , 1 , 1 , 0 });
1314+ core::Tensor expected_verts =
1315+ torus.GetVertexPositions ().IndexGet ({verts_mask});
1316+ core::Tensor expected_tris = t::geometry::TriangleMesh::CreateTorus (
1317+ 2 , 1 , 6 , 3 , core::Float32, core::Int32)
1318+ .GetTriangleIndices ();
1319+ core::Tensor expected_vert_normals =
1320+ torus.GetVertexNormals ().IndexGet ({verts_mask});
1321+ core::Tensor expected_tri_normals = torus.GetTriangleNormals ().Clone ();
1322+ core::Tensor expected_vert_labels =
1323+ torus.GetVertexAttr (" labels" ).IndexGet ({verts_mask});
1324+ core::Tensor expected_vert_colors =
1325+ torus.GetVertexAttr (" colors" ).IndexGet ({verts_mask});
1326+
1327+ torus.RemoveUnreferencedVertices ();
1328+
1329+ EXPECT_TRUE (torus.GetVertexPositions ().AllClose (expected_verts));
1330+ EXPECT_TRUE (torus.GetVertexNormals ().AllClose (expected_vert_normals));
1331+ EXPECT_TRUE (torus.GetVertexColors ().AllClose (expected_vert_colors));
1332+ EXPECT_TRUE (torus.GetVertexAttr (" labels" ).AllClose (expected_vert_labels));
1333+ EXPECT_TRUE (torus.GetTriangleIndices ().AllClose (expected_tris));
1334+ EXPECT_TRUE (torus.GetTriangleNormals ().AllClose (expected_tri_normals));
1335+ }
1336+
12151337} // namespace tests
12161338} // namespace open3d
0 commit comments