Karlsruhe Institute of Technology (KIT) Logo

Master Motor Map

Whole-body human reference model and tools for unifying representations of whole-body human motion

[Legacy] MMM Data Format Extension

The MMMCore library provides convenient mechanisms for extending the legacy MMM data format.

Therefore interfaces exist, which can be used to implement custom data types with corresponding parser extensions. By default, the Legacy MMM parser ignores all unknwon XML tags, so that any custom extensions can be safely included to the data files without interfering with other users who might want to use the data.

See also the XML processing with rapidXML page.

See also the The Legacy MMM data format page.

MMM Extensions

Defining custom data types for root XML tags

Root XML tags are used to define parameters, comments or general purpose data whereas motion-data XML tags specify additional data for a specific timestep of the motion data.

A custom data class can be defined by deriving from MMM::MotionEntry. A short example is given below:

{
public:
CustomData():MotionEntry("MyCustomRootTag")
{
s = "not set";
}
virtual std::string toXML()
{
std::string tab = "\t";
std::stringstream res;
res << "<" << tagName << ">"<< std::endl;
res << tab << "<SecondLevelTag>" << s << "</SecondLevelTag>" << std::endl;
res << "</" << tagName << ">"<< std::endl;
return res.str();
}
std::string s;
};
typedef boost::shared_ptr<CustomData> CustomDataPtr;

The CustomData class can specify any data as long it implements an XML output method. In the constructor the XML tag name is passed to the parent's constructor in order to store it to the parent's variable tagName. In addition a factory class must be defined and registered to the MMM::LegacyMotionReaderXML in order to allow custom tag parsing. Below you find an exemplary implementation for a custom tag factory.

class CustomMotionTagReader : public MMM::XMLMotionTagProcessor
{
public:
CustomRootTagReader():XMLMotionTagProcessor(){};
virtual bool processMotionXMLTag(rapidxml::xml_node<char>* tag, MMM::MotionPtr motion )
{
if (!tag)
return false;
std::string namestr = tag->name();
if (namestr!="MyCustomRootTag")
return false;
rapidxml::xml_node<>* node = tag->first_node("secondleveltag",0,false);
if (!node)
return false;
std::string v = node->value();
CustomDataPtr cmd(new CustomData());
cmd->s = v;
return motion->addEntry("MyCustomRootTag",cmd);
}
};
typedef boost::shared_ptr<CustomMotionTagReader> CustomMotionTagReaderPtr;

The processMotionXMLTag method is called during XML parsing of the <Motion> ... </Motion> object when the corresponding XML tag is recognized (as specified on registering, see below). During parsing a Motion object is generated to which all information is stored. This instance is passed to the method, so that a custom factory may add the generated MotionEntry.

Before XML parsing the MMM::XMLMotionTagProcessor has to be registered to the MMM::LegacyMotionReaderXML:

MMM::LegacyMotionReaderXMLPtr r(new MMM::LegacyMotionReaderXML());
CustomMotionTagReaderPtr customTagProcessor(new CustomMotionTagReader());
r->registerMotionXMLTag("MyCustomRootTag",customTagProcessor);

Now, custom tags, as given in the example below, are recognized by the parser.

<?xml version='1.0' encoding='UTF-8'?>
<MMM>
<Motion name='test'>
<comments>
<text>Line1</text>
</comments>
<MyCustomMotionTag>
<SecondLevelTag>ABC</SecondLevelTag>
</MyCustomMotionTag>
...
</Motion>
</MMM>

The motion can be loaded with

MMM::LegacyMotionPtr motion = r->loadModel(filename);

Defining custom data types for MotionFrame XML tags

MotionFrame XML tags are used to define additional data for a specific timestep of the motion data. Similar to Motion XML tag extensions, custom data classes can be defined by deriving from MMM::MotionDataEntry. A short example is given below:

class CustomMotionData : public MMM::MotionDataEntry
{
public:
CustomMotionData() : MotionDataEntry("MyCustomTag")
{
s = "not set";
}
virtual std::string toXML()
{
std::string tab = "\t";
std::stringstream res;
res << tab << tab << "<" << tagName << ">"<< std::endl;
res << tab << tab << tab << "<inside>" << s << "</inside>" << std::endl;
res << tab << tab << "</" << tagName << ">"<< std::endl;
return res.str();
}
std::string s;
};
typedef boost::shared_ptr<CustomMotionData> CustomMotionDataPtr;

The CustomMotionData class can specify any data as long it implements an XML output method. In the constructor the XML tag name is passed to the parent's constructor in order to store it to the parent's variable tagName. In addition a factory class must be defined and registered to the MMM::LegacyMotionReaderXML in order to allow custom tag parsing. Below you find an exemplary implementation for a custom tag factory.

{
public:
CustomTagReader():XMLMotionFrameTagProcessor(){};
virtual bool processMotionFrameXMLTag(rapidxml::xml_node<char>* tag, MMM::MotionFramePtr motionFrame )
{
if (!tag)
return false;
std::string namestr = tag->name();
if (namestr!="MyCustomTag")
return false;
rapidxml::xml_node<>* node = tag->first_node("inside",0,false);
if (!node)
return false;
rapidxml::xml_attribute<>* attr = node->first_attribute("valid",0,false);
if (attr)
{
std::string attrValue = attr->value();
if (attrValue != "true")
return false;
}
std::string v = node->value();
CustomMotionDataPtr cmd(new CustomMotionData());
cmd->s = v;
return motiondata->addEntry("MyCustomTag",cmd);
}
};
typedef boost::shared_ptr<CustomTagReader> CustomTagReaderPtr;

The processMotionFrameXMLTag method is called during XML parsing of the MotionFrame object when the corresponding XML MotionFrame tag is recognized (as specified on registering, see below). During parsing a MotionFrame object is generated to which all information is stored. This instance is passed to the method, so that a custom factory may add the generated MotionFrameEntry.

Before XML parsing the MMM::XMLMotionFrameTagProcessor has to be registered to the MMM::LegacyMotionReaderXML:

CustomTagReaderPtr customTagProcessor(new CustomTagReader());
r->registerMotionFrameXMLTag("MyCustomTag",customTagProcessor);

Now, custom tags, as given in the example below, are recognized by the parser.

<?xml version='1.0' encoding='UTF-8'?>
<MMM>
<Motion name ='test'>
<comments>
<text>Line1</text>
</comments>
<MotionFrames>
<MotionFrame>
<timestep>0</timestep>
<MyCustomTag>
<inside valid='true'>ABC</inside>
</MyCustomTag>
<RootPosition>1 2 3</RootPosition>
<RootPositionVelocity>4 5 6</RootPositionVelocity>
<RootPositionAcceleration>7 8 9</RootPositionAcceleration>
<RootRotation>10 11 12</RootRotation>
<RootRotationVelocity>13 14 15</RootRotationVelocity>
<RootRotationAcceleration>16 17 18</RootRotationAcceleration>
</MotionFrame>
</MotionFrames>
</Motion>
</MMM>

Again, the motion can be loaded with

MMM::LegacyMotionPtr motion = r->loadModel(filename);
CustomTagReader::processMotionFrameXMLTag
bool processMotionFrameXMLTag(rapidxml::xml_node< char > *tag, MMM::MotionFramePtr motionframe) override
Derived classes must implement this factory method.
Definition: LegacyCustomXMLTest.cpp:196
MMM::XMLMotionTagProcessor::processMotionXMLTag
virtual bool processMotionXMLTag(rapidxml::xml_node< char > *tag, LegacyMotionPtr motion)=0
Derived classes must implement this factory method.
CustomTagReader
Definition: LegacyCustomXMLTest.cpp:192
MMM::XMLMotionFrameTagProcessor
Definition: LegacyMotionReaderXML.h:53
CustomRootTagReader
Definition: LegacyCustomXMLTest.cpp:41
MMM::MotionEntry
Definition: MotionEntries.h:40
CustomData
Definition: LegacyCustomXMLTest.cpp:18
MMM::MotionEntry::tagName
std::string tagName
The name of the XML tag.
Definition: MotionEntries.h:52
CustomData::toXML
std::string toXML() override
Generate XML tag.
Definition: LegacyCustomXMLTest.cpp:27
MMM::LegacyMotionReaderXML
The generic XML reader for legacy MMM motions. The following XML tags are initially supported by this...
Definition: LegacyMotionReaderXML.h:69
MMM
A template that can be used as a superclass of a class hierarchy that wants to provide a factory meth...
Definition: AbstractFactoryMethod.h:28
MMM::XMLMotionTagProcessor
Use this interface to register custom Motion XML tags. To be used for tags within a <Motion> ....
Definition: LegacyMotionReaderXML.h:40
KoroiBot Logo WALK-MAN Logo Xperience Logo SecondHands Logo TimeStorm Logo I-SUPPORT Logo
PACO-PLUS Logo SFB-588 Logo SPP1527 Logo