33#ifndef DART_UTILS_DETAIL_XMLHELPERS_IMPL_HPP_
34#define DART_UTILS_DETAIL_XMLHELPERS_IMPL_HPP_
42template <
typename S,
int N>
43std::string
toString(
const Eigen::Matrix<S, N, 1>& v)
53 const Eigen::Transform<S, 3, Eigen::Isometry>& v,
54 const std::string& rotationType)
56 Eigen::Matrix<S, 3, 1> angles;
57 if (rotationType ==
"intrinsic")
61 else if (rotationType ==
"extrinsic")
68 "Unsupported rotation type [{}]. Assuming intrinsic.", rotationType);
74 ss << v.translation().transpose() <<
" ";
81template <std::
size_t N>
82Eigen::Matrix<double, N, 1>
toVectorNd(
const std::string& str)
85 const std::size_t sizeToRead = std::min(N, pieces.size());
86 if (pieces.size() < N)
88 dterr <<
"Failed to read a vector because the dimension '" << pieces.size()
89 <<
"' is less than the expectation '" << N <<
"'.\n";
91 else if (pieces.size() > N)
93 dterr <<
"Failed to read a vector because the dimension '" << pieces.size()
94 <<
"' is greater than the expectation '" << N <<
"'.\n";
97 Eigen::Matrix<double, N, 1> ret = Eigen::Matrix<double, N, 1>::Zero();
99 for (std::size_t i = 0; i < sizeToRead; ++i)
107 catch (std::exception& e)
109 dterr <<
"value [" << pieces[i]
110 <<
"] is not a valid double for Eigen::Vector" << N <<
"d[" << i
111 <<
"]: " << e.what() <<
"\n";
120template <std::
size_t N>
122 const tinyxml2::XMLElement* element,
const std::string& attributeName)
125 return toVectorNd<N>(val);
129template <
typename ElementType>
131 ElementPtr parentElement,
const std::string& childElementName)
132 : mParentElement(parentElement),
133 mChildElementName(childElementName),
134 mCurrentElement(nullptr)
140template <
typename ElementType>
147template <
typename ElementType>
156 = mCurrentElement->NextSiblingElement(mChildElementName.c_str());
161 = mParentElement->FirstChildElement(mChildElementName.c_str());
165 mParentElement =
nullptr;
171template <
typename ElementType>
175 return mCurrentElement;
179template <
typename ElementType>
183 return mCurrentElement;
187template <
typename ElementType>
191 return *mCurrentElement;
195template <
typename ElementType>
202 && (this->mCurrentElement !=
nullptr
207template <
typename ElementType>
220template <
typename ElementType>
223 return mCurrentElement !=
nullptr;
#define dterr
Output an error message.
Definition Console.hpp:49
#define DART_ERROR(...)
Definition Logging.hpp:76
bool valid
Definition SkelParser.cpp:1674
TemplatedElementEnumerator is a convenience class to help visiting all the child elements of given pa...
Definition XmlHelpers.hpp:179
bool next()
Set the current element to the next sibling element or to the first child element of given parent ele...
Definition XmlHelpers-impl.hpp:148
ElementPtr operator->() const
Dereference operator.
Definition XmlHelpers-impl.hpp:181
ElementType & ElementRef
Definition XmlHelpers.hpp:182
~TemplatedElementEnumerator()
Destructor.
Definition XmlHelpers-impl.hpp:141
ElementRef operator*() const
Dereference operator.
Definition XmlHelpers-impl.hpp:189
ElementPtr get() const
Get the current element.
Definition XmlHelpers-impl.hpp:173
bool operator==(const TemplatedElementEnumerator< ElementType > &rhs) const
Equality operator.
Definition XmlHelpers-impl.hpp:196
ElementPtr mCurrentElement
Currently visiting child element.
Definition XmlHelpers.hpp:224
bool valid() const
Returns true if the current element is valid (not a nullptr)
Definition XmlHelpers-impl.hpp:221
std::string mChildElementName
Child element name.
Definition XmlHelpers.hpp:221
TemplatedElementEnumerator< ElementType > & operator=(const TemplatedElementEnumerator< ElementType > &rhs)
Assignment operator.
Definition XmlHelpers-impl.hpp:209
ElementType * ElementPtr
Definition XmlHelpers.hpp:181
TemplatedElementEnumerator(ElementPtr parentElement, const std::string &childElementName)
Constructor that takes parent element and.
Definition XmlHelpers-impl.hpp:130
ElementPtr mParentElement
Parent element.
Definition XmlHelpers.hpp:218
std::vector< std::string > split(const std::string &str, const std::string &delimiters)
Splits string given delimiters.
Definition String.cpp:86
std::string trim(const std::string &str, const std::string &whitespaces)
Trims both sides of string.
Definition String.cpp:66
Eigen::Vector3d matrixToEulerXYZ(const Eigen::Matrix3d &_R)
get the Euler XYZ angle from R
Definition Geometry.cpp:117
Eigen::Vector3d matrixToEulerZYX(const Eigen::Matrix3d &_R)
get the Euler ZYX angle from R
Definition Geometry.cpp:151
Eigen::Matrix< double, N, 1 > toVectorNd(const std::string &str)
Definition XmlHelpers-impl.hpp:82
double toDouble(const std::string &str)
Definition XmlHelpers.cpp:117
Eigen::Matrix< double, N, 1 > getAttributeVectorNd(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition XmlHelpers-impl.hpp:121
std::string toString(const Eigen::Matrix< S, N, 1 > &v)
Definition XmlHelpers-impl.hpp:43
std::string getAttributeString(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition XmlHelpers.cpp:732