PICCANTE  0.4
The hottest HDR imaging library!
filter_rotation.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_FILTERING_FILTER_ROTATION_HPP
19 #define PIC_FILTERING_FILTER_ROTATION_HPP
20 
21 #include "../filtering/filter.hpp"
22 #include "../image_samplers/image_sampler_bilinear.hpp"
23 
24 #ifndef PIC_DISABLE_EIGEN
25 
26 #ifndef PIC_EIGEN_NOT_BUNDLED
27  #include "../externals/Eigen/Dense"
28  #include "../externals/Eigen/Geometry"
29 #else
30  #include <Eigen/Dense>
31  #include <Eigen/Geometry>
32 #endif
33 
34 #endif
35 
36 namespace pic {
37 #ifndef PIC_DISABLE_EIGEN
38 
42 class FilterRotation: public Filter
43 {
44 protected:
45 
47 
48  //rotation
49  float angleX, angleY, angleZ;
50 
51  //the rotation matrix of (theta, phi)
52  Eigen::Matrix3f mtxRot, mtxRot_inv;
53 
60  void ProcessBBox(Image *dst, ImageVec src, BBox *box)
61  {
62  float c1 = C_PI / dst->heightf;
63  float c2 = C_PI_2 / dst->widthf;
64 
65  for(int j = box->y0; j < box->y1; j++) {
66  float theta = float(j) * c1;
67  float sinTheta = sinf(theta);
68  float cosTheta = cosf(theta);
69 
70  Eigen::Vector3f d;
71 
72  for(int i = box->x0; i < box->x1; i++) {
73  float phi = float(i) * c2;
74 
75  d[0] = sinTheta * cosf(phi);
76  d[1] = cosTheta;
77  d[2] = sinTheta * sinf(phi);
78 
79  auto Rd = (mtxRot_inv * d).normalized();
80 
81 
82  /* printf("\nwrong: %f correct: %f Rd: %f\n",
83  sinTheta * cosf(phi + this->phi),
84  sinTheta * cosf(phi - this->phi),
85  Rd[0]
86  );*/
87 
88  float xt = 1.0f - ((atan2f(Rd[2], -Rd[0]) * C_INV_PI) * 0.5f + 0.5f);
89  float yt = (acosf(Rd[1]) * C_INV_PI);
90 
91  float *data_dst = (*dst)(i, j);
92  isb.SampleImage(src[0], xt, yt, data_dst);
93  }
94  }
95  }
96 
103  Eigen::Vector3f fromAnglesToVector(float theta, float phi)
104  {
105  Eigen::Vector3f ret;
106  float sinTheta = sinf(theta);
107  float cosTheta = cosf(theta);
108 
109  ret[0] = sinTheta * cosf(phi);
110  ret[1] = cosTheta;
111  ret[2] = sinTheta * sinf(phi);
112 
113  return ret;
114  }
115 
116 public:
117 
122  {
123  update(0.0f, 0.0f, 0.0f);
124  }
125 
132  FilterRotation(float angleX, float angleY, float angleZ) : Filter()
133  {
135  }
136 
141  FilterRotation(Eigen::Matrix3f mtx) : Filter()
142  {
143  update(mtx);
144  }
145 
152  void update(float angleX, float angleY, float angleZ)
153  {
154  this->angleX = angleX;
155  this->angleY = angleY;
156  this->angleZ = angleZ;
157 
158  Eigen::Matrix3f mtx;
159  mtx = Eigen::AngleAxisf(angleZ, Eigen::Vector3f::UnitZ()) *
160  Eigen::AngleAxisf(angleY, Eigen::Vector3f::UnitY()) *
161  Eigen::AngleAxisf(angleX, Eigen::Vector3f::UnitX());
162 
163  update(mtx);
164  }
165 
171  void update(Eigen::Matrix3f mtx)
172  {
173  this->mtxRot = mtx;
174  this->mtxRot_inv = Eigen::Transpose< Eigen::Matrix3f >(mtx);
175  }
176 
181  Eigen::Matrix3f getMtxRot()
182  {
183  return mtxRot;
184  }
185 
194  static Image *execute(Image *imgIn, Image *imgOut, float angleX, float angleY, float angleZ)
195  {
197  return fltRot.Process(Single(imgIn), imgOut);
198  }
199 
207  static Image *execute(Image *imgIn, Image *imgOut, Eigen::Matrix3f &mtx)
208  {
209  FilterRotation fltRot(mtx);
210  return fltRot.Process(Single(imgIn), imgOut);
211  }
212 };
213 
214 #endif
215 
216 } // end namespace pic
217 
218 #endif /* PIC_FILTERING_FILTER_ROTATION_HPP */
219 
ImageSamplerBilinear isb
Definition: filter_rotation.hpp:46
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
float angleZ
Definition: filter_rotation.hpp:49
static Image * execute(Image *imgIn, Image *imgOut, Eigen::Matrix3f &mtx)
execute
Definition: filter_rotation.hpp:207
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int x0
Definition: bbox.hpp:32
The Filter class.
Definition: filter.hpp:50
Eigen::Matrix3f mtxRot_inv
Definition: filter_rotation.hpp:52
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_rotation.hpp:60
const float C_PI
Definition: math.hpp:50
Eigen::Matrix3f mtxRot
Definition: filter_rotation.hpp:52
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
float angleY
Definition: filter_rotation.hpp:49
float heightf
Definition: image.hpp:84
Eigen::Matrix3f getMtxRot()
getMtxRot
Definition: filter_rotation.hpp:181
void update(float angleX, float angleY, float angleZ)
update
Definition: filter_rotation.hpp:152
const float C_PI_2
Definition: math.hpp:52
int y0
Definition: bbox.hpp:32
void update(Eigen::Matrix3f mtx)
update
Definition: filter_rotation.hpp:171
FilterRotation(Eigen::Matrix3f mtx)
FilterRotation.
Definition: filter_rotation.hpp:141
float widthf
Definition: image.hpp:84
void SampleImage(Image *img, float x, float y, float *vOut)
SampleImage samples an image in normalized coordiantes (0,1).
Definition: image_sampler_bilinear.hpp:42
float angleX
Definition: filter_rotation.hpp:49
The Image class stores an image as buffer of float.
Definition: image.hpp:60
FilterRotation(float angleX, float angleY, float angleZ)
FilterRotation.
Definition: filter_rotation.hpp:132
virtual void f(FilterFData *data)
f
Definition: filter_radial_basis_function.hpp:69
The FilterRotation class.
Definition: filter_rotation.hpp:42
PIC_INLINE ImageVec Single(Image *img)
Single creates an std::vector which contains img; this is for filters input.
Definition: image_vec.hpp:36
Definition: bilateral_separation.hpp:25
Eigen::Vector3f fromAnglesToVector(float theta, float phi)
fromAnglesToVector
Definition: filter_rotation.hpp:103
FilterRotation()
FilterRotation.
Definition: filter_rotation.hpp:121
The ImageSamplerBilinear class.
Definition: image_sampler_bilinear.hpp:28
static Image * execute(Image *imgIn, Image *imgOut, float angleX, float angleY, float angleZ)
execute
Definition: filter_rotation.hpp:194
const float C_INV_PI
Definition: math.hpp:62