1 // -*- c-basic-offset: 4 -*-
2 /** @file RotatePanorama.cpp
3 *
4 * @author Pablo d'Angelo <pablo.dangelo@web.de>
5 *
6 * $Id: Panorama.h 1947 2007-04-15 20:46:00Z dangelo $
7 *
8 * !! from Panorama.h 1947
9 *
10 * This is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This software is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public
21 * License along with this software. If not, see
22 * <http://www.gnu.org/licenses/>.
23 *
24 */
25
26 #include "RotatePanorama.h"
27
28
29 namespace HuginBase {
30
31
32 ///
RotatePanorama(PanoramaData & panorama,double yaw,double pitch,double roll)33 RotatePanorama::RotatePanorama(PanoramaData& panorama, double yaw, double pitch, double roll)
34 : PanoramaAlgorithm(panorama)
35 {
36 o_transformMat.SetRotationPT(DEG_TO_RAD(yaw), DEG_TO_RAD(pitch), DEG_TO_RAD(roll));
37 }
38
39
40 #define conditional_set(variable, value) \
41 if (image.variable##isLinked())\
42 {\
43 unsigned int j = 0;\
44 while (j < i && !image.variable##isLinkedWith(panorama.getImage(j)))\
45 {\
46 j++;\
47 }\
48 if (j == i) copy.set##variable(value);\
49 } else {\
50 copy.set##variable(value);\
51 }
52
rotatePano(PanoramaData & panorama,const Matrix3 & transformMat)53 void RotatePanorama::rotatePano(PanoramaData& panorama, const Matrix3& transformMat)
54 {
55 for (unsigned int i = 0; i < panorama.getNrOfImages(); i++)
56 {
57 const SrcPanoImage & image = panorama.getImage(i);
58 SrcPanoImage copy = image;
59 double y = image.getYaw();
60 double p = image.getPitch();
61 double r = image.getRoll();
62 Matrix3 mat;
63 mat.SetRotationPT(DEG_TO_RAD(y), DEG_TO_RAD(p), DEG_TO_RAD(r));
64 DEBUG_DEBUG("rotation matrix (PT) for img " << i << " << ypr:" << y << " " << p << " " << r << std::endl << mat);
65 Matrix3 rotated;
66 rotated = transformMat * mat;
67 DEBUG_DEBUG("rotation matrix after transform: " << rotated);
68 rotated.GetRotationPT(y,p,r);
69 y = RAD_TO_DEG(y);
70 p = RAD_TO_DEG(p);
71 r = RAD_TO_DEG(r);
72 DEBUG_DEBUG("rotated angles of img " << i << ": " << y << " " << p << " " << r);
73
74 // Don't update a variable linked to a variable we already updated.
75 conditional_set(Yaw, y);
76 conditional_set(Pitch, p);
77 conditional_set(Roll, r);
78 if(image.getX()!=0.0 || image.getY()!=0.0 || image.getZ()!=0.0)
79 {
80 // rotate translation vector
81 Vector3 vecRot=transformMat.Inverse().TransformVector(Vector3(image.getZ(), image.getX(), image.getY()));
82 conditional_set(X, vecRot.y);
83 conditional_set(Y, vecRot.z);
84 conditional_set(Z, vecRot.x);
85 // rotate translation plane
86 mat.SetRotationPT(DEG_TO_RAD(image.getTranslationPlaneYaw()), DEG_TO_RAD(image.getTranslationPlanePitch()), 0.0);
87 rotated = transformMat * mat;
88 rotated.GetRotationPT(y,p,r);
89 conditional_set(TranslationPlaneYaw, RAD_TO_DEG(y));
90 conditional_set(TranslationPlanePitch, RAD_TO_DEG(p));
91 };
92 panorama.setImage(i, copy);
93 panorama.imageChanged(i);
94 }
95 }
96
97
98 } //namespace
99