UniSet  1.4.0
Calibration.h
00001 #ifndef Calibration_H_
00002 #define Calibration_H_
00003 // -----------------------------------------------------------------------------
00004 #include <cmath>
00005 #include <string>
00006 #include <list>
00007 #include <ostream>
00008 // -----------------------------------------------------------------------------
00024 class Calibration
00025 {
00026     public:
00027         Calibration();
00028         Calibration( const std::string name, const std::string confile="calibration.xml" );
00029         Calibration( xmlNode* node );
00030         ~Calibration();
00031 
00033         static const int outOfRange=-1;
00034 
00041         long getValue( long raw, bool crop_raw=false );
00042 
00043 
00047         long getRawValue( long cal );
00048 
00049 
00055         void build( const std::string name, const std::string confile, xmlNode* node=0  );
00056 
00057 
00059         typedef float TypeOfValue;
00060 
00064         inline long tRound( const TypeOfValue& val )
00065         {
00066             return lround(val);
00067         }
00068 
00069         friend std::ostream& operator<<(std::ostream& os, Calibration& c );
00070         friend std::ostream& operator<<(std::ostream& os, Calibration* c );
00071 
00072     protected:
00073 
00075         struct Point
00076         {
00077             Point( TypeOfValue _x, TypeOfValue _y ):
00078                 x(_x),y(_y){}
00079 
00080             TypeOfValue x;
00081             TypeOfValue y;
00082 
00083             inline bool operator < ( const Point& p ) const
00084             {
00085                 return ( x < p.x );
00086             }
00087         };
00088 
00090         class Part
00091         {
00092             public:
00093                 Part( Point& pleft, Point& pright );
00094                 ~Part(){};
00095 
00097                 bool check( Point& p );
00098 
00100                 bool checkX( TypeOfValue x );
00101 
00103                 bool checkY( TypeOfValue y );
00104                 
00105                 // функции могут вернуть OutOfRange
00106                 TypeOfValue getY( TypeOfValue x );      
00107                 TypeOfValue getX( TypeOfValue y );      
00109                 TypeOfValue calcY( TypeOfValue x );     
00110                 TypeOfValue calcX( TypeOfValue y );     
00112                 inline bool operator < ( const Part& p ) const
00113                 {
00114                     return (p_right < p.p_right);
00115                 }
00116             
00117                 inline Point leftPoint(){ return p_left; }
00118                 inline Point rightPoint(){ return p_right; }
00119                 inline TypeOfValue getK(){ return k; }  
00120                 inline TypeOfValue left_x(){ return p_left.x; }
00121                 inline TypeOfValue left_y(){ return p_left.y; }
00122                 inline TypeOfValue right_x(){ return p_right.x; }
00123                 inline TypeOfValue right_y(){ return p_right.y; }
00124 
00125             protected:
00126                 Point p_left;   
00127                 Point p_right;  
00128                 TypeOfValue k;  
00129         };
00130         
00131         // список надо отсортировать по x!
00132         typedef std::list<Part> PartsList;
00133 
00134     private:
00135         PartsList plist;
00136         std::string myname;
00137 };
00138 // -----------------------------------------------------------------------------
00139 #endif // Calibration_H_
00140 // -----------------------------------------------------------------------------