Skip to content

Commit 33beba4

Browse files
committed
rename Utils.hh to UsdUtils.hh and add tests
Signed-off-by: Ashton Larkin <42042756+adlarkin@users.noreply.github.com>
1 parent 1f3bf93 commit 33beba4

6 files changed

Lines changed: 94 additions & 3 deletions

File tree

usd/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ set(gtest_sources
2222
sdf_parser/Light_Sdf2Usd_TEST.cc
2323
sdf_parser/World_Sdf2Usd_TEST.cc
2424
UsdError_TEST.cc
25+
UsdUtils_TEST.cc
2526
)
2627

2728
# Build the unit tests
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <pxr/base/gf/vec3d.h>
2424
#include <pxr/base/gf/vec3f.h>
2525
#include <pxr/base/tf/token.h>
26+
#include <pxr/usd/usd/attribute.h>
2627
#include <pxr/usd/usd/prim.h>
2728

2829
#include "sdf/system_util.hh"
File renamed without changes.

usd/src/UsdUtils_TEST.cc

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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 <ignition/math/Pose3.hh>
21+
22+
// TODO(adlarkin) this is to remove deprecated "warnings" in usd, these warnings
23+
// are reported using #pragma message so normal diagnostic flags cannot remove
24+
// them. This workaround requires this block to be used whenever usd is
25+
// included.
26+
#pragma push_macro ("__DEPRECATED")
27+
#undef __DEPRECATED
28+
#include <pxr/usd/sdf/path.h>
29+
#include <pxr/usd/usd/stage.h>
30+
#include <pxr/usd/usdGeom/xform.h>
31+
#pragma pop_macro ("__DEPRECATED")
32+
33+
#include "sdf/Link.hh"
34+
#include "sdf/Model.hh"
35+
#include "sdf/Root.hh"
36+
#include "test_config.h"
37+
#include "test_utils.hh"
38+
#include "UsdTestUtils.hh"
39+
#include "UsdUtils.hh"
40+
41+
//////////////////////////////////////////////////
42+
TEST(UsdUtils, PoseWrtParent)
43+
{
44+
const auto path = sdf::testing::TestFile("sdf", "model_link_relative_to.sdf");
45+
sdf::Root root;
46+
47+
ASSERT_TRUE(sdf::testing::LoadSdfFile(path, root));
48+
const auto model = root.Model();
49+
ASSERT_NE(nullptr, model);
50+
51+
const auto linkL1 = model->LinkByName("L1");
52+
ASSERT_NE(nullptr, linkL1);
53+
const auto linkL2 = model->LinkByName("L2");
54+
ASSERT_NE(nullptr, linkL2);
55+
const auto linkL3 = model->LinkByName("L3");
56+
ASSERT_NE(nullptr, linkL3);
57+
58+
ignition::math::Pose3d pose;
59+
auto errors = sdf::usd::PoseWrtParent(*linkL2, pose);
60+
EXPECT_TRUE(errors.empty());
61+
EXPECT_EQ(ignition::math::Pose3d(2, 0, 0, 0, 0, 0), pose);
62+
63+
errors = sdf::usd::PoseWrtParent(*linkL3, pose);
64+
EXPECT_TRUE(errors.empty());
65+
EXPECT_EQ(ignition::math::Pose3d(1, 0, -3, 0, linkL1->RawPose().Pitch(), 0),
66+
pose);
67+
}
68+
69+
//////////////////////////////////////////////////
70+
TEST(UsdUtils, SetPose)
71+
{
72+
auto stage = pxr::UsdStage::CreateInMemory();
73+
ASSERT_TRUE(stage);
74+
75+
const pxr::SdfPath primPath("/prim");
76+
77+
// We create a UsdGeomXform because this is USD's concrete prim schema for
78+
// transforms
79+
ASSERT_TRUE(pxr::UsdGeomXform::Define(stage, primPath));
80+
81+
auto prim = stage->GetPrimAtPath(primPath);
82+
ASSERT_TRUE(prim);
83+
84+
const ignition::math::Pose3d pose(1, 2, 3, 0, 0, 0);
85+
auto errors = sdf::usd::SetPose(pose, stage, primPath);
86+
EXPECT_TRUE(errors.empty());
87+
88+
sdf::usd::testing::CheckPrimPose(prim, pose);
89+
}

usd/src/sdf_parser/Light.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#pragma pop_macro ("__DEPRECATED")
3636

3737
#include "sdf/Light.hh"
38-
#include "../Utils.hh"
38+
#include "../UsdUtils.hh"
3939

4040
namespace sdf
4141
{

usd/src/sdf_parser/Light_Sdf2Usd_TEST.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
#include "sdf/usd/sdf_parser/Light.hh"
4141
#include "test_config.h"
4242
#include "test_utils.hh"
43-
#include "../Utils.hh"
44-
#include "UsdTestUtils.hh"
43+
#include "../UsdTestUtils.hh"
44+
#include "../UsdUtils.hh"
4545

4646
/////////////////////////////////////////////////
4747
// Fixture that creates a USD stage for each test case.

0 commit comments

Comments
 (0)