Skip to content

Commit cbbbc9c

Browse files
committed
Merge branch 'ign-common3' into scpeters/merge_3_4
2 parents d680f3c + 131d2e7 commit cbbbc9c

File tree

12 files changed

+3662
-7
lines changed

12 files changed

+3662
-7
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
name: Ubuntu Bionic CI
99
steps:
1010
- name: Checkout
11-
uses: actions/checkout@v2
11+
uses: actions/checkout@v3
1212
- name: Compile and test
1313
id: ci
1414
uses: ignition-tooling/action-ignition-ci@bionic
@@ -19,7 +19,7 @@ jobs:
1919
name: Ubuntu Focal CI
2020
steps:
2121
- name: Checkout
22-
uses: actions/checkout@v2
22+
uses: actions/checkout@v3
2323
- name: Compile and test
2424
id: ci
2525
uses: ignition-tooling/action-ignition-ci@focal
@@ -28,7 +28,7 @@ jobs:
2828
name: Ubuntu Jammy CI
2929
steps:
3030
- name: Checkout
31-
uses: actions/checkout@v2
31+
uses: actions/checkout@v3
3232
- name: Compile and test
3333
id: ci
3434
uses: ignition-tooling/action-ignition-ci@jammy

graphics/include/gz/common/Image.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ namespace ignition
108108
/// \param[in] _filename The name of the saved image
109109
public: void SavePNG(const std::string &_filename);
110110

111-
/// \brief Save the image in PNG format
112-
/// \param[in] _filename The name of the saved image
111+
/// \brief Get the PNG image in a buffer
112+
/// \param[out] _buffer Buffer with the data
113113
public: void SavePNGToBuffer(std::vector<unsigned char> &_buffer);
114114

115115
/// \brief Set the image from raw data

graphics/src/BVHLoader_TEST.cc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (C) 2022 Open Source Robotics Foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
#include <gtest/gtest.h>
19+
20+
#include "test_config.h"
21+
22+
#include "gz/common/BVHLoader.hh"
23+
#include "gz/common/Skeleton.hh"
24+
#include "gz/common/SkeletonAnimation.hh"
25+
26+
using namespace ignition;
27+
28+
class BHVLoaderTest : public common::testing::AutoLogFixture { };
29+
30+
/////////////////////////////////////////////////
31+
TEST_F(BHVLoaderTest, LoadBVH)
32+
{
33+
common::BVHLoader loader;
34+
auto skel = loader.Load("", 1);
35+
EXPECT_EQ(nullptr, skel);
36+
37+
skel = loader.Load(
38+
common::testing::TestFile("data", "cmu-13_26.bvh"), 1);
39+
EXPECT_NE(nullptr, skel->RootNode());
40+
41+
EXPECT_EQ(skel->RootNode()->Name(), std::string("Hips"));
42+
EXPECT_EQ(31u, skel->NodeCount());
43+
}

graphics/src/Image_TEST.cc

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ using namespace ignition;
2424

2525
class ImageTest : public common::testing::AutoLogFixture { };
2626

27-
27+
const std::string kTestDataGazeboJpeg = // NOLINT(*)
28+
common::testing::TestFile("data", "gazebo_logo.jpeg");
29+
const std::string kTestDataGazeboBmp = // NOLINT(*)
30+
common::testing::TestFile("data", "gazebo_logo.bmp");
2831
const std::string kTestData = // NOLINT(*)
2932
common::testing::TestFile("data", "red_blue_colors.png");
3033

@@ -71,6 +74,50 @@ TEST_F(ImageTest, InvalidImage)
7174
ASSERT_EQ(-1, img.Load("/file/shouldn/never/exist.png"));
7275
}
7376

77+
/////////////////////////////////////////////////
78+
TEST_F(ImageTest, ImageConstructorProperties)
79+
{
80+
common::Image imgInvalid("invalid");
81+
ASSERT_FALSE(imgInvalid.Valid());
82+
83+
common::Image img(kTestData);
84+
CheckImageRGBA(img);
85+
86+
ASSERT_EQ(img.Pixel(0, 0), math::Color::Red);
87+
ASSERT_EQ(img.Pixel(85, 0), math::Color::Blue);
88+
ASSERT_EQ(kAvgColor, img.AvgColor());
89+
ASSERT_EQ(kMaxColor, img.MaxColor());
90+
91+
ASSERT_TRUE(img.Filename().find("red_blue_colors.png") !=
92+
std::string::npos);
93+
}
94+
95+
/////////////////////////////////////////////////
96+
TEST_F(ImageTest, ImageConstructorPropertiesDifferentFormats)
97+
{
98+
common::Image imgBmp(kTestDataGazeboBmp);
99+
100+
ASSERT_EQ(554u, imgBmp.Width());
101+
ASSERT_EQ(234u, imgBmp.Height());
102+
ASSERT_EQ(24u, imgBmp.BPP());
103+
ASSERT_EQ(1662, imgBmp.Pitch());
104+
ASSERT_EQ(common::Image::PixelFormatType::RGB_INT8, imgBmp.PixelFormat());
105+
106+
ASSERT_TRUE(imgBmp.Filename().find("gazebo_logo.bmp") !=
107+
std::string::npos);
108+
109+
common::Image imgJpeg(kTestDataGazeboJpeg);
110+
111+
ASSERT_EQ(554u, imgJpeg.Width());
112+
ASSERT_EQ(234u, imgJpeg.Height());
113+
ASSERT_EQ(24u, imgJpeg.BPP());
114+
ASSERT_EQ(1662, imgJpeg.Pitch());
115+
ASSERT_EQ(common::Image::PixelFormatType::RGB_INT8, imgJpeg.PixelFormat());
116+
117+
ASSERT_TRUE(imgJpeg.Filename().find("gazebo_logo.jpeg") !=
118+
std::string::npos);
119+
}
120+
74121
/////////////////////////////////////////////////
75122
TEST_F(ImageTest, ImageProperties)
76123
{
@@ -91,6 +138,44 @@ TEST_F(ImageTest, ImageProperties)
91138
std::string::npos);
92139
}
93140

141+
TEST_F(ImageTest, ImageSavePng)
142+
{
143+
std::string pathOut;
144+
ASSERT_TRUE(common::testing::TestTmpPath(pathOut));
145+
common::createDirectories(pathOut);
146+
147+
std::string imagePath = common::joinPaths(pathOut, "image.png");
148+
149+
common::Image imgJpeg(kTestDataGazeboJpeg);
150+
imgJpeg.SavePNG(imagePath);
151+
common::Image img(imagePath);
152+
ASSERT_TRUE(img.Valid());
153+
154+
std::vector<unsigned char> values;
155+
img.SavePNGToBuffer(values);
156+
EXPECT_LT(0u, values.size());
157+
}
158+
159+
TEST_F(ImageTest, ImageGetterInvalid)
160+
{
161+
common::Image img;
162+
EXPECT_EQ(0u, img.Width());
163+
EXPECT_EQ(0u, img.Height());
164+
EXPECT_EQ(0u, img.BPP());
165+
EXPECT_EQ(math::Color(), img.Pixel(0, 0));
166+
EXPECT_EQ(math::Color(), img.MaxColor());
167+
168+
common::Image imgBmp(kTestDataGazeboBmp);
169+
EXPECT_EQ(math::Color(), imgBmp.Pixel(2000, 0));
170+
171+
unsigned int width = imgBmp.Width();
172+
unsigned int height = imgBmp.Height();
173+
imgBmp.Rescale(static_cast<int>(width / 2), static_cast<int>(height / 2));
174+
175+
EXPECT_EQ(static_cast<unsigned int>(width / 2), imgBmp.Width());
176+
EXPECT_EQ(static_cast<unsigned int>(height / 2), imgBmp.Height());
177+
}
178+
94179
/////////////////////////////////////////////////
95180
TEST_F(ImageTest, RGBData)
96181
{
@@ -214,7 +299,8 @@ TEST_F(ImageTest, SetFromData)
214299
common::testing::TempPath("test_red_blue_save.png");
215300
img.SavePNG(testSaveImage);
216301
217-
common::Image img2;
302+
common::Image img2; common::Image img;
303+
218304
img2.Load(testSaveImage);
219305
ASSERT_TRUE(img2.Valid());
220306
ASSERT_EQ(common::Image::PixelFormatType::RGB_INT8, img2.PixelFormat());

graphics/src/STLLoader_TEST.cc

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (C) 2022 Open Source Robotics Foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
#include <gtest/gtest.h>
19+
20+
#include "test_config.h"
21+
22+
#include "gz/common/Mesh.hh"
23+
#include "gz/common/SubMesh.hh"
24+
#include "gz/common/Material.hh"
25+
#include "gz/common/STLLoader.hh"
26+
27+
using namespace ignition;
28+
29+
class STLLoaderTest : public common::testing::AutoLogFixture { };
30+
31+
/////////////////////////////////////////////////
32+
TEST_F(STLLoaderTest, LoadSTL)
33+
{
34+
common::STLLoader loader;
35+
auto mesh = loader.Load("");
36+
EXPECT_EQ(nullptr, mesh);
37+
38+
mesh = loader.Load(
39+
common::testing::TestFile("data", "cube.stl"));
40+
EXPECT_NE(nullptr, mesh);
41+
42+
EXPECT_STREQ("unknown", mesh->Name().c_str());
43+
EXPECT_EQ(math::Vector3d(20, 0, 20), mesh->Max());
44+
EXPECT_EQ(math::Vector3d(0, -20, 0), mesh->Min());
45+
// 36 vertices, 24 unique, 12 shared.
46+
EXPECT_EQ(36u, mesh->VertexCount());
47+
EXPECT_EQ(36u, mesh->NormalCount());
48+
EXPECT_EQ(36u, mesh->IndexCount());
49+
EXPECT_EQ(0u, mesh->TexCoordCount());
50+
EXPECT_EQ(1u, mesh->SubMeshCount());
51+
EXPECT_EQ(0u, mesh->MaterialCount());
52+
53+
auto sm = mesh->SubMeshByIndex(0u);
54+
auto subMesh = sm.lock();
55+
EXPECT_NE(nullptr, subMesh);
56+
EXPECT_EQ(math::Vector3d(20, 0, 0), subMesh->Vertex(0u));
57+
EXPECT_EQ(math::Vector3d(0, -20, 0), subMesh->Vertex(1u));
58+
EXPECT_EQ(math::Vector3d(0, 0, 0), subMesh->Vertex(2u));
59+
EXPECT_EQ(math::Vector3d(0, 0, -1), subMesh->Normal(0u));
60+
EXPECT_EQ(math::Vector3d(0, 0, -1), subMesh->Normal(1u));
61+
EXPECT_EQ(math::Vector3d(0, 0, -1), subMesh->Normal(2u));
62+
63+
EXPECT_STREQ("", mesh->SubMeshByIndex(0).lock()->Name().c_str());
64+
65+
mesh = loader.Load(
66+
common::testing::TestFile("data", "cube_binary.stl"));
67+
EXPECT_NE(nullptr, mesh);
68+
69+
EXPECT_STREQ("unknown", mesh->Name().c_str());
70+
EXPECT_EQ(math::Vector3d(20, 0, 20), mesh->Max());
71+
EXPECT_EQ(math::Vector3d(0, -20, 0), mesh->Min());
72+
// 36 vertices, 24 unique, 12 shared.
73+
EXPECT_EQ(36u, mesh->VertexCount());
74+
EXPECT_EQ(36u, mesh->NormalCount());
75+
EXPECT_EQ(36u, mesh->IndexCount());
76+
EXPECT_EQ(0u, mesh->TexCoordCount());
77+
EXPECT_EQ(1u, mesh->SubMeshCount());
78+
EXPECT_EQ(0u, mesh->MaterialCount());
79+
80+
sm = mesh->SubMeshByIndex(0u);
81+
subMesh = sm.lock();
82+
EXPECT_NE(nullptr, subMesh);
83+
EXPECT_EQ(math::Vector3d(20, 0, 0), subMesh->Vertex(0u));
84+
EXPECT_EQ(math::Vector3d(0, -20, 0), subMesh->Vertex(1u));
85+
EXPECT_EQ(math::Vector3d(0, 0, 0), subMesh->Vertex(2u));
86+
EXPECT_EQ(math::Vector3d(0, 0, -1), subMesh->Normal(0u));
87+
EXPECT_EQ(math::Vector3d(0, 0, -1), subMesh->Normal(1u));
88+
EXPECT_EQ(math::Vector3d(0, 0, -1), subMesh->Normal(2u));
89+
90+
EXPECT_STREQ("", mesh->SubMeshByIndex(0).lock()->Name().c_str());
91+
}

profiler/src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ set(
1010
Profiler_Disabled_TEST.cc
1111
)
1212

13+
if(NOT WIN32)
14+
list(APPEND PROFILER_TESTS Profiler_Error_TEST.cc)
15+
endif()
16+
1317
if(IGN_PROFILER_REMOTERY)
1418
set(
1519
Remotery_SRC

0 commit comments

Comments
 (0)