Go to the documentation of this file.00001 #ifndef OPENTISSUE_KINEMATICS_SKELETON_IO_SKELETON_XML_WRITE_H
00002 #define OPENTISSUE_KINEMATICS_SKELETON_IO_SKELETON_XML_WRITE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <TinyXML/tinyxml.h>
00013
00014 #include <stdexcept>
00015
00016 namespace OpenTissue
00017 {
00018 namespace skeleton
00019 {
00020 namespace detail
00021 {
00022
00031 template<typename skeleton_type>
00032 bool xml_write(TiXmlDocument & doc, skeleton_type const & skeleton)
00033 {
00034 typedef typename skeleton_type::math_types::coordsys_type coordsys_type;
00035 typedef typename skeleton_type::bone_type bone_type;
00036 typedef typename bone_type::bone_traits bone_traits;
00037 typedef typename skeleton_type::const_bone_iterator const_bone_iterator;
00038
00039 TiXmlElement * skeleton_elem = new TiXmlElement( "skeleton" );
00040 doc.LinkEndChild(skeleton_elem);
00041
00042 const_bone_iterator bone = skeleton.begin();
00043 const_bone_iterator end = skeleton.end();
00044 for(;bone!=end;++bone)
00045 {
00046 TiXmlElement * bone_elem = new TiXmlElement( "bone" );
00047
00048 if(bone->parent())
00049 {
00050 bone_elem->SetAttribute( "parent", bone->parent()->get_name() );
00051 }
00052 bone_elem->SetAttribute( "name", bone->get_name() );
00053 {
00054 coordsys_type bind_pose = bone_traits::convert( bone->bind_pose() );
00055 std::stringstream stream;
00056 stream.precision(15);
00057 stream << bind_pose;
00058 bone_elem->SetAttribute( "bindpose", stream.str() );
00059 }
00060 {
00061 coordsys_type bone_space = bone_traits::convert( bone->bone_space() );
00062 std::stringstream stream;
00063 stream.precision(15);
00064 stream << bone_space;
00065 bone_elem->SetAttribute( "bonespace", stream.str() );
00066 }
00067 skeleton_elem->LinkEndChild( bone_elem );
00068 }
00069
00070 return true;
00071 }
00072
00073 }
00074
00083 template<typename skeleton_type>
00084 bool xml_write(std::string const & filename,skeleton_type const & skeleton)
00085 {
00086
00087 TiXmlDocument doc;
00088
00089 TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "", "" );
00090 doc.LinkEndChild(decl);
00091
00092 if(!OpenTissue::skeleton::detail::xml_write( doc, skeleton ) )
00093 return false;
00094
00095
00096 #ifdef TIXML_USE_STL
00097 doc.SaveFile(filename);
00098 #else
00099 doc.SaveFile(filename.c_str());
00100 #endif
00101
00102 return true;
00103 }
00104
00105 }
00106 }
00107
00108
00109 #endif