6 #ifndef CNOID_BODY_BODY_MOTION_H
7 #define CNOID_BODY_BODY_MOTION_H
9 #include <cnoid/MultiValueSeq>
10 #include <cnoid/MultiSE3Seq>
11 #include <cnoid/Signal>
12 #include <cnoid/NullOut>
14 #include "exportdecl.h"
26 using AbstractSeq::operator=;
28 virtual std::shared_ptr<AbstractSeq> cloneSeq()
const override;
30 void setDimension(
int numFrames,
int numJoints,
int numLinks,
bool clearNewArea =
false);
31 void setNumJoints(
int numJoints,
bool clearNewElements =
false);
33 int numLinks()
const {
return linkPosSeq_->numParts(); }
34 int numJoints()
const {
return jointPosSeq_->numParts(); }
36 double frameRate()
const;
37 virtual double getFrameRate()
const override;
38 virtual void setFrameRate(
double frameRate)
override;
40 double timeStep()
const;
42 virtual double getOffsetTime()
const override;
43 virtual void setOffsetTime(
double time)
override;
45 int numFrames()
const;
46 virtual int getNumFrames()
const override;
47 virtual void setNumFrames(
int n,
bool clearNewArea =
false)
override;
68 Frame(
BodyMotion& motion,
int frame) : motion_(motion), frame_(frame) { }
69 Frame& operator=(
const Frame&) {
return *
this; }
72 Frame(
const Frame& org) : motion_(org.motion_), frame_(org.frame_) { }
75 int frame()
const {
return frame_; }
91 int frame()
const {
return frame_; }
98 bool load(
const std::string& filename, std::ostream& os =
nullout());
99 bool save(
const std::string& filename, std::ostream& os =
nullout());
100 bool save(
const std::string& filename,
double version, std::ostream& os =
nullout());
102 typedef std::map<std::string, std::shared_ptr<AbstractSeq>>
ExtraSeqMap;
108 template <
class SeqType>
109 std::shared_ptr<SeqType>
extraSeq(
const std::string& name)
const {
110 ExtraSeqMap::const_iterator p = extraSeqs.find(name);
111 return ((p != extraSeqs.end()) ?
112 std::dynamic_pointer_cast<SeqType>(p->second) : std::shared_ptr<SeqType>());
115 void setExtraSeq(
const std::string& name, std::shared_ptr<AbstractSeq> seq);
117 template <
class SeqType>
119 std::shared_ptr<AbstractSeq>& base = extraSeqs[name];
120 std::shared_ptr<SeqType> seq;
122 seq = std::dynamic_pointer_cast<SeqType>(base);
125 seq = std::make_shared<SeqType>();
127 seq->setFrameRate(frameRate());
128 seq->setNumFrames(numFrames());
129 sigExtraSeqsChanged_();
134 void clearExtraSeq(
const std::string& name);
137 return sigExtraSeqsChanged_;
142 setNumJoints(numJoints, clearNewElements);
150 return load(filename, os);
154 return save(filename, os);
158 virtual bool doReadSeq(
const Mapping* archive, std::ostream& os)
override;
159 virtual bool doWriteSeq(
YAMLWriter& writer, std::function<
void()> additionalPartCallback)
override;
162 std::shared_ptr<MultiSE3Seq> linkPosSeq_;
163 std::shared_ptr<MultiValueSeq> jointPosSeq_;
164 ExtraSeqMap extraSeqs;
165 Signal<void()> sigExtraSeqsChanged_;
168 CNOID_EXPORT BodyMotion::Frame
operator<<(BodyMotion::Frame frame,
const Body& body);
169 CNOID_EXPORT BodyMotion::Frame
operator>>(BodyMotion::Frame frame,
const Body& body);
170 CNOID_EXPORT BodyMotion::ConstFrame
operator>>(BodyMotion::ConstFrame frame, Body& body);
171 CNOID_EXPORT Body&
operator<<(Body& body, BodyMotion::Frame frame);
172 CNOID_EXPORT Body&
operator<<(Body& body, BodyMotion::ConstFrame frame);
173 CNOID_EXPORT
const Body&
operator>>(
const Body& body, BodyMotion::Frame frame);
175 #ifdef CNOID_BACKWARD_COMPATIBILITY
176 typedef std::shared_ptr<BodyMotion> BodyMotionPtr;