Go to the documentation of this file.
6 #ifndef CNOID_BODY_BODY_H
7 #define CNOID_BODY_BODY_H
12 #include "exportdecl.h"
32 Body(
const std::string& name);
37 void copyFrom(
const Body* org,
CloneMap* cloneMap =
nullptr);
41 virtual Link* createLink(
const Link* org =
nullptr)
const;
43 const std::string& name()
const;
44 void setName(
const std::string& name);
45 const std::string& modelName()
const;
46 void setModelName(
const std::string& name);
48 void setRootLink(
Link* link);
50 [[deprecated(
"This func. does nothing")]]
56 void updateLinkTree();
58 void initializePosition();
59 virtual void initializeState();
61 Body*
parentBody()
const {
return parentBodyLink_ ? parentBodyLink_->body() :
nullptr; }
63 void setParent(
Link* parentBodyLink);
65 void syncPositionWithParentBody(
bool doForwardKinematics =
true);
72 return linkTraverse_.numLinks();
81 return linkTraverse_.link(index);
88 Link* link(
const std::string& name)
const;
97 const std::vector<Link*>&
links()
const {
98 return linkTraverse_.links();
108 Link* findUniqueEndLink()
const;
109 Link* lastSerialLink()
const;
121 return numActualJoints;
130 return static_cast<int>(jointIdToLinkArray.size()) - numActualJoints;
137 return static_cast<int>(jointIdToLinkArray.size());
146 return jointIdToLinkArray[id];
153 Link* joint(
const std::string& name)
const;
168 jointIdToLinkArray.begin(), jointIdToLinkArray.begin() + numActualJoints);
171 const std::vector<LinkPtr>&
allJoints()
const {
return jointIdToLinkArray; }
174 return static_cast<int>(devices_.size());
193 template<
class DeviceType> DeviceType*
findDevice(
const std::string& name)
const {
194 return dynamic_cast<DeviceType*
>(findDeviceSub(name));
198 for(
auto& device : devices_)
199 if(
auto found =
dynamic_cast<DeviceType*
>(device.get()))
205 return findDeviceSub(name);
209 [[deprecated(
"Use addDevice(Device* device, Link* link)")]]
210 void addDevice(
Device* device);
211 void removeDevice(
Device* device);
213 void sortDevicesByLinkOrder();
214 void initializeDeviceStates();
220 return isStaticModel_;
223 return rootLink_->isFixedJoint();
226 void resetDefaultPosition(
const Isometry3& T);
231 const Vector3& calcCenterOfMass();
232 const Vector3& centerOfMass()
const;
237 linkTraverse_.calcForwardKinematics(calcVelocity, calcAcceleration);
240 void clearExternalForces();
251 template<
typename T> T info(
const std::string& key)
const;
252 template<
typename T> T info(
const std::string& key,
const T& defaultValue)
const;
253 template<
typename T>
void setInfo(
const std::string& key,
const T& value);
257 void cloneShapes(
CloneMap& cloneMap);
259 template<
class T> T*
findCache(
const std::string& name){
260 return dynamic_cast<T*
>(findCacheSub(name));
263 template<
class T>
const T*
findCache(
const std::string& name)
const {
264 return dynamic_cast<const T*
>(findCacheSub(name));
268 T* cache = findCache<T>(name);
271 insertCache(name, cache);
277 insertCache(name, cache);
282 void removeCache(
const std::string& name);
284 void setCurrentTimeFunction(std::function<
double()> func);
287 bool addHandler(
BodyHandler* handler,
bool isTopPriority =
false);
290 return dynamic_cast<BodyHandlerType*
>(
291 findHandler([](
BodyHandler* handler)->
bool{
return dynamic_cast<BodyHandlerType*
>(handler); }));
294 int numHandlers()
const;
300 bool installCustomizer();
302 bool hasVirtualJointForces()
const;
303 void setVirtualJointForces(
double timeStep = 0.0);
304 static void addCustomizerDirectory(
const std::string& path);
307 void resetLinkName(
Link* link,
const std::string& name);
308 void resetJointSpecificName(
Link* link);
309 void resetJointSpecificName(
Link* link,
const std::string& name);
320 std::vector<LinkPtr> jointIdToLinkArray;
323 std::vector<ExtraJoint> extraJoints_;
324 std::function<double()> currentTimeFunction;
330 Link* createEmptyJoint(
int jointId);
331 Device* findDeviceSub(
const std::string& name)
const;
332 Referenced* findCacheSub(
const std::string& name);
333 const Referenced* findCacheSub(
const std::string& name)
const;
334 void insertCache(
const std::string& name,
Referenced* cache);
338 template<> CNOID_EXPORT
double Body::info(
const std::string& key)
const;
339 template<> CNOID_EXPORT
double Body::info(
const std::string& key,
const double& defaultValue)
const;
340 template<> CNOID_EXPORT
bool Body::info(
const std::string& key,
const bool& defaultValue)
const;
341 template<> CNOID_EXPORT
void Body::setInfo(
const std::string& key,
const double& value);
342 template<> CNOID_EXPORT
void Body::setInfo(
const std::string& key,
const bool& value);
ref_ptr< Body > BodyPtr
Definition: Body.h:26
T * getOrCreateCache(const std::string &name)
Definition: Body.h:267
int numLinks() const
Definition: Body.h:71
Body * parentBody() const
Definition: Body.h:61
Definition: ValueTree.h:253
const ExtraJoint & extraJoint(int index) const
Definition: Body.h:244
void setInfo(const std::string &key, const T &value)
Body * clone() const
Definition: Body.h:38
Eigen::Vector3d Vector3
Definition: EigenTypes.h:57
Link * parentBodyLink() const
Definition: Body.h:62
Device * device(int index) const
Definition: Body.h:177
DeviceType * findDevice(const std::string &name) const
Definition: Body.h:193
void setCache(const std::string &name, Referenced *cache)
Definition: Body.h:276
Container::iterator iterator
Definition: Body.h:157
void clearExtraJoints()
Definition: Body.h:246
Eigen::Isometry3d Isometry3
Definition: EigenTypes.h:73
BodyHandlerType * findHandler()
Definition: Body.h:289
const T * findCache(const std::string &name) const
Definition: Body.h:263
const Isometry3 & defaultPosition() const
Definition: Body.h:227
int numAllJoints() const
Definition: Body.h:136
int numJoints() const
Definition: Body.h:120
Body * clone(CloneMap &cloneMap) const
Definition: Body.h:39
Device * findDevice(const std::string &name) const
Definition: Body.h:204
void expandLinkOffsetRotations()
Definition: Body.h:51
iterator begin()
Definition: Body.h:159
bool isFixedRootModel() const
Definition: Body.h:222
Definition: BodyCustomizerInterface.h:54
The header file of the LinkTraverse class.
Link * rootLink() const
Definition: Body.h:104
Definition: BodyCustomizerInterface.h:26
Definition: AbstractSceneLoader.h:11
Definition: ClonableReferenced.h:10
Definition: CloneMap.h:13
DeviceList< DeviceType > devices() const
Definition: Body.h:189
int numDevices() const
Definition: Body.h:173
ContainerWrapper< std::vector< LinkPtr > > joints()
Definition: Body.h:166
iterator end()
Definition: Body.h:160
Definition: BodyHandler.h:20
Definition: LinkTraverse.h:17
Link * link(int index) const
Definition: Body.h:80
void * BodyCustomizerHandle
Definition: Body.h:23
Definition: Referenced.h:54
double currentTime() const
Definition: Body.h:285
Definition: PolymorphicReferencedArray.h:14
T * findCache(const std::string &name)
Definition: Body.h:259
const DeviceList & devices() const
Definition: Body.h:185
void addExtraJoint(const ExtraJoint &extraJoint)
Definition: Body.h:245
DeviceType * findDevice() const
Definition: Body.h:197
int numVirtualJoints() const
Definition: Body.h:129
const std::vector< Link * > & links() const
Definition: Body.h:97
bool isStaticModel() const
Definition: Body.h:219
Link * joint(int id) const
Definition: Body.h:145
const LinkTraverse & linkTraverse() const
Definition: Body.h:93
Definition: DeviceList.h:16
const std::vector< LinkPtr > & allJoints() const
Definition: Body.h:171
const Mapping * info() const
Definition: Body.cpp:388
void calcForwardKinematics(bool calcVelocity=false, bool calcAcceleration=false)
Definition: Body.h:236
ExtraJoint & extraJoint(int index)
Definition: Body.h:243
ContainerWrapper(iterator begin, iterator end)
Definition: Body.h:158
int numExtraJoints() const
Definition: Body.h:242