From 777d4611ab3ebd8151d0855180b5ad755dc015d7 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Wed, 27 Jan 2021 12:18:32 +0100 Subject: [PATCH 1/2] Fixed ellipsoid indexes Signed-off-by: ahcorde --- graphics/src/MeshManager.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/graphics/src/MeshManager.cc b/graphics/src/MeshManager.cc index 4ea4022a9..9ef187ecf 100644 --- a/graphics/src/MeshManager.cc +++ b/graphics/src/MeshManager.cc @@ -849,12 +849,12 @@ void MeshManager::CreateEllipsoid(const std::string &_name, double d_phi = (umax - umin) / (_rings - 1.0); double d_theta = (vmax - vmin) / (_segments - 1.0); - for (i = 0, theta = vmin; i < _segments; ++i, theta += d_theta) + for (i = 0, theta = vmin; i < _rings; ++i, theta += d_theta) { const auto c_theta = cos(theta); const auto s_theta = sin(theta); - for (j = 0, phi = umin; j < _rings; ++j, phi += d_phi) + for (j = 0, phi = umin; j < _segments; ++j, phi += d_phi) { const auto c_phi = cos(phi); const auto s_phi = sin(phi); @@ -883,17 +883,17 @@ void MeshManager::CreateEllipsoid(const std::string &_name, { unsigned int verticesCount = subMesh.VertexCount(); for ( - unsigned int firstIndex = verticesCount - 2 * (_rings + 1); - firstIndex + _rings + 2 < verticesCount; + int firstIndex = verticesCount - 2 * (_segments + 1); + (firstIndex + _segments + 2 < verticesCount) && (firstIndex > 0); firstIndex++) { - subMesh.AddIndex(firstIndex + _rings + 1); + subMesh.AddIndex(firstIndex + _segments + 1); subMesh.AddIndex(firstIndex + 1); subMesh.AddIndex(firstIndex + 0); - subMesh.AddIndex(firstIndex + _rings + 2); + subMesh.AddIndex(firstIndex + _segments + 2); subMesh.AddIndex(firstIndex + 1); - subMesh.AddIndex(firstIndex + _rings + 1); + subMesh.AddIndex(firstIndex + _segments + 1); } } } From c63829fb5a27894d54e79031fa7814ceb3338f6b Mon Sep 17 00:00:00 2001 From: ahcorde Date: Thu, 28 Jan 2021 08:39:28 +0100 Subject: [PATCH 2/2] Add test to check that all indexes are positive Signed-off-by: ahcorde --- graphics/src/SubMesh_TEST.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/graphics/src/SubMesh_TEST.cc b/graphics/src/SubMesh_TEST.cc index a15e9c2c2..360c2d004 100644 --- a/graphics/src/SubMesh_TEST.cc +++ b/graphics/src/SubMesh_TEST.cc @@ -346,6 +346,19 @@ TEST_F(SubMeshTest, SubMesh) } } +///////////////////////////////////////////////// +void checkIndexes(const common::Mesh *_mesh) +{ + for (auto j = 0u; j < _mesh->SubMeshCount(); j++) + { + auto submesh = _mesh->SubMeshByIndex(j).lock(); + for (auto i = 0u; i < submesh->IndexCount(); i++) + { + EXPECT_GE(submesh->Index(i), 0); + } + } +} + ///////////////////////////////////////////////// TEST_F(SubMeshTest, Volume) { @@ -398,12 +411,16 @@ TEST_F(SubMeshTest, Volume) common::MeshManager::Instance()->MeshByName("ellipsoid"); ASSERT_TRUE(unitEllipsoid != nullptr); + checkIndexes(unitEllipsoid); + // Checking that we can not add or modify a new mesh with the name common::MeshManager::Instance()->CreateEllipsoid("ellipsoid", ignition::math::Vector3d(2, 1.4, 7), 100, 100); const common::Mesh *unitEllipsoid2 = common::MeshManager::Instance()->MeshByName("ellipsoid"); + checkIndexes(unitEllipsoid2); + // The new mesh should have more vertex, but it should be introduced in the // meshmanager. It should be the same number becuase it was not modified. EXPECT_EQ(unitEllipsoid->VertexCount(), unitEllipsoid2->VertexCount()); @@ -416,6 +433,8 @@ TEST_F(SubMeshTest, Volume) const common::Mesh *otherEllipsoid = common::MeshManager::Instance()->MeshByName("other_ellipsoid"); ASSERT_TRUE(otherEllipsoid != nullptr); + + checkIndexes(otherEllipsoid); } // Capsule mesh tests