Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RotatePanorama.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
26 #include "RotatePanorama.h"
27 
28 
29 namespace HuginBase {
30 
31 
33 RotatePanorama::RotatePanorama(PanoramaData& panorama, double yaw, double pitch, double roll)
34  : PanoramaAlgorithm(panorama)
35 {
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 
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;
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);
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);
91  };
92  panorama.setImage(i, copy);
93  panorama.imageChanged(i);
94  }
95 }
96 
97 
98 } //namespace
double y
Definition: Vector3.h:47
double X
general : Matrix3 is a class for handling 3x3 Matrix manipulation.
Definition: Matrix3.h:37
void GetRotationPT(double &Yaw, double &Pitch, double &Roll)
GetRotation in panotools style.
Definition: Matrix3.cpp:157
double TranslationPlanePitch
Vector3 TransformVector(const Vector3 &V) const
transforms a vector
Definition: Matrix3.h:143
void SetRotationPT(double yaw, double pitch, double roll)
set rotation in panotools style, code adapted from Panotools-Script by Bruno Postle ...
Definition: Matrix3.cpp:110
RotatePanorama(PanoramaData &panorama, const Matrix3 &transformMat)
virtual void setImage(std::size_t nr, const SrcPanoImage &img)=0
set a panorama image, counting starts with 0
double TranslationPlaneYaw
Model for a panorama.
Definition: PanoramaData.h:81
virtual const SrcPanoImage & getImage(std::size_t nr) const =0
get a panorama image, counting starts with 0
double Yaw
#define conditional_set(variable, value)
#define RAD_TO_DEG(x)
Definition: hugin_math.h:45
double Y
Matrix3 Inverse() const
return inverse if it exists, otherwise identity
Definition: Matrix3.cpp:256
double z
Definition: Vector3.h:47
double Z
virtual void imageChanged(unsigned int imgNr)=0
mark image change for maintainance
double Roll
#define DEBUG_DEBUG(msg)
Definition: utils.h:68
static void rotatePano(PanoramaData &panorama, const Matrix3 &transformMat)
#define DEG_TO_RAD(x)
Definition: hugin_math.h:44
general : Vector3 is a class for handling 3D Vectors manipulation.
Definition: Vector3.h:43
double x
x,y,z coordinates, 0 at the initialisation
Definition: Vector3.h:47
virtual std::size_t getNrOfImages() const =0
number of images.
All variables of a source image.
Definition: SrcPanoImage.h:194
double Pitch