22 #include "MAMotionSkit.hpp" 24 #include "core/MADevice.hpp" 25 #include "core/MAValueGenerators.hpp" 26 #include "MASkitDatabase.hpp" 28 #include <MCContainers.hpp> 29 #include <MCThreadLocalData.hpp> 31 #include <boost/algorithm/string.hpp> 32 #include <boost/math/constants/constants.hpp> 39 void CheckStaticMtnParserVariables()
41 if (unlikely(!JointNames.get()))
43 JointNames.reset(
new MC::StringList);
64 boost::split(Strs,
Name, boost::is_any_of(
"#"));
66 boost::split(Strs, TempStr, boost::is_any_of(
"_"));
67 Strs.erase(Strs.begin());
68 TempStr = boost::algorithm::join(Strs,
"_");
83 *NewMotionSkit = *
this;
85 MCSwapTableColumns<int, MC::IntTable>(NewMotionSkit->Keyframes, 7, 13);
86 MCSwapTableColumns<int, MC::IntTable>(NewMotionSkit->Keyframes, 8, 14);
87 MCSwapTableColumns<int, MC::IntTable>(NewMotionSkit->Keyframes, 9, 15);
89 MCSwapTableColumns<int, MC::IntTable>(NewMotionSkit->Keyframes, 10, 16);
90 MCSwapTableColumns<int, MC::IntTable>(NewMotionSkit->Keyframes, 11, 17);
91 MCSwapTableColumns<int, MC::IntTable>(NewMotionSkit->Keyframes, 12, 18);
98 MC_LOG(
"-- %s motion keyframes --",
Name.c_str());
101 MC_LOG(
"Starting posture: SIT");
105 MC_LOG(
"Starting posture: LIE");
109 MC_LOG(
"Starting posture: STAND");
111 for (
unsigned int i = 0; i <
Keyframes.size(); ++i)
116 Message.append(
">> Time: ");
118 Message.append(
" ms | ");
119 for (
unsigned int i1 = 1; i1 <
Keyframes[i].size(); ++i1)
121 Message.append((*JointNames)[i1-1]+
": ");
122 if ((*JointNames)[i1-1].find(
"Leg") != std::string::npos)
124 if ((*JointNames)[i1-1].find(
"1") != std::string::npos)
130 if ((*JointNames)[i1-1] ==
"LegLH1" || (*JointNames)[i1-1] ==
"LegRH1")
140 if ((*JointNames)[i1-1].find(
"2") != std::string::npos)
148 if ((*JointNames)[i1-1].find(
"3") != std::string::npos)
157 if ((*JointNames)[i1-1].find(
"Neck") != std::string::npos)
159 if ((*JointNames)[i1-1].find(
"NeckTilt1") != std::string::npos)
164 if ((*JointNames)[i1-1].find(
"NeckTilt2") != std::string::npos)
168 Position.FromJointDegrees(NeckTilt1,
Keyframes[i][i1]);
173 if ((*JointNames)[i1-1].find(
"NeckPan") != std::string::npos)
182 if ((*JointNames)[i1-1] ==
"Mouth")
193 Message.append(
" | ");
195 MC_LOG(
"%s", Message.c_str());
200 MC_LOG(
"Finishing posture: SIT");
204 MC_LOG(
"Finishing posture: LIE");
208 MC_LOG(
"Finishing posture: STAND");
210 MC_LOG(
"Finishing posture: N/A");
263 MC_WARNING(
"Wrong file signature, can't decode motion sequence");
280 int KeyframeCount = BinaryData.
GetInt16(
true);
281 int FrameRate = BinaryData.
GetInt16(
true);
291 BlockSize = BinaryData.
GetInt32(
true);
293 if (KeyframeCount == 0 || FrameRate == 0 || BinaryData.
IsPositionAtEnd())
295 MC_WARNING(
"Empty motion data while decoding motion sequence");
300 TempInt = (int)BinaryData.
GetUChar();
302 TempStr = BinaryData.
GetString(TempInt,
"_#-:|");
303 BlockSize -= TempInt;
306 MC_WARNING(
"Can't read motion name (chunk) while decoding motion sequence");
312 MotionSequence->
Name = MA::SkitNamePrefix+TempStr;
314 TempInt = (int)BinaryData.
GetUChar();
316 TempStr = BinaryData.
GetString(TempInt,
"_#-:|");
317 BlockSize -= TempInt;
320 MC_WARNING(
"Can't read the creator while decoding motion sequence");
321 delete MotionSequence;
326 TempInt = (int)BinaryData.
GetUChar();
328 TempStr = BinaryData.
GetString(TempInt,
"-");
329 BlockSize -= TempInt;
332 MC_WARNING(
"Incompatible hardware platform, it is not ERS-7 (DRX-1000 != %s)", TempStr.c_str());
333 delete MotionSequence;
339 MC_WARNING(
"Can't decode the block 1 successfully while decoding motion sequence");
340 delete MotionSequence;
352 BlockSize = BinaryData.
GetInt32(
true);
355 int JointCount = BinaryData.
GetInt16(
true);
358 CheckStaticMtnParserVariables();
359 bool JointNamesReady = !JointNames->empty();
362 for (
int i = 0; i < JointCount; ++i)
364 TempInt = (int)BinaryData.
GetUChar();
366 TempStr = BinaryData.
GetString(TempInt,
":/-");
367 BlockSize -= TempInt;
370 MC_WARNING(
"Can't decode the joint names while decoding motion sequence");
371 delete MotionSequence;
373 if (!JointNamesReady)
379 if (!JointNamesReady)
381 JointNames->push_back(MADevice::GetMotorDisplayName(TempStr));
386 MC_WARNING(
"Can't decode the block 2 successfully while decoding motion sequence");
387 delete MotionSequence;
399 BlockSize = BinaryData.
GetInt32(
true);
401 for (
int i = 0; i < KeyframeCount; ++i)
403 MC::IntList KeyframeValues;
406 TempInt = BinaryData.
GetInt32(
true);
408 KeyframeValues.push_back(TempInt*FrameRate);
414 for (
int i1 = 0; i1 < JointCount; ++i1)
416 float TempFloat = (float)BinaryData.
GetInt32(
true);
419 KeyframeValues.push_back((
int)roundf(TempFloat*180.0 /
420 (1000000.0*boost::math::constants::pi<float>())));
424 MC_WARNING(
"Can't decode the key frame %d while decoding motion sequence", i);
425 delete MotionSequence;
430 if (i > 0 && KeyframeValues[0] == 0)
435 MotionSequence->
Keyframes.push_back(KeyframeValues);
441 MC_LOG(
"Decoded motion sequence: %s", MotionSequence->
Name.c_str());
442 return MotionSequence;
447 MA::LegJointsType joint)
const 449 if (leg == MA::Leg::LF)
451 if (joint == MA::LegJoint1)
453 if (joint == MA::LegJoint2)
455 if (joint == MA::LegJoint3)
458 if (leg == MA::Leg::LH)
460 if (joint == MA::LegJoint1)
462 if (joint == MA::LegJoint2)
464 if (joint == MA::LegJoint3)
467 if (leg == MA::Leg::RF)
469 if (joint == MA::LegJoint1)
471 if (joint == MA::LegJoint2)
473 if (joint == MA::LegJoint3)
476 if (leg == MA::Leg::RH)
478 if (joint == MA::LegJoint1)
480 if (joint == MA::LegJoint2)
482 if (joint == MA::LegJoint3)
491 if (tail_joint == MA::TailTilt)
501 if (head_joint == MA::NeckTilt1)
503 if (head_joint == MA::NeckPan)
505 if (head_joint == MA::NeckTilt2)
507 if (head_joint == MA::MouthJoint)
509 if (head_joint == MA::EarLeft)
521 MC_WARNING(
"Invalid keyframe for sit posture check (%d > %d)", keyframe_index,
528 Result = Result &&
Keyframes[keyframe_index][7] == -25;
530 Result = Result && Keyframes[keyframe_index][8] == -4;
532 Result = Result && Keyframes[keyframe_index][9] == 20;
534 Result = Result && Keyframes[keyframe_index][10] == -78;
536 Result = Result && Keyframes[keyframe_index][11] == 20;
538 Result = Result && Keyframes[keyframe_index][12] == 110;
540 Result = Result && Keyframes[keyframe_index][13] == -25;
542 Result = Result && Keyframes[keyframe_index][14] == -4;
544 Result = Result && Keyframes[keyframe_index][15] == 20;
546 Result = Result && Keyframes[keyframe_index][16] == -78;
548 Result = Result && Keyframes[keyframe_index][17] == 20;
550 Result = Result && Keyframes[keyframe_index][18] == 110;
559 MC_WARNING(
"Invalid keyframe for lie posture check (%d > %d)", keyframe_index,
566 Result = Result && (
Keyframes[keyframe_index][7] >= 59 && Keyframes[keyframe_index][7] <= 69);
568 Result = Result && Keyframes[keyframe_index][8] == 0;
570 Result = Result && Keyframes[keyframe_index][9] == 30;
572 Result = Result && (Keyframes[keyframe_index][10] >= -129 && Keyframes[keyframe_index][10] <= -119);
574 Result = Result && Keyframes[keyframe_index][11] == 4;
576 Result = Result && Keyframes[keyframe_index][12] == 122;
578 Result = Result && (Keyframes[keyframe_index][13] >= 59 && Keyframes[keyframe_index][13] <= 69);
580 Result = Result && Keyframes[keyframe_index][14] == 0;
582 Result = Result && Keyframes[keyframe_index][15] == 30;
584 Result = Result && (Keyframes[keyframe_index][16] >= -129 && Keyframes[keyframe_index][16] <= -119);
586 Result = Result && Keyframes[keyframe_index][17] == 4;
588 Result = Result && Keyframes[keyframe_index][18] == 122;
597 MC_WARNING(
"Invalid keyframe for stand posture check (%d > %d)", keyframe_index,
604 Result = Result &&
Keyframes[keyframe_index][7] == -5;
606 Result = Result && Keyframes[keyframe_index][8] == 3;
608 Result = Result && Keyframes[keyframe_index][9] == 30;
610 Result = Result && Keyframes[keyframe_index][10] == -5;
612 Result = Result && Keyframes[keyframe_index][11] == 3;
614 Result = Result && Keyframes[keyframe_index][12] == 30;
616 Result = Result && Keyframes[keyframe_index][13] == -5;
618 Result = Result && Keyframes[keyframe_index][14] == 3;
620 Result = Result && Keyframes[keyframe_index][15] == 30;
622 Result = Result && Keyframes[keyframe_index][16] == -5;
624 Result = Result && Keyframes[keyframe_index][17] == 3;
626 Result = Result && Keyframes[keyframe_index][18] == 30;
632 bool invert_value)
const 634 if (column_index == 0 || column_index >
Keyframes[0].size()-1)
636 MC_WARNING(
"Invalid column index to get a generator container (0 < %d <= %d?)",
642 for (
unsigned int i = 1; i <
Keyframes.size(); ++i)
646 if (unlikely(invert_value))
MANum< float > Value
Current value.
int16_t GetInt16(bool reverse_order=false)
Get a 16 bit integer from the current position.
virtual void FromJointDegree(int degree) override
Compute from a joint degree value.
bool IsPostureSit(unsigned int keyframe_index) const
Check if a keyframe posture is sit.
void AddGenerator(MAGeneratorBase &generator, bool in_front=false)
Add a new generator after the last internal generator.
MANum< float > UpDownValue
Current up-down direction value.
The forward-backward/upward-downward feature of a leg joint.
MANum< float > UpDownValue
Current up-down direction value.
std::string GetName() const
Get the motion name.
virtual void FromJointDegree(int degree) override
Compute from a joint degree value.
bool IsPostureLie(unsigned int keyframe_index) const
Check if a keyframe posture is lie.
bool IsFinishingPostureStand() const
Check if the finishing posture is stand.
virtual void FromJointDegree(int degree) override
Compute from a joint degree value.
unsigned char GetUChar()
Get an unsigned char from the current position.
std::string Name
Motion name.
virtual void FromJointDegree(int degree) override
Compute from a joint degree value.
#define MC_WARNING(...)
Warning macro.
std::string MCToStr(const T value, bool hex_manipulator=false)
Convert an other type to string with std::stringstream.
static MAMotionSkit * DecodeMtnData(const MCBinaryData &binary_data)
Load motion sequence from binary data.
std::string GetString(unsigned int length, const std::string &additional_chars="")
Get a string from the current position.
MANum< float > ForeBackValue
Current fore-back direction value.
bool IsFinishingPostureSit() const
Check if the finishing posture is sit.
void SetPosition(unsigned int position)
Set the cursor position.
bool IsStartingPostureSit() const
Check if the starting posture is sit.
MC::IntTable Keyframes
Keyframes (first column - timestamp, other columns - joint values)
void IncrementPosition(unsigned int position=1)
Increment the cursor position.
MAMotionSkit()
Class constructor.
The left-right turning feature of the head.
void Dump() const
Print the motion skit information.
bool IsStartingPostureStand() const
Check if the starting posture is stand.
The bent-stretched feature of a leg joint.
virtual void FromJointDegree(int degree) override
Compute from a joint degree value.
Generator container class.
MA::MotionSkitSPtr CloneMirrored() const
Clone with mirrored leg joint trajectories between left and right sides.
MAGeneratorContainer * GetGeneratorContainer(MA::Leg::LegTypes leg, MA::LegJointsType joint) const
Get generator container for a leg joint.
The sidelong feature of a leg joint.
Motion sequence (motion skit) class.
bool IsFinishingPostureLie() const
Check if the finishing posture is lie.
int32_t GetInt32(bool reverse_order=false)
Get a 32 bit integer from the current position.
A wrapper class to cover boost::thread_specific_ptr/folly::ThreadLocal API on certain targets...
int GetDuration() const
Get skit duration.
The opened-closed position of the mouth.
#define MC_LOG(...)
Debug macro.
int SkitDuration
Skit duration (in msec)
MANum< float > ForeBackValue
Current fore-back direction value.
int GetPosition() const
Get the current position in the binary data.
The fore-back, up-down position of the head.
bool IsPositionAtEnd() const
Check if the current position is at the end of the binary data.
bool IsPostureStand(unsigned int keyframe_index) const
Check if a keyframe posture is stand.
bool IsStartingPostureLie() const
Check if the starting posture is lie.
std::string GetSkitName() const
Get skit name generated from motion name.