CalculateFOV.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00026 #include "CalculateFOV.h"
00027 
00028 #include <algorithm>
00029 #include <vigra/copyimage.hxx>
00030 #include <nona/RemappedPanoImage.h>
00031 
00032 namespace HuginBase {
00033 
00034 using namespace hugin_utils;
00035 
00036 FDiff2D CalculateFOV::calcFOV(const PanoramaData& panorama)
00037 {
00038     if (panorama.getNrOfImages() == 0) {
00039         // no change
00040         return FDiff2D(panorama.getOptions().getHFOV(), panorama.getOptions().getVFOV());
00041     }
00042 
00043     vigra::Size2D panoSize(360*2,180*2);
00044 
00045     // remap into minature pano.
00046     PanoramaOptions opts;
00047     opts.setHFOV(360);
00048     opts.setProjection(PanoramaOptions::EQUIRECTANGULAR);
00049     opts.setWidth(panoSize.x);
00050     opts.setHeight(panoSize.y);
00051 
00052     // remap image
00053     // DGSW - make sure the type is correct
00054     vigra::BImage panoAlpha(panoSize.x, panoSize.y,static_cast< unsigned char >(0));
00055     //    vigra::BImage panoAlpha(panoSize.x, panoSize.y,0);
00056     Nona::RemappedPanoImage<vigra::BImage, vigra::BImage> remapped;
00057     UIntSet activeImgs = panorama.getActiveImages();
00058     for (UIntSet::iterator it = activeImgs.begin(); it != activeImgs.end(); ++it) {
00059         //    for (unsigned int imgNr=0; imgNr < getNrOfImages(); imgNr++) {
00060         // DGSW FIXME - Unreferenced
00061         //              const PanoImage & img = getImage(*it);
00062         remapped.setPanoImage(panorama.getSrcImage(*it), opts, vigra::Rect2D(0,0,panoSize.x,panoSize.y));
00063         //remapped.setPanoImage(*this, *it, vigra::Size2D(img.getWidth(), img.getHeight()), opts);
00064         // calculate alpha channel
00065         remapped.calcAlpha();
00066         // copy into global alpha channel.
00067         vigra::copyImageIf(vigra_ext::applyRect(remapped.boundingBox(),
00068                                                 vigra_ext::srcMaskRange(remapped)),
00069                             vigra_ext::applyRect(remapped.boundingBox(),
00070                                                 vigra_ext::srcMask(remapped)),
00071                             vigra_ext::applyRect(remapped.boundingBox(),
00072                                                 destImage(panoAlpha)));
00073         }
00074 
00075     // get field of view
00076     FDiff2D ul,lr;
00077     bool found = false;
00078     ul.x = DBL_MAX;
00079     ul.y = DBL_MAX;
00080     lr.x = -DBL_MAX;
00081     lr.y = -DBL_MAX;
00082     for (int v=0; v< panoSize.y; v++) {
00083         for (int h=0; h < panoSize.x; h++) {
00084             if (panoAlpha(h,v)) {
00085                 // pixel is valid
00086                 if ( ul.x > h ) {
00087                     found=true;
00088                     ul.x = h;
00089                 }
00090                 if ( ul.y > v ) {
00091                     found=true;
00092                     ul.y = v;
00093                 }
00094                 if ( lr.x < h) {
00095                     found=true;
00096                     lr.x = h;
00097                 }
00098                 if ( lr.y < v) {
00099                     found=true;
00100                     lr.y = v;
00101                 }
00102             }
00103         }
00104     }
00105     if (!found) {
00106         // if nothing found, return current fov
00107         return FDiff2D(panorama.getOptions().getHFOV(), panorama.getOptions().getVFOV());
00108     }
00109     ul=ul/2.0;
00110     lr=lr/2.0;
00111     ul.x = ul.x - 180;
00112     ul.y = ul.y - 90;
00113     lr.x = lr.x - 180;
00114     lr.y = lr.y - 90;
00115     FDiff2D fov (2*std::max(fabs(ul.x), fabs(lr.x)), 2*std::max(fabs(ul.y), fabs(lr.y)));
00116     if(fov.x<40)
00117     {
00118         fov.x+=1;
00119     };
00120     return fov;
00121 }
00122 
00123 }

Generated on 4 Sep 2015 for Hugintrunk by  doxygen 1.4.7