Skip to content

Commit e6bc93b

Browse files
authored
Merge pull request #673 from gazebosim/scpeters/merge_6_main
Merge gz-common6 ➡️ main
2 parents 433d1cd + 057f8be commit e6bc93b

File tree

13 files changed

+93
-5
lines changed

13 files changed

+93
-5
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ jobs:
2929
- name: Compile and test
3030
id: ci
3131
uses: gazebo-tooling/action-gz-ci@noble
32+
with:
33+
# codecov-enabled: true
34+
cppcheck-enabled: true
35+
cpplint-enabled: true
36+
# doxygen-enabled: true

Changelog.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@
44

55
## Gazebo Common 6.x
66

7+
### Gazebo Common 6.0.2 (2025-02-12)
8+
9+
1. Add missing includes
10+
* [Pull request #660](https://github.com/gazebosim/gz-common/pull/660)
11+
12+
### Gazebo Common 6.0.1 (2024-12-17)
13+
14+
1. Check normal presence before trying to read asMesh normals
15+
* [Pull request #654](https://github.com/gazebosim/gz-common/pull/654)
16+
17+
1. Include `math::Angle` since it is used here
18+
* [Pull request #649](https://github.com/gazebosim/gz-common/pull/649)
19+
20+
1. Adds EoL to example
21+
* [Pull request #642](https://github.com/gazebosim/gz-common/pull/642)
22+
23+
1. Remove gts references from documentation
24+
* [Pull request #645](https://github.com/gazebosim/gz-common/pull/645)
25+
726
## Gazebo Common 6.0.0 (2024-09-25)
827

928
1. **Baseline:** this includes all changes from 5.6.0 and earlier.

events/include/gz/common/Event.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define GZ_COMMON_EVENT_HH_
1919

2020
#include <atomic>
21+
#include <chrono>
2122
#include <functional>
2223
#include <list>
2324
#include <map>

graphics/include/gz/common/SubMesh.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,10 @@ namespace gz
405405
/// the primitive type is not TRIANGLES, or there are no triangles.
406406
public: double Volume() const;
407407

408+
/// \brief Verify that all indices point to a valid vertex in the submesh
409+
/// \return True if all values of indices are valid, false otherwise.
410+
public: bool HasValidIndices() const;
411+
408412
/// \brief Private data pointer.
409413
GZ_UTILS_IMPL_PTR(dataPtr)
410414
};

graphics/src/AssimpLoader.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,8 @@ ImagePtr AssimpLoader::Implementation::LoadEmbeddedTexture(
613613
{
614614
if (_texture->mHeight == 0)
615615
{
616-
Image::PixelFormatType format = Image::PixelFormatType::UNKNOWN_PIXEL_FORMAT;
616+
Image::PixelFormatType format =
617+
Image::PixelFormatType::UNKNOWN_PIXEL_FORMAT;
617618
if (_texture->CheckFormat("png"))
618619
{
619620
format = Image::PixelFormatType::COMPRESSED_PNG;

graphics/src/AssimpLoader_TEST.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,8 @@ TEST_F(AssimpLoader, LoadGlbPbrAsset)
791791
EXPECT_NE(pbr->RoughnessMapData(), nullptr);
792792
// Check pixel values to test metallicroughness texture splitting
793793
EXPECT_FLOAT_EQ(pbr->MetalnessMapData()->Pixel(256, 256).R(), 0.0f);
794-
EXPECT_FLOAT_EQ(pbr->RoughnessMapData()->Pixel(256, 256).R(), 124.0f / 255.0f);
794+
EXPECT_FLOAT_EQ(pbr->RoughnessMapData()->Pixel(256, 256).R(),
795+
124.0f / 255.0f);
795796

796797
// Bug in assimp 5.0.x that doesn't parse coordinate sets properly
797798
// \todo(iche033) Lightmaps are disabled for glb meshes

graphics/src/SubMesh.cc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,12 @@ struct Neighbors
625625
void SubMesh::RecalculateNormals()
626626
{
627627
if (this->dataPtr->primitiveType != SubMesh::TRIANGLES
628-
|| this->dataPtr->indices.empty()
629628
|| this->dataPtr->indices.size() % 3u != 0)
630629
return;
631630

631+
if (!this->HasValidIndices())
632+
return;
633+
632634
// Reset all the normals
633635
for (auto &n : this->dataPtr->normals)
634636
n.Set(0, 0, 0);
@@ -743,6 +745,9 @@ std::string SubMesh::Name() const
743745
//////////////////////////////////////////////////
744746
double SubMesh::Volume() const
745747
{
748+
if (!this->HasValidIndices())
749+
return 0.0;
750+
746751
double volume = 0.0;
747752
if (this->dataPtr->primitiveType == SubMesh::TRIANGLES)
748753
{
@@ -774,6 +779,20 @@ double SubMesh::Volume() const
774779
return volume;
775780
}
776781

782+
//////////////////////////////////////////////////
783+
bool SubMesh::HasValidIndices() const
784+
{
785+
if (this->dataPtr->indices.empty())
786+
return false;
787+
788+
for (unsigned int idx = 0u; idx < this->dataPtr->indices.size(); ++idx)
789+
{
790+
if (this->dataPtr->indices[idx] >= this->dataPtr->vertices.size())
791+
return false;
792+
}
793+
return true;
794+
}
795+
777796
//////////////////////////////////////////////////
778797
NodeAssignment::NodeAssignment()
779798
: vertexIndex(0), nodeIndex(0), weight(0.0)

graphics/src/SubMesh_TEST.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,3 +598,37 @@ TEST_F(SubMeshTest, NormalsRecalculation)
598598
// because of neighbour vertex
599599
ASSERT_NE(submesh->Normal(0), submesh->Normal(1));
600600
}
601+
602+
/////////////////////////////////////////////////
603+
TEST_F(SubMeshTest, HasValidIndices)
604+
{
605+
// Check empty submesh
606+
auto submesh = std::make_shared<common::SubMesh>();
607+
EXPECT_FALSE(submesh->HasValidIndices());
608+
609+
// Check box submesh
610+
const common::Mesh *unitBox =
611+
common::MeshManager::Instance()->MeshByName("unit_box");
612+
ASSERT_TRUE(unitBox != nullptr);
613+
auto unitBoxSubmesh = unitBox->SubMeshByIndex(0).lock();
614+
615+
// Submesh has valid indices and we should be able to calculate normals
616+
// and volume
617+
EXPECT_TRUE(unitBoxSubmesh->HasValidIndices());
618+
unitBoxSubmesh->RecalculateNormals();
619+
ASSERT_EQ(unitBoxSubmesh->VertexCount(), unitBoxSubmesh->NormalCount());
620+
EXPECT_EQ(24u, unitBoxSubmesh->NormalCount());
621+
EXPECT_DOUBLE_EQ(1.0, unitBoxSubmesh->Volume());
622+
623+
// Add some invalid indices
624+
unitBoxSubmesh->AddIndex(100);
625+
unitBoxSubmesh->AddIndex(101);
626+
unitBoxSubmesh->AddIndex(102);
627+
628+
// Submesh has invalid indices so it is no longer able to update normals or
629+
// compute volume.
630+
EXPECT_FALSE(unitBoxSubmesh->HasValidIndices());
631+
unitBoxSubmesh->RecalculateNormals();
632+
EXPECT_EQ(24u, unitBoxSubmesh->NormalCount());
633+
EXPECT_DOUBLE_EQ(0.0, unitBoxSubmesh->Volume());
634+
}

include/gz/common/Battery.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef GZ_COMMON_BATTERY_HH_
1818
#define GZ_COMMON_BATTERY_HH_
1919

20+
#include <cstdint>
2021
#include <functional>
2122
#include <map>
2223
#include <memory>

include/gz/common/Console.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ namespace gz
129129
/// \return True when the initialization succeed or false otherwise.
130130
public: static bool Init(const std::string &_directory,
131131
const std::string &_filename);
132-
132+
133133
/// \brief Detach fhe file sink from the global logger. After this call,
134134
/// console logging will keep working but no file logging.
135135
public: static void Close();
136-
136+
137137
/// \brief Get the full path of the directory where all the log files
138138
/// are stored.
139139
/// \return Full path of the directory.

0 commit comments

Comments
 (0)