Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CylinderMapping.cpp
1 // BIAS includes
2 #include "CylinderMapping.hh"
3 
4 
5 using namespace BIAS;
6 using namespace std;
7 
8 
9 static double toDeg(const double rad) {
10  return (rad / M_PI * 180.0);
11 }
12 
13 static double toRad(const double deg) {
14  return (M_PI / 180.0 * deg);
15 }
16 
17 
18 static void rotateY(BIAS::Vector3<double>& v, const double rad) {
19  v.Set(v[2] * sin(rad) + v[0] * cos(rad),
20  v[1],
21  v[2] * cos(rad) - v[0] * sin(rad));
22 }
23 
24 
26 {
27  Reset();
28 }
29 
31 {
32  px_=-1; // principal x
33  py_=-1; // principal y
34 
35  focalX_=100;
36  focalY_=80;
37 
38  camAngleX_=-1; // camera opening angle in x-direction
39  camAngleY_=-1; // camera opening angle in y-direction
40 }
41 
42 void CylinderMapping::setFocalLength(const double fx, const double fy) {
43  focalX_=fx;
44  focalY_=fy;
45 }
46 
47 
48 void CylinderMapping::setPrincipalPoint(const double in_px_,
49  const double in_py_) {
50  px_ = in_px_;
51  py_ = in_py_;
52 }
53 
54 
56  BIAS::HomgPoint2D& source)
57  const {
58 
59  double camAngleX;//camAngleX;
60  camAngleX = toDeg(atan(width_ * 0.5 / focalX_)) * 2.0;
61  //camAngleY = toDeg(atan(height_ * 0.5 / focalY_)) * 2.0;
62 
63  double px=px_, py=py_;
64  if (px==-1) px = (width_-1) / 2.0;
65  if (py==-1) py = (height_-1) / 2.0;
66 
67  BIAS::HomgPoint2D normsink(sink[0] / width_,
68  sink[1] / height_);
69 
70  BIAS::Vector3<double> v1(0.0, 0.0, 1.0);
71  rotateY(v1, toRad(-camAngleX / 2.0));
72 
73  double origWidth = fabs(v1[0] * (1.0 / v1[2])) * 2.0;
74 
75  rotateY(v1, toRad(sink[0] / (double) width_ * camAngleX));
76  v1[1] = normsink[1] - 0.5;
77 
78  double lambda = 1.0 / v1[2];
79  source[0] = lambda * v1[0];
80  source[1] = lambda * v1[1];
81 
82  source[0] = (source[0] / origWidth + 0.5) * width_;
83  source[1] = (source[1] + 0.5) * height_;
84 
85  return 0;
86 }
void Set(const T *pv)
copy the array of vectorsize beginning at *T to this-&gt;data_
Definition: Vector3.hh:532
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
void setFocalLength(const double fx, const double fy)
Set the focal length of the camera.
void Reset()
if you want to call Map() twice for this object with different params, call Reset() before ...
virtual int GetSourceCoordinates_(const BIAS::HomgPoint2D &sink, BIAS::HomgPoint2D &source) const
this does the trick
void setPrincipalPoint(const double px, const double py)
Set the principal point of the camera.