Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

LoggedDataDriver.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_LoggedDataDriver_h_
00003 #define INCLUDED_LoggedDataDriver_h_
00004 
00005 #include "local/DeviceDriver.h"
00006 #include "local/DataSources/FileSystemImageSource.h"
00007 
00008 //! description of LoggedDataDriver
00009 class LoggedDataDriver : public virtual DeviceDriver, public virtual plist::PrimitiveListener {
00010 public:
00011   LoggedDataDriver(const std::string& name) : DeviceDriver(autoRegisterLoggedDataDriver,name),
00012     path(), fsSensorSrc(*this, ".*\\.pos$"), fsImageSrc(*this, ".*\\.(jpg|jpeg|png)$")
00013   {
00014     addEntry("Path",path,"The directory from which data samples should be loaded, or a single specific file.\nA single file can be either a single data file (e.g. sensor or camera image), or an index file as output by VisionGUI, or in the format 'filename <tab> time', where 'filename' is an absolute path or relative to the directory containing the index file, and 'time' is in milliseconds, relative to the time at which the index file is loaded.\nIn the future, this could also be network addresses for teleoperation and remote processing.");
00015     addEntry("Sensors",fsSensorSrc,"Settings for loading logged sensor readings (stored in PostureEngine format)");
00016     addEntry("Camera",fsImageSrc,"Settings for loading logged camera images (stored as either JPEG or PNG)");
00017     path.addPrimitiveListener(this);
00018     fsSensorSrc.path.addPrimitiveListener(this);
00019     fsImageSrc.path.addPrimitiveListener(this);
00020   }
00021   
00022   virtual std::string getClassName() const { return autoRegisterLoggedDataDriver; }
00023   
00024   virtual void getSensorSources(std::map<std::string,DataSource*>& sources) {
00025     sources.clear();
00026     sources["Sensors"]=&fsSensorSrc;
00027   }
00028   virtual void getImageSources(std::map<std::string,DataSource*>& sources) {
00029     sources.clear();
00030     sources["Camera"]=&fsImageSrc;
00031   }
00032   
00033   virtual void plistValueChanged(const plist::PrimitiveBase& pl) {
00034     if(&pl==&path) {
00035       // reload file lists for data sources which aren't overriding the common path
00036       if(fsSensorSrc.path.size()==0)
00037         fsSensorSrc.loadFileList();
00038       if(fsImageSrc.path.size()==0)
00039         fsImageSrc.loadFileList();
00040     }
00041     if(&pl==&fsSensorSrc.path || &pl==&fsImageSrc.path || &pl==&path) {
00042       // if both streams are using the same source...
00043       if(fsSensorSrc.getUsedPath()==fsImageSrc.getUsedPath()) {
00044         //keep them in sync across loops, smooth offset between end times
00045         //std::cout << "SYNCING LOOP TIMES" << std::endl;
00046         float looptime=std::max(fsSensorSrc.getLoopTime(false),fsImageSrc.getLoopTime(false));
00047         if(looptime>0) { // if negative, indicates neither in use by LoadDataThread, framerates are unknown
00048           fsSensorSrc.setLoopTime(looptime);
00049           fsImageSrc.setLoopTime(looptime);
00050         }
00051       }
00052     } else {
00053       std::cerr << "LoggedDataDriver didn't handle call to plistValueChanged for " << pl.get() << std::endl;
00054     }
00055   }
00056   
00057   plist::Primitive<std::string> path;
00058   
00059 protected:
00060   FileSystemDataSource fsSensorSrc;
00061   FileSystemImageSource fsImageSrc;
00062   
00063 private:
00064   //! holds the class name, set via registration with the DeviceDriver registry
00065   static const std::string autoRegisterLoggedDataDriver;
00066 };
00067 
00068 /*! @file
00069  * @brief 
00070  * @author Ethan Tira-Thompson (ejt) (Creator)
00071  *
00072  * $Author: ejt $
00073  * $Name: tekkotsu-4_0 $
00074  * $Revision: 1.2 $
00075  * $State: Exp $
00076  * $Date: 2007/06/06 18:00:59 $
00077  */
00078 
00079 #endif

Tekkotsu Hardware Abstraction Layer 4.0
Generated Thu Nov 22 01:00:53 2007 by Doxygen 1.5.4