Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed ellipsoid indexes #159

Merged
merged 2 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions graphics/src/MeshManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions graphics/src/SubMesh_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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());
Expand All @@ -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
Expand Down