Homepage Demos Overview Downloads Tutorials Reference
Credits

LoadCalibration.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_LoadCalibration_h_
00003 #define INCLUDED_LoadCalibration_h_
00004 
00005 #include "FileBrowserControl.h"
00006 
00007 //! will load calibration parameters from a text file into a forward and backward matrix
00008 template<unsigned int ROWS, unsigned int COLS>
00009 class LoadCalibration : public FileBrowserControl {
00010 public:
00011 
00012   //!Constructor
00013   LoadCalibration(float f_cal[ROWS][COLS],float b_cal[ROWS][COLS])
00014     : FileBrowserControl("Load Calibration...","","/ms/data/motion/"), forw_cal(f_cal), back_cal(b_cal)
00015   { setFilter("*.txt"); }
00016   //!Constructor
00017   LoadCalibration(const std::string& n,float f_cal[ROWS][COLS],float b_cal[ROWS][COLS])
00018     : FileBrowserControl(n,"","/ms/data/motion/"), forw_cal(f_cal), back_cal(b_cal)
00019   { setFilter("*.txt"); }
00020   //!Constructor
00021   LoadCalibration(const std::string& n, const std::string& d,float f_cal[ROWS][COLS],float b_cal[ROWS][COLS])
00022     : FileBrowserControl(n,d,"/ms/data/motion/"), forw_cal(f_cal), back_cal(b_cal)
00023   { setFilter("*.txt"); }
00024 
00025 protected:
00026   //!calls readData() for each of the matrices
00027   virtual ControlBase* selectedFile(const std::string& f) {
00028     FILE * file=fopen(f.c_str(),"r");
00029     if(readData(file,forw_cal))
00030       readData(file,back_cal);
00031     fclose(file);
00032     FileBrowserControl::selectedFile(f);
00033     return NULL;
00034   }
00035 
00036   //!does the actual loading once a file is selected
00037   bool readData(FILE * f, float mat[ROWS][COLS]) {
00038     const unsigned int curl=500;
00039     char curs[curl];
00040     for(unsigned int i=0; i<ROWS; i++) {
00041       fgets(curs,curl,f);
00042       if(feof(f)) {
00043         serr->printf("ERROR: short read, got %d lines.\n",(mat==forw_cal?i:i+ROWS));
00044         return false;
00045       } else {
00046         char *c=curs;
00047         for(unsigned int col=0; col<COLS; col++)
00048           mat[i][col]=strtod(c,&c);
00049       }
00050     }
00051     return true;
00052   }
00053 
00054   float (* forw_cal)[COLS]; //!< pointer to the forward calibration matrix
00055   float (* back_cal)[COLS]; //!< pointer to the backward calibration matrix
00056 
00057 private:
00058   LoadCalibration(const LoadCalibration& ); //!< don't call
00059   LoadCalibration& operator=(const LoadCalibration& ); //!< don't call
00060 };
00061 
00062 /*! @file
00063  * @brief Defines LoadCalibration, which will load calibration parameters from a text file into a forward and backward matrix
00064  * @author ejt (Creator)
00065  *
00066  * $Author: ejt $
00067  * $Name: tekkotsu-2_0 $
00068  * $Revision: 1.2 $
00069  * $State: Exp $
00070  * $Date: 2004/01/18 10:16:56 $
00071  */
00072 
00073 #endif

Tekkotsu v2.0
Generated Wed Jan 21 03:20:29 2004 by Doxygen 1.3.4