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