From e17b09f656fd4b3e7ea5fdd39893642135d1ee7c Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Mon, 19 Mar 2018 10:26:21 +0100 Subject: [PATCH 1/4] fix usage of wrong split function in unit test --- src/Unittests/unittests_split_edge_copy.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Unittests/unittests_split_edge_copy.cc b/src/Unittests/unittests_split_edge_copy.cc index 4dd2088d..c2fbd67e 100644 --- a/src/Unittests/unittests_split_edge_copy.cc +++ b/src/Unittests/unittests_split_edge_copy.cc @@ -91,13 +91,15 @@ TEST_F(OpenMeshSplitEdgeCopyTriangleMesh, SplitEdgeCopyTriangleMesh) { //set internal property mesh_.status(eh).set_tagged(true); - // split face with new vertex - mesh_.split_edge_copy(eh, vhandle[3]); + // split edge with new vertex + mesh_.split_copy(eh, vhandle[3]); // Check setup Mesh::EdgeHandle eh0 = mesh_.edge_handle( mesh_.next_halfedge_handle( mesh_.halfedge_handle(eh, 1) ) ); EXPECT_EQ(999, mesh_.property(eprop_int, eh0)) << "Different Property value"; EXPECT_TRUE(mesh_.status(eh0).tagged()) << "Different internal property value"; + + EXPECT_EQ(mesh_.valence(fh), 3) << "Face of TriMesh has valence other than 3"; } /* splits an edge that has a property in a poly mesh with split_edge_copy From 0d45e1e4c69f8b6b749a9bf633f93ea2ee83c7ee Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Mon, 19 Mar 2018 10:26:56 +0100 Subject: [PATCH 2/4] add unittest to check if face properties are copied correctly after edge split --- src/Unittests/unittests_split_edge_copy.cc | 98 ++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/src/Unittests/unittests_split_edge_copy.cc b/src/Unittests/unittests_split_edge_copy.cc index c2fbd67e..cb64e28f 100644 --- a/src/Unittests/unittests_split_edge_copy.cc +++ b/src/Unittests/unittests_split_edge_copy.cc @@ -154,4 +154,102 @@ TEST_F(OpenMeshSplitEdgeCopyPolyMesh, SplitEdgeCopyPolymesh) { EXPECT_EQ(999, mesh_.property(eprop_int, eh0)) << "Different Property value"; EXPECT_TRUE(mesh_.status(eh0).tagged()) << "Different internal property value"; } + + +/* splits an edge in a triangle mesh that has a face property with split_edge_copy + * the property should be copied to the new edge + */ +TEST_F(OpenMeshSplitEdgeCopyTriangleMesh, SplitEdgeCopyFacePropertiesTriangleMesh) { + + mesh_.clear(); + mesh_.request_edge_status(); + mesh_.request_face_status(); + + static_assert(std::is_same::value, "Mesh is not a triangle mesh"); + + // Add some vertices + Mesh::VertexHandle vhandle[4]; + + vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0)); + vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0)); + vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0)); + vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0)); + + Mesh::VertexHandle inner_vertex = mesh_.add_vertex(Mesh::Point(0.5, 0.5, 0)); + Mesh::VertexHandle boundary_vertex = mesh_.add_vertex(Mesh::Point(0.0, 0.5, 0)); + + // Add two faces + std::vector face_vhandles; + face_vhandles.push_back(vhandle[2]); + face_vhandles.push_back(vhandle[1]); + face_vhandles.push_back(vhandle[0]); + + Mesh::FaceHandle fh0 = mesh_.add_face(face_vhandles); + + face_vhandles.clear(); + face_vhandles.push_back(vhandle[2]); + face_vhandles.push_back(vhandle[0]); + face_vhandles.push_back(vhandle[3]); + + Mesh::FaceHandle fh1 = mesh_.add_face(face_vhandles); + + Mesh::EdgeHandle inner_edge = Mesh::EdgeHandle(2); + + EXPECT_EQ(mesh_.n_faces(), 2u); + + // Test setup: + // 1 --- 2 + // | / | + // | / | + // | / | + // 0 --- 3 + + // set property + OpenMesh::FPropHandleT fprop_int; + mesh_.add_property(fprop_int); + mesh_.property(fprop_int, fh0) = 13; + mesh_.property(fprop_int, fh1) = 17; + //set internal property + mesh_.status(fh0).set_tagged(true); + + // 2 to 4 split + mesh_.split_copy(inner_edge, inner_vertex); + + EXPECT_EQ(mesh_.n_faces(), 4u); + + for (auto fh : mesh_.faces()) + { + EXPECT_EQ(mesh_.valence(fh), 3); + } + + // Check setup + Mesh::HalfedgeHandle heh21 = mesh_.find_halfedge(vhandle[2], vhandle[1]); + Mesh::HalfedgeHandle heh10 = mesh_.find_halfedge(vhandle[1], vhandle[0]); + Mesh::HalfedgeHandle heh03 = mesh_.find_halfedge(vhandle[0], vhandle[3]); + Mesh::HalfedgeHandle heh32 = mesh_.find_halfedge(vhandle[3], vhandle[2]); + + EXPECT_EQ(13, mesh_.property(fprop_int, mesh_.face_handle(heh21))) << "Different Property value"; + EXPECT_EQ(13, mesh_.property(fprop_int, mesh_.face_handle(heh10))) << "Different Property value"; + EXPECT_EQ(17, mesh_.property(fprop_int, mesh_.face_handle(heh03))) << "Different Property value"; + EXPECT_EQ(17, mesh_.property(fprop_int, mesh_.face_handle(heh32))) << "Different Property value"; + EXPECT_TRUE(mesh_.status(mesh_.face_handle(heh21)).tagged()) << "Different internal property value"; + EXPECT_TRUE(mesh_.status(mesh_.face_handle(heh10)).tagged()) << "Different internal property value"; + EXPECT_FALSE(mesh_.status(mesh_.face_handle(heh03)).tagged()) << "Different internal property value"; + EXPECT_FALSE(mesh_.status(mesh_.face_handle(heh32)).tagged()) << "Different internal property value"; + + // also test boundary split + Mesh::EdgeHandle boundary_edge = mesh_.edge_handle(heh10); + + // 1 to 2 split + mesh_.split_copy(boundary_edge, boundary_vertex); + + Mesh::HalfedgeHandle heh1b = mesh_.find_halfedge(vhandle[1], boundary_vertex); + Mesh::HalfedgeHandle hehb0 = mesh_.find_halfedge(boundary_vertex, vhandle[0]); + + EXPECT_EQ(13, mesh_.property(fprop_int, mesh_.face_handle(heh1b))) << "Different Property value"; + EXPECT_EQ(13, mesh_.property(fprop_int, mesh_.face_handle(hehb0))) << "Different Property value"; + EXPECT_TRUE(mesh_.status(mesh_.face_handle(heh1b)).tagged()) << "Different internal property value"; + EXPECT_TRUE(mesh_.status(mesh_.face_handle(hehb0)).tagged()) << "Different internal property value"; +} + } From 480f1175e17665ce9e85925085ea8d83b058d6bf Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Mon, 19 Mar 2018 10:54:06 +0100 Subject: [PATCH 3/4] also copy face properties in split_copy(EdgeHandle, VertexHandle) --- src/OpenMesh/Core/Mesh/TriConnectivity.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/OpenMesh/Core/Mesh/TriConnectivity.cc b/src/OpenMesh/Core/Mesh/TriConnectivity.cc index e3d69623..fc12ac00 100644 --- a/src/OpenMesh/Core/Mesh/TriConnectivity.cc +++ b/src/OpenMesh/Core/Mesh/TriConnectivity.cc @@ -488,6 +488,11 @@ void TriConnectivity::split(EdgeHandle _eh, VertexHandle _vh) void TriConnectivity::split_copy(EdgeHandle _eh, VertexHandle _vh) { + VertexHandle v0 = to_vertex_handle(halfedge_handle(_eh, 0)); + VertexHandle v1 = to_vertex_handle(halfedge_handle(_eh, 1)); + + int nf = n_faces(); + // Split the halfedge ( handle will be preserved) split(_eh, _vh); @@ -495,6 +500,22 @@ void TriConnectivity::split_copy(EdgeHandle _eh, VertexHandle _vh) // have been created for(VEIter ve_it = ve_iter(_vh); ve_it.is_valid(); ++ve_it) copy_all_properties(_eh, *ve_it, true); + + for (auto vh : {v0, v1}) + { + // get the halfedge pointing from new vertex to old vertex + HalfedgeHandle h = find_halfedge(_vh, vh); + if (!is_boundary(h)) // for boundaries there are no faces whose properties need to be copied + { + FaceHandle fh0 = face_handle(h); + FaceHandle fh1 = face_handle(opposite_halfedge_handle(prev_halfedge_handle(h))); + if (fh0.idx() >= nf) // is fh0 the new face? + std::swap(fh0, fh1); + + // copy properties from old face to new face + copy_all_properties(fh0, fh1, true); + } + } } }// namespace OpenMesh From d32df7f1ba57014dba143e330ab1211f39ad4868 Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Tue, 20 Mar 2018 09:58:27 +0100 Subject: [PATCH 4/4] add some consts --- src/OpenMesh/Core/Mesh/TriConnectivity.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OpenMesh/Core/Mesh/TriConnectivity.cc b/src/OpenMesh/Core/Mesh/TriConnectivity.cc index fc12ac00..fb77f87e 100644 --- a/src/OpenMesh/Core/Mesh/TriConnectivity.cc +++ b/src/OpenMesh/Core/Mesh/TriConnectivity.cc @@ -488,10 +488,10 @@ void TriConnectivity::split(EdgeHandle _eh, VertexHandle _vh) void TriConnectivity::split_copy(EdgeHandle _eh, VertexHandle _vh) { - VertexHandle v0 = to_vertex_handle(halfedge_handle(_eh, 0)); - VertexHandle v1 = to_vertex_handle(halfedge_handle(_eh, 1)); + const VertexHandle v0 = to_vertex_handle(halfedge_handle(_eh, 0)); + const VertexHandle v1 = to_vertex_handle(halfedge_handle(_eh, 1)); - int nf = n_faces(); + const int nf = n_faces(); // Split the halfedge ( handle will be preserved) split(_eh, _vh); @@ -504,7 +504,7 @@ void TriConnectivity::split_copy(EdgeHandle _eh, VertexHandle _vh) for (auto vh : {v0, v1}) { // get the halfedge pointing from new vertex to old vertex - HalfedgeHandle h = find_halfedge(_vh, vh); + const HalfedgeHandle h = find_halfedge(_vh, vh); if (!is_boundary(h)) // for boundaries there are no faces whose properties need to be copied { FaceHandle fh0 = face_handle(h);