Timer.cpp

00001 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
00002 /* 
00003  * Copyright (C) 2008 Micha Hersch, EPFL
00004  * RobotCub Consortium, European Commission FP6 Project IST-004370
00005  * email:   micha.hersch@robotcub.org
00006  * website: www.robotcub.org
00007  * Permission is granted to copy, distribute, and/or modify this program
00008  * under the terms of the GNU General Public License, version 2 or any
00009  * later version published by the Free Software Foundation.
00010  *
00011  * A copy of the license can be found at
00012  * http://www.robotcub.org/icub/license/gpl.txt
00013  *
00014  * This program is distributed in the hope that it will be useful, but
00015  * WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
00017  * Public License for more details
00018  */
00019 #include "Timer.h"
00020 
00021 Timer::Timer(){
00022   m_StartTime = 0;
00023   m_TimeToGo  = 0;
00024 }
00025 
00026 Timer::Timer(long TimeToGoMs){
00027   m_StartTime = 0;
00028   m_TimeToGo  = TimeToGoMs;
00029 }
00030 
00031 void Timer::Start(long TimeToGoMs){
00032 #ifdef WIN32
00033   m_StartTime = GetTickCount();
00034 #else
00035   gettimeofday(&m_TV,NULL);
00036   m_StartTime  = m_TV.tv_sec  * 1000;
00037   m_StartTime += m_TV.tv_usec / 1000;
00038 #endif
00039   m_TimeToGo = TimeToGoMs;
00040 }
00041 
00042 int Timer::IsDone(){
00043   long currTime;
00044 #ifdef WIN32
00045   currTime = GetTickCount();  
00046 #else
00047   struct timeval mCTV;
00048   gettimeofday(&mCTV,NULL);
00049   currTime      = mCTV.tv_sec *1000;
00050   currTime     += mCTV.tv_usec/1000;
00051 #endif
00052   if((currTime-m_StartTime)>m_TimeToGo)
00053     return TRUE;
00054   return FALSE;
00055 }
00056 
00057 
00058 
00059 History::History(){
00060   m_History   = NULL;
00061   m_DataSize  = 0;
00062   m_Size      = 0;
00063   m_Current   = 0;
00064   m_CurrentV  = 0;
00065 }
00066 
00067 History::~History(){
00068   if(m_History!=NULL) delete [] m_History;
00069   m_History = NULL;
00070 }
00071 
00072 void  History::Init(int dataSize, int size){
00073   if((dataSize>0)&&(size>0)){
00074     if(m_History!=NULL) delete [] m_History;    
00075     m_DataSize  = dataSize;
00076     m_Size      = size;
00077     m_History   = new float[dataSize*size];
00078     m_Current   = 0;
00079     m_CurrentV  = 0;
00080  }
00081   Clear();
00082 }
00083 
00084 void  History::Clear(){
00085   if(m_History!=NULL){
00086     m_Current = 0;
00087     memset(m_History,0,m_DataSize*m_Size*sizeof(float));
00088   }
00089 }
00090 void  History::AddData(float *data){
00091   if(m_History!=NULL){
00092     m_Current ++;   
00093     if(m_Current>=m_Size)
00094       m_Current = 0;
00095 
00096     memcpy(m_History+m_Current*m_DataSize,data,m_DataSize*sizeof(float));
00097   }
00098 }
00099 
00100 void  History::AddVertData(float *data){
00101   if(m_History!=NULL){
00102     m_CurrentV ++;   
00103     if(m_CurrentV>=m_DataSize)
00104       m_CurrentV = 0;
00105 
00106 
00107     int i;
00108     for(i=0;i<m_Size;i++){
00109       *(m_History + m_CurrentV + i*m_DataSize) = data[i];
00110     }
00111   }
00112 }
 All Data Structures Functions Variables

Generated on Wed Sep 22 16:51:26 2010 for Body_Schema_Learning by  doxygen 1.6.1