00001
00002
00003 #ifndef IMAGE_POSITION_READER_HPP
00004 #define IMAGE_POSITION_READER_HPP
00005
00006 #include <string>
00007
00008 #include <kernel/jafarMacro.hpp>
00009 #include <kernel/keyValueFile.hpp>
00010
00011 #include <jmath/jblas.hpp>
00012
00013 namespace jafar {
00014 namespace geom {
00015 class T3D;
00016 }
00017 namespace datareader {
00018 class Position;
00023 class PositionReader {
00024 private:
00025 std::string directory;
00026 std::string pattern;
00027 std::string patternTransfos;
00028 std::string patternTimes;
00029 jblas::vec robotToSensorCorrection;
00030 int first, last, step;
00031
00032 geom::T3D *robotToSensor, *sensorToRobot;
00033
00034 Position *cached_pos;
00035 unsigned int cached_pos_index;
00036
00037 public:
00043 enum PosFileType {
00044 JAFAR,
00045 CALIFE,
00046 GENOM
00047 };
00053 enum TransfoSource {
00054 POS,
00055 T3D
00056 };
00057
00058 PositionReader();
00059 ~PositionReader();
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00082 void setup(std::string directory_,
00083 std::string pattern_ = "image.pos.%04d.g.pos",
00084 std::string patternTransfos_ = "%04d_to_%04d.t3d",
00085 std::string patternTimes_ = "",
00086 jblas::vec* robotToSensorCorrection_ = NULL,
00087 int first_ = -1, int last_ = -1, int step_ = -1);
00088
00094 Position loadPosition(unsigned int index_,
00095 PosFileType fileType = JAFAR) const;
00096 void loadPosition(unsigned int index_, Position& pos) const;
00097 void loadT3D(unsigned int index1, unsigned int index2, jafar::geom::T3D &t3d) const;
00098 void loadTime(unsigned int index, double &time) const;
00103 jafar::geom::T3D* loadTransfo(unsigned int iFrom, unsigned int iTo, int *dt = NULL, TransfoSource source = POS);
00104 };
00105
00106
00111 class Position : public kernel::KeyValueFileLoad {
00112 public:
00113 Position() {}
00114
00115 public:
00116
00118 void sensorToMain(jafar::geom::T3D& pos) { robotToSensor(pos); }
00120 jafar::geom::T3D* sensorToMain() { return robotToSensor(); }
00122 void mainToBase(jafar::geom::T3D& pos) { baseToRobot(pos); }
00124 jafar::geom::T3D* mainToBase() { return baseToRobot(); }
00126 void mainToOrigin(jafar::geom::T3D& pos) { originToRobot(pos); }
00128 jafar::geom::T3D* mainToOrigin() { return originToRobot(); }
00129
00131 void robotToSensor(jafar::geom::T3D& pos);
00133 jafar::geom::T3D* robotToSensor();
00135 void baseToRobot(jafar::geom::T3D& pos);
00137 jafar::geom::T3D* baseToRobot();
00139 void originToRobot(jafar::geom::T3D& pos);
00141 jafar::geom::T3D* originToRobot();
00142
00144 inline int date() { return m_date; }
00146 static void fromCalifeToJafar(const jblas::vec src, jblas::vec& dst);
00148 static void fromJafarToCalife(const jblas::vec src, jblas::vec& dst);
00149
00150 protected:
00152 virtual void loadKeyValueFile(jafar::kernel::KeyValueFile const& keyValueFile);
00154 void fixRobotToSensor(const jblas::vec &robotToSensorCorrection);
00156 bool loadPomPosition(std::string filename);
00157
00158 private:
00159 void loadStringInT3D(const std::string& , jafar::geom::T3D& pos);
00160 bool readline(std::string &line, char *sep, int index, int len, jblas::vec &res);
00161 jblas::vec m_robotToSensor, m_baseToRobot, m_originToRobot;
00162 int m_date;
00163
00164 friend Position PositionReader::loadPosition(unsigned int index_,
00165 PositionReader::PosFileType fileType) const;
00166 friend void PositionReader::loadPosition(unsigned int index_, Position& pos) const;
00167 };
00168
00169 }
00170 }
00171 #endif // DATAREADER_POSITION_READER_HPP