mRunTicksPos.cpp

00001 /*
00002   mRunCtrl 用の TircksPositionInterface 実装
00003   Satofumi KAMIMURA
00004   $Id$
00005 */
00006 
00007 #include "tRunCtrlSimulator.h"
00008 
00009 
00010 tRunCtrl_Simulator::TicksPosition::TicksPosition(void)
00011   : first_ticks(0), offset_length(3000), ticksDiff(0) {
00012 }
00013 
00014 
00015 tRunCtrl_Simulator::TicksPosition::~TicksPosition(void) {
00016 }
00017 
00018 
00019 void tRunCtrl_Simulator::TicksPosition::add(const VXV::Position3D& pos,
00020                                             unsigned long total_msec) {
00021 
00022   unsigned long ticks = adjustTicksDiff(total_msec);
00023   if (pos_deque.empty()) {
00024     first_ticks = ticks;
00025   }
00026   pos_deque.push_back(pos);
00027   int length = static_cast<int>(pos_deque.size() - offset_length);
00028   if (length > 0) {
00029     pos_deque.erase(pos_deque.begin(), pos_deque.begin() + length);
00030     first_ticks += length;
00031   }
00032 }
00033 
00034 
00035 VXV::Position3D tRunCtrl_Simulator::TicksPosition::getPosition(unsigned long
00036                                                                ticks) const {
00037   int size = static_cast<int>(pos_deque.size());
00038   if (pos_deque.empty()) {
00039     return VXV::Position3D();
00040 
00041   } else if (ticks < first_ticks) {
00042     return pos_deque.front();
00043 
00044   } else if (ticks > first_ticks + size-1) {
00045     return pos_deque.back();
00046 
00047   } else {
00048     return pos_deque[ticks - first_ticks];
00049   }
00050 }
00051 
00052 
00053 void tRunCtrl_Simulator::TicksPosition::adjustOwnTicks(unsigned long setTicks,
00054                                                        unsigned long ticks) {
00055   ticksDiff = ticks - setTicks;
00056   pos_deque.clear();
00057 }
00058 
00059 
00060 unsigned long tRunCtrl_Simulator::TicksPosition::adjustTicksDiff(unsigned long
00061                                                                  ticks) const {
00062   return ticks - ticksDiff;
00063 }
00064 
00065 
00066 void tRunCtrl_Simulator::TicksPosition::clear(void) {
00067   pos_deque.clear();
00068 }
00069 
00070 
00071 void tRunCtrl_Simulator::TicksPosition::set_dataLength(unsigned long msec) {
00072   offset_length = msec;
00073 }
00074 

Generated on Mon Apr 13 22:52:03 2009 by  doxygen 1.5.7.1