|
| 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 | +} |
0 commit comments