14 #ifndef LIB_ALMATH_SCENEGRAPH_RIGIDBODYSYSTEMBUILDER_H
15 #define LIB_ALMATH_SCENEGRAPH_RIGIDBODYSYSTEMBUILDER_H
19 #include <Eigen/Geometry>
21 #include <boost/format.hpp>
26 namespace RigidBodySystemBuilder {
38 std::string
joint_name(
const std::string &body_name)
const {
52 typedef Eigen::Transform<Scalar, 3, Eigen::AffineCompact, Eigen::DontAlign>
74 typedef Eigen::Transform<Scalar, 3, Eigen::AffineCompact, Eigen::DontAlign>
102 virtual const Config &config()
const = 0;
103 virtual void addLink(Link link) = 0;
104 virtual void addStaticFrame(StaticFrame sframe) = 0;
107 void add(
const std::string &parent_body,
const std::string &new_body,
109 const BodyMass &mass,
const std::string &new_joint) {
110 addLink(
Link{parent_body, new_body, new_joint, H_parent_joint, joint_type,
113 void add(
const std::string &parent_body,
const std::string &new_body,
116 add(parent_body, new_body, H_parent_joint, joint_type, mass,
117 this->config().joint_name(new_body));
125 if (this->config().no_static_frame)
return;
133 add(parent_frame, new_static_frame, H_parent_new,
134 this->config().joint_name(new_static_frame));
138 #define TYPEDEF_Interface_TYPES \
139 typedef typename Interface<T>::Scalar Scalar; \
140 typedef typename Interface<T>::Link Link; \
141 typedef typename Interface<T>::BodyMass BodyMass; \
142 typedef typename Interface<T>::Vector3 Vector3; \
143 typedef typename Interface<T>::Matrix3 Matrix3; \
144 typedef typename Interface<T>::StaticFrame StaticFrame; \
145 typedef typename Interface<T>::AffineCompact3 AffineCompact3
148 template <
typename T>
160 _builder.addStaticFrame(sframe);
167 template <
typename TD,
typename TB>
176 _builder.addLink(link.template cast<TB>());
180 _builder.addStaticFrame(sframe.template cast<TB>());
187 template <
typename T>
196 std::stringstream ss;
197 ss <<
"cannot add body \"" << link.
new_body
198 <<
"\": unknown parent body \"" << link.
parent_body <<
"\"";
199 throw std::runtime_error(ss.str());
202 std::stringstream ss;
203 ss <<
"cannot add body \"" << link.
new_body <<
"\":"
204 <<
" there is already a frame with this name";
205 throw std::runtime_error(ss.str());
208 std::stringstream ss;
209 ss <<
"cannot add joint \"" + link.
new_joint +
"\":"
210 <<
" there is already a transform with this name";
211 throw std::runtime_error(ss.str());
213 this->_builder.addLink(link);
214 _known_bodies.insert(link.
new_body);
220 throw std::runtime_error(
222 "\": unknown parent frame \"" + sframe.
parent_frame +
"\"");
226 throw std::runtime_error(
"cannot add static frame \"" +
228 "\": there is already a frame with this name");
231 throw std::runtime_error(
233 "\": there is already a transform with this name");
235 this->_builder.addStaticFrame(sframe);
242 std::set<std::string> _known_bodies =
243 std::set<std::string>({this->_builder.config().galilean_frame});
244 std::set<std::string> _known_joints;
245 std::set<std::string> _known_sframes;
246 std::set<std::string> _known_stransforms;
248 bool xIsKnownBody(
const std::string &
name)
const {
249 return _known_bodies.find(name) != _known_bodies.end();
253 bool xIsKnownFrame(
const std::string &name)
const {
254 return xIsKnownBody(name) ||
255 (_known_sframes.find(name) != _known_sframes.end());
258 bool xIsKnownJoint(
const std::string &name)
const {
259 return _known_joints.find(name) != _known_joints.end();
263 bool xIsKnownTransform(
const std::string &name)
const {
264 return xIsKnownJoint(name) ||
265 (_known_stransforms.find(name) != _known_stransforms.end());
269 template <
typename T>
276 this->_builder.addLink(link);
280 #undef TYPEDEF_Interface_TYPES
StaticFrameData< Scalar > StaticFrame
void add(const std::string &parent_body, const std::string &new_body, const AffineCompact3 &H_parent_joint, JointType joint_type, const BodyMass &mass)
Eigen::Transform< Scalar, 3, Eigen::AffineCompact, Eigen::DontAlign > AffineCompact3
virtual void addLink(Link link)
std::string joint_name(const std::string &body_name) const
BodyMass::Matrix3 Matrix3
ALMATH_API std::string name(const ptree &pt)
virtual void addLink(LinkData< TD > link)
Interface< T > & _builder
virtual void addStaticFrame(StaticFrameData< TD > sframe)
AffineCompact3 pose_parent_new
LinkData< S > cast() const
Eigen::Transform< Scalar, 3, Eigen::AffineCompact, Eigen::DontAlign > AffineCompact3
std::string joint_name_format
const Config & config() const
void add(const std::string &parent_frame, const std::string &new_static_frame, const AffineCompact3 &H_parent_new, const std::string &new_static_transform)
AffineCompact3 pose_parent_new
std::string new_static_transform
void addStaticFrame(StaticFrame sframe)
void add(const std::string &parent_body, const std::string &new_body, const AffineCompact3 &H_parent_joint, JointType joint_type, const BodyMass &mass, const std::string &new_joint)
Adapter(Interface< TB > &builder)
BodyMass::Matrix3 Matrix3
BodyMass::Vector3 Vector3
Decorator(Interface< T > &builder)
const Config & config() const
Eigen::Matrix< Scalar, 3, 3, Eigen::DontAlign > Matrix3
Eigen::Matrix< Scalar, 3, 1, Eigen::DontAlign > Vector3
Interface< TB > & _builder
virtual void addStaticFrame(StaticFrame sframe)
std::string galilean_frame
NamesChecker(Interface< T > &builder)
void add(const std::string &parent_frame, const std::string &new_static_frame, const AffineCompact3 &H_parent_new)
InertiaEraser(Interface< T > &builder)
Math::BodyMass< Scalar > BodyMass
StaticFrameData< S > cast() const
BodyMass::Vector3 Vector3
StaticFrame::AffineCompact3 AffineCompact3
Matrix3 rotational_inertia
std::string new_static_frame