From 00315138355543dea8d7788f51ac64e261bfa4eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Tue, 16 Feb 2021 13:13:15 +0100 Subject: [PATCH] Fixed a crash in the modified butterfly subdivider with vertices with valance larger than 30. --- .../Subdivider/Uniform/ModifiedButterFlyT.hh | 11 +++++++++ src/Unittests/TestFiles/cylinder.om | Bin 0 -> 1198 bytes src/Unittests/unittests_subdivider_uniform.cc | 22 ++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 src/Unittests/TestFiles/cylinder.om diff --git a/src/OpenMesh/Tools/Subdivider/Uniform/ModifiedButterFlyT.hh b/src/OpenMesh/Tools/Subdivider/Uniform/ModifiedButterFlyT.hh index 78b8f806..f476ad1f 100644 --- a/src/OpenMesh/Tools/Subdivider/Uniform/ModifiedButterFlyT.hh +++ b/src/OpenMesh/Tools/Subdivider/Uniform/ModifiedButterFlyT.hh @@ -179,6 +179,17 @@ protected: ///TODO:Implement fixed positions + // Compute the maximal vertex valence in the mesh + unsigned int maxValence = 0; + for ( auto vertex : _m.vertices() ) { + maxValence = std::max(maxValence,_m.valence(vertex)); + } + + // We pre initialized with 30. If it's larger, we update the weights + if (maxValence >= 30) { + init_weights( maxValence + 1 ); + } + // Do _n subdivisions for (size_t i=0; i < _n; ++i) { diff --git a/src/Unittests/TestFiles/cylinder.om b/src/Unittests/TestFiles/cylinder.om new file mode 100644 index 0000000000000000000000000000000000000000..7036e0a3ae74fe35c8c93bf22cdbbaddf518e1a0 GIT binary patch literal 1198 zcmYL|N6yqx5QKYj&N=5CJvrLlY*--{{A*6Y4cPn=YmUJ+#t6g$jsO>6$ASy+y62f0 z$@1rRxw>9S^ZM0O`vm|ztLwA6Ag|bB;QKB6-um+GrOEvE!#gYY=c};s>&g0gj4R!< z_1C+ViBDZ<2@mSD7Uz_b<%d-24AOH(A5poQYZcSj@VAVZB$Fz4^?nVQ=n&S@-YE zO=qspD|6k0uOYLaP@)pSAA)wJ9$%Wat+x9KsjUeDEgz4*Kr-{tK0o&D!iz<&yy zj={h&cszuHhtOdk4(-GHT_n7V?6%R!HoD!!qMO)e9gnT!>s2DYO00}z!blp+RC1YG zF4Cz*dNI$W=b8B|o0(;2(_D6%n@;k%Nq#aekN5fKaSQ-w>r9pYnuax_h hey>{TReRl9wOi|U>a|Y2({9w;jdlwfEoe2X@DI>8I|2Xz literal 0 HcmV?d00001 diff --git a/src/Unittests/unittests_subdivider_uniform.cc b/src/Unittests/unittests_subdivider_uniform.cc index 835c89cf..53900233 100644 --- a/src/Unittests/unittests_subdivider_uniform.cc +++ b/src/Unittests/unittests_subdivider_uniform.cc @@ -1027,6 +1027,28 @@ TEST_F(OpenMeshSubdividerUniform_Triangle, Modified_Butterfly) { +TEST_F(OpenMeshSubdividerUniform_Triangle, Modified_Butterfly_cylinder) { + mesh_.clear(); + + OpenMesh::IO::read_mesh(mesh_, "cylinder.om"); + + // Initialize subdivider + OpenMesh::Subdivider::Uniform::ModifiedButterflyT butter; + + // Check setup + EXPECT_EQ(66u, mesh_.n_vertices() ) << "Wrong number of vertices"; + EXPECT_EQ(128u, mesh_.n_faces() ) << "Wrong number of faces"; + + // Execute 3 subdivision steps + butter( mesh_,3,true ); + + // Check setup + EXPECT_EQ(4098u, mesh_.n_vertices() ) << "Wrong number of vertices after subdivision with loop"; + EXPECT_EQ(8192u, mesh_.n_faces() ) << "Wrong number of faces after subdivision with loop"; +} + + + TEST_F(OpenMeshSubdividerUniform_Triangle, Modified_Butterfly_delete_vertex) { for (bool collect_garbage : { false, true })