Go to the documentation of this file.00001 #ifndef OPENTISSUE_KINEMATICS_ANIMATION_IO_ANIMATION_KEYFRAME_ANIMATION_XML_READ_H
00002 #define OPENTISSUE_KINEMATICS_ANIMATION_IO_ANIMATION_KEYFRAME_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_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 TiXmlHandle document_handle( &xml_document );
00048
00049 TiXmlElement * xml_transform = document_handle.FirstChild( "animation" ).FirstChild( "transform" ).Element();
00050 for( ; xml_transform; xml_transform=xml_transform->NextSiblingElement("transform") )
00051 {
00052 channels_type * transform = keyframe_animation.create_joint_channels();
00053 if(!xml_transform->Attribute("bone"))
00054 {
00055 std::cerr << "Invalid file format" << std::endl;
00056 return false;
00057 }
00058 size_t bone_number = atoi(xml_transform->Attribute("bone"));
00059 transform->set_bone_number(bone_number);
00060
00061 TiXmlHandle transform_handle( xml_transform );
00062 TiXmlElement * xml_keyframe = transform_handle.FirstChild( "keyframe" ).Element();
00063 for( ; xml_keyframe; xml_keyframe=xml_keyframe->NextSiblingElement("keyframe") )
00064 {
00065 TiXmlHandle keyframe_handle( xml_keyframe );
00066
00067 real_type time = 0;
00068
00069 if(xml_keyframe->Attribute("time"))
00070 time = (real_type) atof(xml_keyframe->Attribute("time"));
00071
00072 if(xml_keyframe->Attribute("value"))
00073 {
00074 coordsys_type value;
00075 std::istringstream str_stream(xml_keyframe->Attribute("value"));
00076 str_stream >> value;
00077 transform->add_key(time,value);
00078 }
00079 }
00080 }
00081 xml_document.Clear();
00082 return true;
00083 };
00084
00085 }
00086 }
00087
00088
00089 #endif