00001 #include "HBTRecorder.h" 00002 #include "OBT_ASSERT.h" 00003 00004 using namespace HBT ; 00005 00006 00007 //============================================================================= 00008 const std::string Recorder::HEADER( "PostureFileVer" ) ; 00009 //----------------------------------------------------------------------------- 00010 Recorder::Recorder( const std::string& fileName ) 00011 : _initRecorded( false ), 00012 _file() 00013 { 00014 // Open directly the file 00015 open( fileName ) ; 00016 } 00017 //----------------------------------------------------------------------------- 00018 Recorder::Recorder() 00019 : _initRecorded( false ), 00020 _file() 00021 { 00022 } 00023 //----------------------------------------------------------------------------- 00024 Recorder::~Recorder() 00025 { 00026 _file.close() ; 00027 } 00028 //----------------------------------------------------------------------------- 00029 void Recorder::open( const std::string& fileName ) 00030 { 00031 _file.open( fileName.c_str(), std::ios::binary ) ; 00032 } 00033 //----------------------------------------------------------------------------- 00034 void Recorder::write( const std::string& txt ) 00035 { 00036 // size + c string (including the '\0') 00037 size_t size = txt.size() + 1 ; 00038 _file.write( (char*)&size, sizeof( size_t )) ; 00039 _file.write( (char*)txt.c_str(), size ) ; 00040 } 00041 //----------------------------------------------------------------------------- 00042 void Recorder::write( const bool& flag ) 00043 { 00044 // true => '1', false => '0' 00045 char tmp = flag ? '1' : '0' ; 00046 _file.write( &tmp, 1 ) ; 00047 } 00048 //----------------------------------------------------------------------------- 00049 template< typename T > 00050 void Recorder::write( const T& val ) 00051 { 00052 // the binary value 00053 _file.write( (char*)&val, sizeof( T ) ) ; 00054 } 00055 //----------------------------------------------------------------------------- 00056 void Recorder::write( const Ogre::Vector3& vect ) 00057 { 00058 // the 3 binary values 00059 _file.write( (char*)&vect.x, sizeof( Ogre::Real ) ) ; 00060 _file.write( (char*)&vect.y, sizeof( Ogre::Real ) ) ; 00061 _file.write( (char*)&vect.z, sizeof( Ogre::Real ) ) ; 00062 } 00063 //----------------------------------------------------------------------------- 00064 void Recorder::write( const Ogre::Quaternion& quat ) 00065 { 00066 // the 4 binary values 00067 _file.write( (char*)&quat.w, sizeof( Ogre::Real ) ) ; 00068 _file.write( (char*)&quat.x, sizeof( Ogre::Real ) ) ; 00069 _file.write( (char*)&quat.y, sizeof( Ogre::Real ) ) ; 00070 _file.write( (char*)&quat.z, sizeof( Ogre::Real ) ) ; 00071 } 00072 //----------------------------------------------------------------------------- 00073 template< typename T > 00074 void Recorder::write( const std::vector< T >& tab ) 00075 { 00076 // size of the vector + the N values 00077 size_t size = tab.size() ; 00078 _file.write( (char*)&size, sizeof( size_t ) ) ; 00079 for( size_t i = 0 ; i < size ; i++ ) 00080 { 00081 write( tab[ i ] ) ; 00082 } 00083 } 00084 00085 //----------------------------------------------------------------------------- 00086 Recorder& Recorder::write( const InitialisationSequence& intialisationSequence ) 00087 { 00088 OBT_ASSERT( _file.is_open() && "The file is not opened" ) ; 00089 OBT_ASSERT( 0 == _file.tellp() && "The file is not empty" ) ; 00090 00091 write( HEADER + "0" ) ; // Tag, this is the header with the version number 00092 00093 write( intialisationSequence.meshFile ) ; 00094 write( intialisationSequence.humanName ) ; 00095 write( intialisationSequence.useShadows ) ; 00096 write( intialisationSequence.generalScale ) ; 00097 write( intialisationSequence.rootQuat ) ; 00098 write( intialisationSequence.rootPos ) ; 00099 write( intialisationSequence.boneNumber ) ; 00100 write( intialisationSequence.postureQuat ) ; 00101 00102 _initRecorded = true ; 00103 00104 return *this ; 00105 } 00106 //----------------------------------------------------------------------------- 00107 Recorder& Recorder::write( unsigned int date, const PostureData& posture ) 00108 { 00109 OBT_ASSERT( _file.is_open() && "The file is not opened" ) ; 00110 OBT_ASSERT( _initRecorded && "You must write InitialisationSequence before writeing the posture data" ) ; 00111 write( date ) ; 00112 write( posture.rootPos ) ; 00113 write( posture.rootQuat ) ; 00114 write( posture.generalScale ) ; 00115 write( posture.postureQuat ) ; 00116 write( posture.quatModified ) ; 00117 return *this ; 00118 } 00119 //----------------------------------------------------------------------------- 00120
Documentation generated on Mon Jun 9 11:45:55 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |