Go to the documentation of this file.00001 #ifndef OPENTISSUE_KINEMATICS_ANIMATION_IO_ANIMATION_KEYFRAME_CAL3D_ANIMATION_XML_READ_H
00002 #define OPENTISSUE_KINEMATICS_ANIMATION_IO_ANIMATION_KEYFRAME_CAL3D_ANIMATION_XML_READ_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <TinyXML/tinyxml.h>
00013
00014 namespace OpenTissue
00015 {
00016 namespace animation
00017 {
00018
00027 template<typename keyframe_animation_type>
00028 bool keyframe_animation_cal3d_xml_read(std::string const & filename, keyframe_animation_type & keyframe_animation)
00029 {
00030 typedef typename keyframe_animation_type::coordsys_type coordsys_type;
00031 typedef typename keyframe_animation_type::real_type real_type;
00032 typedef typename keyframe_animation_type::channels_type channels_type;
00033 typedef typename coordsys_type::vector3_type vector3_type;
00034 typedef typename coordsys_type::quaternion_type quaternion_type;
00035
00036 #ifdef TIXML_USE_STL
00037 TiXmlDocument xml_document(filename);
00038 #else
00039 TiXmlDocument xml_document(filename.c_str());
00040 #endif
00041
00042 if(!xml_document.LoadFile())
00043 {
00044 std::cerr << "file not found" << std::endl;
00045 return false;
00046 }
00047
00048 std::stringstream str;
00049 TiXmlNode* node;
00050 TiXmlElement * xml_animation = xml_document.FirstChildElement( "ANIMATION" );
00051 TiXmlElement * xml_transform = xml_animation->FirstChildElement();
00052
00053 for( ; xml_transform; xml_transform=xml_transform->NextSiblingElement() )
00054 {
00055 channels_type * transform = keyframe_animation.create_joint_channels();
00056
00057 if(!xml_transform->Attribute("BONEID"))
00058 {
00059 std::cerr << "Invalid file format" << std::endl;
00060 return false;
00061 }
00062
00063 size_t bone_number = atoi( xml_transform->Attribute("BONEID") );
00064 transform->set_bone_number(bone_number);
00065
00066 TiXmlElement * xml_keyframe = xml_transform->FirstChildElement();
00067 for( ; xml_keyframe; xml_keyframe=xml_keyframe->NextSiblingElement() )
00068 {
00069 float tx, ty, tz;
00070 float rx, ry, rz, s;
00071 real_type time = 0;
00072
00073 coordsys_type value;
00074
00075 if( xml_keyframe->Attribute("TIME") )
00076 time = (real_type) atof(xml_keyframe->Attribute("TIME"));
00077
00078 TiXmlElement * translation = xml_keyframe->FirstChildElement();
00079 TiXmlElement * rotation = translation->NextSiblingElement();
00080
00081 if( translation && rotation )
00082 {
00083 node = translation->FirstChild();
00084 TiXmlText* translationdata = node->ToText();
00085 str.clear();
00086 str << translationdata->Value();
00087 str >> tx >> ty >> tz;
00088
00089 node = rotation->FirstChild();
00090 TiXmlText* rotationdata = node->ToText();
00091 str.clear();
00092 str << rotationdata->Value();
00093 str >> rx >> ry >> rz >> s;
00094
00095 coordsys_type bind_pose;
00096 value.T()= vector3_type( tx, ty, tz );
00097 value.Q()= quaternion_type( s, -rx, -ry, -rz );
00098 transform->add_key(time,value);
00099 }
00100 }
00101 }
00102 xml_document.Clear();
00103 return true;
00104 };
00105
00106 }
00107 }
00108
00109
00110 #endif