00001
00002 #ifndef INCLUDED_LoggedDataDriver_h_
00003 #define INCLUDED_LoggedDataDriver_h_
00004
00005 #include "local/DeviceDriver.h"
00006 #include "local/DataSources/FileSystemImageSource.h"
00007
00008
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
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
00043 if(fsSensorSrc.getUsedPath()==fsImageSrc.getUsedPath()) {
00044
00045
00046 float looptime=std::max(fsSensorSrc.getLoopTime(false),fsImageSrc.getLoopTime(false));
00047 if(looptime>0) {
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
00065 static const std::string autoRegisterLoggedDataDriver;
00066 };
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 #endif