RotatePanorama.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00026 #include "RotatePanorama.h"
00027 
00028 
00029 namespace HuginBase {
00030     
00031 
00033 RotatePanorama::RotatePanorama(PanoramaData& panorama, double yaw, double pitch, double roll)
00034  : PanoramaAlgorithm(panorama)
00035 {
00036     o_transformMat.SetRotationPT(DEG_TO_RAD(yaw), DEG_TO_RAD(pitch), DEG_TO_RAD(roll));
00037 }
00038     
00039 
00040 #define conditional_set(variable, value) \
00041 if (image.variable##isLinked())\
00042 {\
00043     unsigned int j = 0;\
00044     while (j < i && !image.variable##isLinkedWith(panorama.getImage(j)))\
00045     {\
00046         j++;\
00047     }\
00048     if (j == i) copy.set##variable(value);\
00049 } else {\
00050     copy.set##variable(value);\
00051 }
00052 
00053 void RotatePanorama::rotatePano(PanoramaData& panorama, const Matrix3& transformMat)
00054 {
00055     for (unsigned int i = 0; i < panorama.getNrOfImages(); i++)
00056     {
00057         const SrcPanoImage & image = panorama.getImage(i);
00058         SrcPanoImage copy = image;
00059         double y = image.getYaw();
00060         double p = image.getPitch();
00061         double r = image.getRoll();
00062         Matrix3 mat;
00063         mat.SetRotationPT(DEG_TO_RAD(y), DEG_TO_RAD(p), DEG_TO_RAD(r));
00064         DEBUG_DEBUG("rotation matrix (PT) for img " << i << " << ypr:" << y << " " << p << " " << r << std::endl << mat);
00065         Matrix3 rotated;
00066         rotated = transformMat * mat;
00067         DEBUG_DEBUG("rotation matrix after transform: " << rotated);
00068         rotated.GetRotationPT(y,p,r);
00069         y = RAD_TO_DEG(y);
00070         p = RAD_TO_DEG(p);
00071         r = RAD_TO_DEG(r);
00072         DEBUG_DEBUG("rotated angles of img " << i << ": " << y << " " << p << " " << r);
00073         
00074         // Don't update a variable linked to a variable we already updated.
00075         conditional_set(Yaw, y);
00076         conditional_set(Pitch, p);
00077         conditional_set(Roll, r);
00078         if(image.getX()!=0.0 || image.getY()!=0.0 || image.getZ()!=0.0)
00079         {
00080             // rotate translation vector
00081             Vector3 vecRot=transformMat.Inverse().TransformVector(Vector3(image.getZ(), image.getX(), image.getY()));
00082             conditional_set(X, vecRot.y);
00083             conditional_set(Y, vecRot.z);
00084             conditional_set(Z, vecRot.x);
00085             // rotate translation plane
00086             mat.SetRotationPT(DEG_TO_RAD(image.getTranslationPlaneYaw()), DEG_TO_RAD(image.getTranslationPlanePitch()), 0.0);
00087             rotated = transformMat * mat;
00088             rotated.GetRotationPT(y,p,r);
00089             conditional_set(TranslationPlaneYaw, RAD_TO_DEG(y));
00090             conditional_set(TranslationPlanePitch, RAD_TO_DEG(p));
00091         };
00092         panorama.setImage(i, copy);
00093         panorama.imageChanged(i);
00094     }
00095 }
00096 
00097 
00098 } //namespace

Generated on 31 Oct 2014 for Hugintrunk by  doxygen 1.4.7