Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages
hugin_base/hugin_math/Transforms.h
Go to the documentation of this file.00001 // -*- c-basic-offset: 4 -*- 00026 #ifndef _HUGIN_MATH_TRANSFORMS_H 00027 #define _HUGIN_MATH_TRANSFORMS_H 00028 00029 #include <cmath> 00030 #include <hugin_math/hugin_math.h> 00031 00032 00033 namespace hugin_utils { 00034 namespace TRANSFORM { 00035 00036 struct DegToRad 00037 { 00038 double operator()(double x) 00039 { return (x/180.0*M_PI); }; 00040 }; 00041 00042 struct RadToDeg 00043 { 00044 double operator()(double x) 00045 { return (x/M_PI*180.0); }; 00046 }; 00047 00048 00049 inline double calcRectFocalLength(double hfov, double width) 00050 { 00051 return width / ( 2*tan(hfov/2)); 00052 } 00053 00054 inline void rotatePoint(FDiff2D & dest, FDiff2D src, double angle) 00055 { 00056 double cos_r = cos(angle); 00057 double sin_r = sin(angle); 00058 dest.x = src.x*cos_r - src.y*sin_r; 00059 dest.y = src.x*sin_r + src.y*cos_r; 00060 } 00061 00062 00068 struct ERectToRect 00069 { 00070 public: 00075 ERectToRect(double focalLength) 00076 : f(focalLength) { }; 00077 00078 void operator()(FDiff2D & dest, const FDiff2D & src) 00079 { 00080 dest.x = f * tan(src.x); 00081 dest.y = f * tan(src.y); 00082 } 00083 double f; 00084 }; 00085 00086 00089 struct RectToERect 00090 { 00091 public: 00096 RectToERect(double focalLength) 00097 : f(focalLength) { }; 00098 00099 void operator()(FDiff2D & dest, const FDiff2D & src) 00100 { 00101 dest.x = atan2(src.x,f); 00102 dest.y = atan2(src.y,f); 00103 } 00104 double f; 00105 }; 00106 00109 struct CartToImg 00110 { 00111 CartToImg(double width, double height) 00112 { 00113 tx = width/2.0; 00114 ty = height/2.0; 00115 }; 00116 00117 void operator()(FDiff2D & dest, const FDiff2D & src) 00118 { 00119 dest.x = src.x + tx; 00120 dest.y = src.y + ty; 00121 } 00122 double tx, ty; 00123 }; 00124 00125 00128 struct ImgToCart 00129 { 00130 ImgToCart(double width, double height) 00131 { 00132 tx = width/2.0; 00133 ty = height/2.0; 00134 }; 00135 00136 void operator()(FDiff2D & dest, const FDiff2D & src) 00137 { 00138 dest.x = src.x - tx; 00139 dest.y = src.y - ty; 00140 } 00141 double tx, ty; 00142 }; 00143 00146 struct RotERect 00147 { 00148 public: 00149 RotERect(double yaw, double pitch, double roll) 00150 : p(pitch), y(yaw), sin_r(sin(roll)), cos_r(cos(roll)) 00151 { }; 00152 00153 void operator()(FDiff2D & dest, const FDiff2D & rsrc) 00154 { 00155 FDiff2D src(rsrc); 00156 // order of rotations: r, p, y 00157 dest.x = src.x*cos_r - src.y*sin_r; 00158 dest.y = src.x*sin_r + src.y*cos_r; 00159 dest.x += y; 00160 dest.y += p; 00161 } 00162 double p,y; 00163 double sin_r, cos_r; 00164 }; 00165 00166 00169 struct Translate 00170 { 00171 public: 00172 Translate(double x, double y) 00173 : x(x), y(y) { } 00174 00175 void operator()(FDiff2D & dest, const FDiff2D & src) 00176 { 00177 dest.x = src.x - x; 00178 dest.y = src.y - y; 00179 } 00180 double x,y; 00181 }; 00182 00185 struct InvRotERect 00186 { 00187 public: 00188 InvRotERect(double yaw, double pitch, double roll) 00189 : p(pitch), y(yaw), msin_r(sin(-roll)), mcos_r(cos(-roll)) 00190 { }; 00191 00192 void operator()(FDiff2D & dest, const FDiff2D & src) 00193 { 00194 // order of rotations: r, p, y 00195 dest.x -= y; 00196 dest.y -= p; 00197 dest.x = src.x*mcos_r - src.y*msin_r; 00198 dest.y = src.x*msin_r + src.y*mcos_r; 00199 } 00200 double p,y; 00201 double msin_r, mcos_r; 00202 }; 00203 00204 00205 } // namespace 00206 } // namespace 00207 #endif // _TRANSFORMS_H
1.3.9.1