IntrinsicsExtrinsicsContainer.cpp

Go to the documentation of this file.
00001 
00011 #include "IntrinsicsExtrinsicsContainer.hpp"
00012 #include "Rotation.hpp"
00013 
00014 GslMatrix IntrinsicsExtrinsicsContainer::getExtrinsicsMatrix(unsigned int imgIdx) const
00015 {
00016         GslMatrix result(3,4);
00017         result.setToIdentity();
00018 
00019         // Get a rotation, in axis/angle form
00020         GslVector axis;
00021         Rotation r;
00022         r.setScaledAxis(getRotation(imgIdx));
00023 
00024         // Convert that rotation into matrix form
00025         GslMatrix m3x3(3,3);
00026         r.getMatrix(m3x3);
00027 
00028         // Copy that matrix into the result we'll return
00029         for (int row = 0; row < 3; row++)
00030                 for (int col = 0; col < 3; col++)
00031                         result(row,col) = m3x3(row,col);
00032 
00033         // Get our translation
00034         GslVector translation = getTranslation(imgIdx);
00035 
00036         // Put the translation into the result also
00037         result(0,3) = translation(0);
00038         result(1,3) = translation(1);
00039         result(2,3) = translation(2);
00040 
00041         return result;
00042 }
00043 
00044 
00045 
00046 GslMatrix IntrinsicsExtrinsicsContainer::getIntrinsicsMatrix() const
00047 {
00048         GslMatrix result(3,3);
00049         result.setToZero();
00050         result(0,0) = alpha();
00051         result(0,1) = skewness();
00052         result(0,2) = u0();
00053         result(1,1) = beta();
00054         result(1,2) = v0();
00055         result(2,2) = 1.;
00056 
00057         return result;
00058 }
00059 
00060 
00061 
00062 void IntrinsicsExtrinsicsContainer::setRotation (unsigned int index, const GslVector &v) 
00063 { 
00064         unsigned int startIndex = 7 + 6 * index;
00065         this->at(startIndex++) = v(0);
00066         this->at(startIndex++) = v(1);
00067         this->at(startIndex++) = v(2);
00068 }
00069 
00070 
00071 
00072 void IntrinsicsExtrinsicsContainer::setTranslation(unsigned int imgIdx, const GslVector &v)
00073 { 
00074         unsigned int startIndex = 7 + (imgIdx * 6) + 3;
00075         this->at(startIndex++) = v(0);
00076         this->at(startIndex++) = v(1);
00077         this->at(startIndex++) = v(2);
00078 }
00079 
00080 
00081 
00082 GslVector IntrinsicsExtrinsicsContainer::getRotation (unsigned int imgIdx) const
00083 {
00084         unsigned int startIndex = 7 + (imgIdx * 6);
00085         if (startIndex >= this->getNumRows())
00086                 throw Error("IntrinsicsExtrinsicsContainer::getRotation(): invalid param %d is >= our number of items %d.", startIndex, getNumRows());
00087 
00088         GslVector result(3);
00089         result(0) = this->at(startIndex++);
00090         result(1) = this->at(startIndex++);
00091         result(2) = this->at(startIndex++);
00092 
00093         return result;
00094 }
00095 
00096 
00097 
00098 GslVector IntrinsicsExtrinsicsContainer::getTranslation(unsigned int imgIdx) const
00099 {
00100         unsigned int startIndex = 7 + (imgIdx * 6) + 3;
00101         if (startIndex >= this->getNumRows())
00102                 throw Error("IntrinsicsExtrinsicsContainer::getTranslation(): invalid param %d is >= our number of items %d.", startIndex, getNumRows());
00103 
00104         GslVector result(3);
00105         result(0) = this->at(startIndex++);
00106         result(1) = this->at(startIndex++);
00107         result(2) = this->at(startIndex++);
00108 
00109         return result;
00110 }
00111 
00112 
00113 
00114 GslMatrix IntrinsicsExtrinsicsContainer::getTransformation(unsigned int imgIdx) const
00115 {
00116         GslMatrix result = getIntrinsicsMatrix() * getExtrinsicsMatrix(imgIdx);
00117         double homogenous = result(result.getNumRows()-1, result.getNumCols()-1);
00118         for (unsigned int row = 0; row < result.getNumRows(); row++)
00119         {
00120                 for (unsigned int col = 0; col < result.getNumCols(); col++)
00121                 {
00122                         result(row,col) /= homogenous;
00123                 }
00124         }
00125         return result;
00126 }

Generated on Mon May 26 11:19:28 2003 for CamChecker by doxygen1.3