[an error occurred while processing this directive]
Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

hugin_base/nona/SpaceTransform.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00026 #ifndef _NONA_SPACETRANSFORM_H
00027 #define _NONA_SPACETRANSFORM_H
00028     
00029 #include <vigra/diff2d.hxx>
00030 #include <hugin_math/Matrix3.h>
00031 
00032 #include <panodata/PanoramaData.h>
00033 
00034 
00035 namespace HuginBase {
00036 namespace Nona {
00037         
00038     
00042 struct _FuncParams
00043 {
00044     union {
00045         double var0;
00046         double distance;
00047         double shift;
00048     };
00049     double      var1;
00050     double      var2;
00051     double      var3;
00052     double      var4;
00053     double      var5;
00054     double  var6;
00055     double  var7;
00056     Matrix3     mt;
00057 };
00058 
00059 
00063 typedef void (*trfn)( double x_dest, double y_dest, double* x_src, double* y_src, const _FuncParams &params );
00064 
00065 
00069 typedef struct _fDesc
00070 {
00071     trfn                func;   // function to be called
00072     _FuncParams param;  // parameters to be used
00073 } fDescription;
00074 
00075 
00076 
00080 class IMPEX SpaceTransform
00081 {
00082             
00083     public:
00086         SpaceTransform();
00087 
00090         ~SpaceTransform();
00091 
00095         void Init(  const SrcPanoImage & img,
00096                     const vigra::Diff2D & destSize,
00097                     PanoramaOptions::ProjectionFormat destProj,
00098                     double destHFOV );
00099 
00103         void InitInv(   const SrcPanoImage & img,
00104                         const vigra::Diff2D & destSize,
00105                         PanoramaOptions::ProjectionFormat destProj,
00106                         double destHFOV );
00107 
00108         
00109         // Different ways to create the transform
00110         
00111     public:
00114         void InitRadialCorrect(const vigra::Size2D & sz, const std::vector<double> & radDist, 
00115                                const hugin_utils::FDiff2D & centerShift);
00116 
00120         void InitRadialCorrect(const SrcPanoImage & src, int channel=1);
00121 
00122         void InitInvRadialCorrect(const SrcPanoImage & src, int channel=1);
00123 
00124         void createTransform(const SrcPanoImage & src, const PanoramaOptions & dest);
00125         
00126         void createInvTransform(const SrcPanoImage & src, const PanoramaOptions & dest);
00127 
00128         // create pano -> img transform
00129         void createTransform(const PanoramaData & pano, unsigned int imgNr,
00130                              const PanoramaOptions & dest,
00131                              vigra::Diff2D srcSize=vigra::Diff2D(0,0));
00132 
00133         // create image->pano transformation
00134         void createInvTransform(const PanoramaData & pano, unsigned int imgNr,
00135                                 const PanoramaOptions & dest,
00136                                 vigra::Diff2D srcSize=vigra::Diff2D(0,0));
00137         
00138         void createTransform(const vigra::Diff2D & srcSize,
00139                          const VariableMap & srcVars,
00140                          Lens::LensProjectionFormat srcProj,
00141                          const vigra::Diff2D &destSize,
00142                          PanoramaOptions::ProjectionFormat destProj,
00143                              double destHFOV);
00144         
00145         // create image->pano transformation
00146         void createInvTransform(const vigra::Diff2D & srcSize,
00147                                 const VariableMap & srcVars,
00148                                 Lens::LensProjectionFormat srcProj,
00149                                 const vigra::Diff2D & destSize,
00150                                 PanoramaOptions::ProjectionFormat destProj,
00151                                 double destHFOV);
00152         
00153         
00154     public:
00158         bool transform(hugin_utils::FDiff2D& dest, const hugin_utils::FDiff2D & src) const;
00159 
00163         bool transformImgCoord(double & x_dest, double & y_dest, double x_src, double y_src) const;
00164 
00165         bool transformImgCoord(hugin_utils::FDiff2D & dest, const hugin_utils::FDiff2D &src) const
00166         {
00167             return transformImgCoord(dest.x, dest.y, src.x, src.y);
00168         }
00169         
00170         
00171     public:
00173         bool isIdentity()
00174         {
00175             return m_Stack.size() == 0;
00176         }
00177 
00178         
00179     private:
00181         void AddTransform( trfn function_name, double var0, double var1 = 0.0f, double var2 = 0.0f, double var3 = 0.0f, double var4=0.0f, double var5=0.0f, double var6=0.0f, double var7=0.0f );
00182         void AddTransform( trfn function_name, Matrix3 m, double var0, double var1=0.0f, double var2=0.0f, double var3=0.0f);
00183         
00184         
00185     private:
00187         bool m_Initialized;
00188 
00190         double m_srcTX, m_srcTY;
00191         double m_destTX, m_destTY;
00192 
00194         std::vector<fDescription>       m_Stack;
00195 
00196 };
00197 
00198 
00199 
00200 
00208 template <class VECTOR>
00209 void combinePolynom4(const VECTOR & p,
00210                      const VECTOR & q,
00211                      VECTOR & c);
00212 
00213 
00217 template <class TRANSFORM>
00218 void traceImageOutline(vigra::Size2D sz,
00219                        TRANSFORM & transf,
00220                        vigra::Rect2D & inside,
00221                        vigra::Rect2D & boundingBox);
00222 
00223 
00226 IMPEX double estScaleFactorForFullFrame(const SrcPanoImage & src);
00227 
00228 
00244 double estRadialScaleCrop(const std::vector<double> & coeff, int width, int height);
00245 
00246 
00247 
00248 
00249 
00250 //==============================================================================
00251 // template implementations
00252 
00253 template <class VECTOR>
00254 void combinePolynom4(const VECTOR & p, const VECTOR & q, VECTOR & c)
00255 {
00256     double d3 = p[3]*p[3]*p[3];
00257     c[0] = (3*q[1]*p[3]*p[3]*p[2]+q[3]*p[0]+q[2]*(2*p[3]*p[1]+p[2]*p[2])+q[0]*d3*p[3]);
00258     c[1] = (2*q[2]*p[3]*p[2]+q[1]*d3+q[3]*p[1]);
00259     c[2] = (q[3]*p[2]+q[2]*p[3]*p[3]);
00260     c[3] = q[3]*p[3];
00261 
00262     /*
00263     old code for polynoms of up to x^3
00264     c[0] = q[0]*(p[2]*(2*p[3]*p[1]+p[2]*p[2])+p[3]*(2*p[3]*p[0]+2*p[2]*p[1])+p[0]*p[3]*p[3]+2*p[1]*p[3]*p[2])
00265            +q[1]*(2*p[3]*p[0]+2*p[2]*p[1])+q[2]*p[0];
00266 
00267     c[1] = q[0]*(p[3]*(2*p[3]*p[1]+p[2]*p[2])+2*p[2]*p[2]*p[3]+p[1]*p[3]*p[3])
00268             +q[2]*p[1]+q[1]*(2*p[3]*p[1]+p[2]*p[2]);
00269 
00270     c[2] = 3*q[0]*p[3]*p[3]*p[2]+2*q[1]*p[3]*p[2]+q[2]*p[2];
00271     c[3] = q[0]*p[3]*p[3]*p[3]+q[1]*p[3]*p[3]+q[2]*p[3]+q[3];
00272     */
00273 }
00274 
00275 
00276 template <class TRANSFORM>
00277 void traceImageOutline(vigra::Size2D sz, TRANSFORM & transf, vigra::Rect2D & inside, vigra::Rect2D & boundingBox)
00278 {
00279     boundingBox = vigra::Rect2D();
00280     inside = vigra::Rect2D();
00281     int x=0;
00282     int y=0;
00283     double xd;
00284     double yd;
00285     transf.transformImgCoord(xd,yd, x,y);
00286     // calculate scaling factor that would be required to avoid black borders
00287 //    double scale = std::max((-sz.x/2)/(xd-sz.x/2), (-sz.y/2)/(yd-sz.y/2));
00288     int left = 0;
00289     int right = sz.x;
00290     int top = 0;
00291     int bottom = sz.y;
00292     // left
00293     for (y=0; y < sz.y; y++) {
00294         transf.transformImgCoord(xd,yd, x,y);
00295         boundingBox |= vigra::Point2D(hugin_utils::roundi(xd), hugin_utils::roundi(yd));
00296         left = std::max(hugin_utils::roundi(xd), left);
00297     }
00298     // right
00299     x = sz.x-1;
00300     for (y=0; y < sz.y; y++) {
00301         transf.transformImgCoord(xd,yd, x,y);
00302         boundingBox |= vigra::Point2D(hugin_utils::roundi(xd), hugin_utils::roundi(yd));
00303         right = std::min(hugin_utils::roundi(xd), right);
00304     }
00305     // bottom
00306     y=sz.y-1;
00307     for (x=0; x < sz.x; x++) {
00308         transf.transformImgCoord(xd,yd, x,y);
00309         boundingBox |= vigra::Point2D(hugin_utils::roundi(xd), hugin_utils::roundi(yd));
00310         bottom = std::min(hugin_utils::roundi(yd), bottom);
00311     }
00312     // top
00313     y=0;
00314     for (x=0; x < sz.x; x++) {
00315         transf.transformImgCoord(xd,yd, x,y);
00316         boundingBox |= vigra::Point2D(hugin_utils::roundi(xd), hugin_utils::roundi(yd));
00317         top = std::max(hugin_utils::roundi(yd), top);
00318     }
00319     inside.setUpperLeft(vigra::Point2D(left, top));
00320     inside.setLowerRight(vigra::Point2D(right, bottom));
00321 }
00322 
00323 
00324 
00325 } // namespace
00326 } // namespace
00327 
00328 #endif

Generated on Mon Sep 20 01:01:26 2010 for Hugintrunk by doxygen 1.3.9.1