Skip to content

Commit d09ce09

Browse files
committed
usd -> sdf: Read transforms
Signed-off-by: ahcorde <ahcorde@gmail.com>
1 parent 8955a74 commit d09ce09

File tree

4 files changed

+579
-0
lines changed

4 files changed

+579
-0
lines changed
+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
#ifndef SDF_USD_USD_PARSER_UTILS_HH_
19+
#define SDF_USD_USD_PARSER_UTILS_HH_
20+
21+
#include <string>
22+
#include <vector>
23+
24+
#include <ignition/math/Pose3.hh>
25+
#include <ignition/math/Vector3.hh>
26+
27+
// TODO(ahcorde):this is to remove deprecated "warnings" in usd, these warnings
28+
// are reported using #pragma message so normal diagnostic flags cannot remove
29+
// them. This workaround requires this block to be used whenever usd is
30+
// included.
31+
#pragma push_macro ("__DEPRECATED")
32+
#undef __DEPRECATED
33+
#include <pxr/usd/usdGeom/gprim.h>
34+
#pragma pop_macro ("__DEPRECATED")
35+
36+
#include "sdf/sdf_config.h"
37+
#include "sdf/system_util.hh"
38+
#include "sdf/usd/Export.hh"
39+
#include "sdf/usd/UsdError.hh"
40+
41+
#include "USDData.hh"
42+
43+
namespace sdf
44+
{
45+
// Inline bracke to help doxygen filtering.
46+
inline namespace SDF_VERSION_NAMESPACE {
47+
//
48+
namespace usd
49+
{
50+
/// \brief This class stores the transforms of a schema
51+
/// This might contains scale, translate or rotation operations
52+
/// The booleans are used to check if there is a transform defined
53+
/// in the schema
54+
/// Rotation is splitted in a vector because this might be defined
55+
/// as a rotation of 3 angles (ZYX, XYZ, etc).
56+
class IGNITION_SDFORMAT_USD_VISIBLE UDSTransforms
57+
{
58+
public:
59+
/// \brief Scale of the schema
60+
ignition::math::Vector3d scale{1, 1, 1};
61+
62+
/// \brief Rotation of the schema
63+
std::vector<ignition::math::Quaterniond> q;
64+
65+
/// \brief Translatio of the schema
66+
ignition::math::Vector3d translate{0, 0, 0};
67+
68+
/// \brief True if there is a rotation ZYX definedor false otherwise
69+
bool isRotationZYX = false;
70+
71+
/// \brief True if there is a rotation (as a quaterion) defined
72+
/// or false otherwise
73+
bool isRotation = false;
74+
75+
/// \brief True if there is a translation defined or false otherwise
76+
bool isTranslate = false;
77+
};
78+
79+
/// \brief This function will parse all the parents transforms of a prim
80+
/// This will stop when the name of the parent is the same as _schemaToStop
81+
/// \param[in] _prim Initial prim to read the transform
82+
/// \param[in] _usdData USDData structure to get info about the prim, for
83+
/// example: metersperunit
84+
/// \param[out] _tfs A vector with all the transforms
85+
/// \param[out] _scale The scale of the prims
86+
/// \param[in] _schemaToStop Name of the prim where the loop will stop
87+
/// reading transforms
88+
void IGNITION_SDFORMAT_USD_VISIBLE GetAllTransforms(
89+
const pxr::UsdPrim &_prim,
90+
USDData &_usdData,
91+
std::vector<ignition::math::Pose3d> &_tfs,
92+
ignition::math::Vector3d &_scale,
93+
const std::string &_schemaToStop);
94+
95+
/// \brief This function get the transform from a prim to the specified
96+
/// schemaToStop variable
97+
/// This will stop when the name of the parent is the same as _schemaToStop
98+
/// \param[in] _prim Initial prim to read the transform
99+
/// \param[in] _usdData USDData structure to get info about the prim, for
100+
/// example: metersperunit
101+
/// \param[out] _pose Pose of the prim
102+
/// \param[out] _scale The scale of the prim
103+
/// \param[in] _schemaToStop Name of the prim where the loop will stop
104+
/// reading transforms
105+
void IGNITION_SDFORMAT_USD_VISIBLE GetTransform(
106+
const pxr::UsdPrim &_prim,
107+
USDData &_usdData,
108+
ignition::math::Pose3d &_pose,
109+
ignition::math::Vector3d &_scale,
110+
const std::string &_schemaToStop);
111+
112+
/// \brief Read the usd prim transforms. Scale, rotation or transform might
113+
/// be defined as float or doubles
114+
/// \param[in] _prim Prim where the transforms are read
115+
UDSTransforms IGNITION_SDFORMAT_USD_VISIBLE ParseUSDTransform(
116+
const pxr::UsdPrim &_prim);
117+
}
118+
}
119+
}
120+
#endif

usd/src/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ set(sources
1515
usd_parser/USDData.cc
1616
usd_parser/USDStage.cc
1717
usd_parser/USDMaterial.cc
18+
usd_parser/USDUtils.cc
1819
)
1920

2021
ign_add_component(usd SOURCES ${sources} GET_TARGET_NAME usd_target)
@@ -43,6 +44,7 @@ set(gtest_sources
4344
sdf_parser/World_Sdf2Usd_TEST.cc
4445
usd_parser/USDData_TEST.cc
4546
usd_parser/USDStage_TEST.cc
47+
usd_parser/USDUtils_TEST.cc
4648
UsdError_TEST.cc
4749
UsdUtils_TEST.cc
4850
)

0 commit comments

Comments
 (0)