CalculateOptimalScale.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00026 #include "CalculateOptimalScale.h"
00027 
00028 #include <panotools/PanoToolsInterface.h>
00029 
00030 
00031 namespace HuginBase {
00032 
00033 using namespace hugin_utils;
00034 
00036 double CalculateOptimalScale::calcOptimalScale(PanoramaData& panorama)
00037 {
00038     if (panorama.getNrOfImages() == 0)
00039         return 1;
00040 
00041     PanoramaOptions opt = panorama.getOptions();
00042     double scale = 0;
00043 
00044     for (unsigned i = 0; i < panorama.getNrOfImages(); i++) {
00045         double s = calcOptimalPanoScale(panorama.getSrcImage(i), opt);
00046         if (scale < s) {
00047             scale = s;
00048         }
00049     }
00050 
00051     return scale;
00052 }
00053 
00054 
00058 double CalculateOptimalScale::calcOptimalPanoScale(const SrcPanoImage & src,
00059                                                     const PanoramaOptions & dest)
00060 {
00061     // calculate the input pixel per output pixel ratio at the panorama center.
00062 
00063     PTools::Transform transf;
00064     SrcPanoImage timg = src;
00065     timg.setRoll(0);
00066     timg.setPitch(0);
00067     timg.setYaw(0);
00068     timg.setX(0);
00069     timg.setY(0);
00070     timg.setZ(0);
00071     transf.createTransform(timg, dest);
00072     FDiff2D imgp1;
00073     FDiff2D imgp2;
00074 
00075     transf.transform(imgp1, FDiff2D(0,0));
00076     transf.transform(imgp2, FDiff2D(1,1));
00077     double dist = hugin_utils::norm(imgp2-imgp1);
00078 
00079     return dist / sqrt(2.0);
00080 
00081     /*
00082         // calculate average pixel density of each image
00083         // and use the highest one to calculate the width
00084         double density=0;
00085         double w = imgSize.x;
00086         switch (imgProj) {
00087             case Lens::RECTILINEAR:
00088                 density = 1/RAD_TO_DEG(atan(2*tan(DEG_TO_RAD(v)/2)/w));
00089                 break;
00090             case Lens::CIRCULAR_FISHEYE:
00091             case Lens::FULL_FRAME_FISHEYE:
00092                 // if we assume the linear fisheye model: r = f * theta
00093                 // then we get the same pixel density as for cylindrical and equirect
00094             case Lens::EQUIRECTANGULAR:
00095             case Lens::PANORAMIC:
00096                 density = w / v;
00097                 break;
00098         }
00099         // TODO: use density properly based on the output projection.
00100         double width = roundi(density * opt.getHFOV());
00101         */
00102 }
00103 
00104 
00105 } //namespace

Generated on 21 Oct 2014 for Hugintrunk by  doxygen 1.4.7