Skip to content

Commit 1157051

Browse files
authored
Added BVH and STL loader tests (#466)
Signed-off-by: ahcorde <[email protected]>
1 parent 753566f commit 1157051

File tree

5 files changed

+3436
-0
lines changed

5 files changed

+3436
-0
lines changed

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/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+
}

0 commit comments

Comments
 (0)