HBT::Player Class Reference

This object defines a reader for the posture data. More...

#include <HBTPlayer.h>

Collaboration diagram for HBT::Player:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Player ()
 Default constructor.
 Player (const std::string &fileName)
 Constructor.
virtual ~Player ()
 Destructor.
void open (const std::string &fileName)
 Open the file.
 operator bool () const
 Boolean operator.
Playerread (InitialisationSequence &intialisationSequence)
 The initialisation sequence reader.
Playerread (unsigned int &date, PostureData &posture)
 The posture reader.
void setLoop (bool loop=true)
 Set the behiavor at the end of the file.

Protected Member Functions

Readers
void read (std::string &txt)
 Read a string.
void read (bool &flag)
 Read a bool.
void read (Ogre::Vector3 &vect)
 Read an Ogre::Vector3.
void read (Ogre::Quaternion &quat)
 Read an Ogre::Quaternion.
template<typename T>
void read (std::vector< T > &tab)
 Read a vector of T.
template<typename T>
void read (T &val)
 Read a T.

Protected Attributes

bool _initRead
 The flag to know if the initialisation sequence is read.
bool _loop
 The flag to loop at the end of the file.
std::ifstream _file
 The file where the data will be written.
PostureData _lastPosture
 The last read posture.
unsigned int _lastDate
 The last read date.

Detailed Description

This object defines a reader for the posture data.

The format is a binary file in three parts, see Recorder.

Example of use :

  AvatarMesh avatar ;
  // Open the file
  Player player( filename ) ;
  // Do the initialisations of the avatar mesh 
  InitialisationSequence initialisationSequence ;
  player.read( InitialisationSequence ) ;
  avatar.init( ogreSceneManager, &initialisationSequence ) ;
  avatar.show() ;
  for( ;; )
  {
    // And for each step update the posture
    unsigned int date ;
    PostureData posture ;
    player.read( date, posture ) ;
    avatar.update( posture ) ;
  }

Definition at line 35 of file HBTPlayer.h.


Constructor & Destructor Documentation

Player::Player (  ) 

Default constructor.

Use open to define the name of the file where the data will be read.

Definition at line 18 of file HBTPlayer.cpp.

00019 : _initRead( false ),
00020   _loop( false ),
00021   _file()
00022 { 
00023 }

Player::Player ( const std::string &  fileName  ) 

Constructor.

Parameters:
[in] fileName,the file where the data will be read.
This constructor calls open to define the file.

Definition at line 10 of file HBTPlayer.cpp.

References open().

00011 : _initRead( false ),
00012   _loop( false ),
00013   _file()
00014 { 
00015   open( fileName ) ;
00016 }

Player::~Player (  )  [virtual]

Destructor.

Closes the file.

Definition at line 25 of file HBTPlayer.cpp.

References _file.

00026 {
00027   _file.close() ;
00028 }


Member Function Documentation

void Player::open ( const std::string &  fileName  ) 

Open the file.

Parameters:
[in] fileName,the file where the data will be read.

Definition at line 30 of file HBTPlayer.cpp.

References _file, and _initRead.

Referenced by OMK::HumanoPlayer::loadParameters(), and Player().

00031 {
00032   _file.open( fileName.c_str(), std::ios::binary ) ;
00033   _initRead = false ;
00034 }

HBT::Player::operator bool (  )  const [inline]

Boolean operator.

Returns:
true if the initialisation sequence have been already read, or false if not.

Definition at line 55 of file HBTPlayer.h.

00055 { return _initRead ; }

Player & Player::read ( InitialisationSequence intialisationSequence  ) 

The initialisation sequence reader.

This reader must be called first, before any call to the posture reader.

Definition at line 89 of file HBTPlayer.cpp.

References _file, _initRead, HBT::InitialisationSequence::boneNumber, HBT::InitialisationSequence::generalScale, HBT::Recorder::HEADER, HBT::InitialisationSequence::humanName, HBT::InitialisationSequence::meshFile, HBT::InitialisationSequence::postureQuat, HBT::InitialisationSequence::rootPos, HBT::InitialisationSequence::rootQuat, and HBT::InitialisationSequence::useShadows.

Referenced by OMK::HumanoPlayer::computeParameters(), OMK::HumanoPlayer::loadParameters(), and read().

00090 {
00091   OBT_ASSERT( _file.is_open() && "The file is not opened" ) ;
00092   // Go to the beginning of the file
00093   _file.seekg( 0 ) ;
00094 
00095   // Tag
00096   std::string header ;
00097   read( header ) ;
00098   size_t length = Recorder::HEADER.length() ;
00099   OBT_ASSERT( header.substr( 0, length ) == Recorder::HEADER && "Not the good header" ) ;
00100   // Version
00101   if( header.substr( length ) == "0" )
00102   {
00103     read( initialisationSequence.meshFile ) ;
00104     read( initialisationSequence.humanName ) ;
00105     read( initialisationSequence.useShadows ) ;
00106     read( initialisationSequence.generalScale ) ;
00107     read( initialisationSequence.rootQuat ) ;
00108     read( initialisationSequence.rootPos ) ;
00109     read( initialisationSequence.boneNumber ) ;
00110     read( initialisationSequence.postureQuat ) ;
00111   }
00112   else
00113   {
00114     OBT_ASSERT( false && "not the good version" ) ; // version
00115   }
00116 
00117   _initRead = true ;
00118   return *this ;
00119 }

Player & Player::read ( unsigned int date,
PostureData posture 
)

The posture reader.

This reader must be called after the call to the initialisation sequence reader.

See setLoop to know the behavior at the end of the file.

Definition at line 121 of file HBTPlayer.cpp.

References _file, _initRead, _lastDate, _lastPosture, _loop, HBT::PostureData::generalScale, HBT::PostureData::postureQuat, HBT::PostureData::quatModified, read(), HBT::PostureData::rootPos, and HBT::PostureData::rootQuat.

00122 {
00123   OBT_ASSERT( _file.is_open() && "The file is not opened" ) ;
00124   OBT_ASSERT( _initRead && "You must read InitialisationSequence before reading the posture data" ) ;
00125   _file.peek() ;
00126   if( !_file.eof() )
00127   {
00128     read( _lastDate ) ; 
00129     read( _lastPosture.rootPos ) ; 
00130     read( _lastPosture.rootQuat ) ;    
00131     read( _lastPosture.generalScale ) ;
00132     read( _lastPosture.postureQuat ) ; 
00133     read( _lastPosture.quatModified ) ;
00134   }
00135   else if( _loop )
00136   {
00137     _file.clear() ;
00138     InitialisationSequence initialisationSequence ;
00139     read( initialisationSequence ) ;
00140   }
00141   date = _lastDate ;
00142   posture = _lastPosture ;
00143   return *this ;
00144 }

void HBT::Player::setLoop ( bool  loop = true  )  [inline]

Set the behiavor at the end of the file.

Parameters:
[in] loop,the flag.
The behavior depends of the flag value This flag can be set at any time.

Definition at line 75 of file HBTPlayer.h.

Referenced by OMK::HumanoPlayer::computeParameters(), and OMK::HumanoPlayer::loadParameters().

00075 { _loop = loop ; }

void Player::read ( std::string &  txt  )  [protected]

Read a string.

Definition at line 36 of file HBTPlayer.cpp.

References _file.

00037 {
00038   size_t size ;
00039   _file.read( (char*)&size, sizeof(size) ) ;
00040   char* txtTmp = new char[ size ] ;
00041   _file.read( txtTmp, size ) ;
00042   txt = txtTmp ;
00043   delete[] txtTmp ;
00044 }

void Player::read ( bool flag  )  [protected]

Read a bool.

Definition at line 46 of file HBTPlayer.cpp.

References _file.

00047 {
00048   char tmp ;
00049   _file.read( &tmp, 1 ) ;
00050   flag = tmp == '1' ;
00051 }

void Player::read ( Ogre::Vector3 &  vect  )  [protected]

Read an Ogre::Vector3.

Definition at line 59 of file HBTPlayer.cpp.

References _file.

00060 {
00061   _file.read( (char*)&vect.x, sizeof( Ogre::Real ) ) ;
00062   _file.read( (char*)&vect.y, sizeof( Ogre::Real ) ) ;
00063   _file.read( (char*)&vect.z, sizeof( Ogre::Real ) ) ;
00064 }

void Player::read ( Ogre::Quaternion &  quat  )  [protected]

Read an Ogre::Quaternion.

Definition at line 66 of file HBTPlayer.cpp.

References _file.

00067 {
00068   _file.read( (char*)&quat.w, sizeof( Ogre::Real ) ) ;
00069   _file.read( (char*)&quat.x, sizeof( Ogre::Real ) ) ;
00070   _file.read( (char*)&quat.y, sizeof( Ogre::Real ) ) ;
00071   _file.read( (char*)&quat.z, sizeof( Ogre::Real ) ) ;
00072 }

template<typename T>
void Player::read ( std::vector< T > &  tab  )  [protected]

Read a vector of T.

Definition at line 75 of file HBTPlayer.cpp.

References _file, and read().

00076 {
00077   tab.clear() ;
00078   size_t size ;
00079   _file.read( (char*)&size, sizeof( size_t ) ) ;
00080   for( ; size != 0 ; size-- )
00081   {
00082     T val ;
00083     read( val ) ;
00084     tab.push_back( val ) ;
00085   }
00086 }

template<typename T>
void Player::read ( T &  val  )  [protected]

Read a T.

Definition at line 54 of file HBTPlayer.cpp.

References _file.

00055 {
00056   _file.read( (char*)&val, sizeof( T ) ) ;
00057 }


Member Data Documentation

bool HBT::Player::_initRead [protected]

The flag to know if the initialisation sequence is read.

Definition at line 78 of file HBTPlayer.h.

Referenced by open(), and read().

bool HBT::Player::_loop [protected]

The flag to loop at the end of the file.

See setLoop.

Definition at line 81 of file HBTPlayer.h.

Referenced by read().

std::ifstream HBT::Player::_file [protected]

The file where the data will be written.

Definition at line 83 of file HBTPlayer.h.

Referenced by open(), read(), and ~Player().

PostureData HBT::Player::_lastPosture [protected]

The last read posture.

Used when the loop is set to false.

Definition at line 86 of file HBTPlayer.h.

Referenced by read().

unsigned int HBT::Player::_lastDate [protected]

The last read date.

Used when the loop is set to false.

Definition at line 89 of file HBTPlayer.h.

Referenced by read().


logo OpenMask

Documentation generated on Mon Jun 9 11:46:00 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007