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/impex.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         //        vigra::ImageExportInfo imge2("c:/hugin_calcfov_alpha.png");
00074         //        exportImage(vigra::srcImageRange(panoAlpha), imge2);
00075         }
00076 
00077     // get field of view
00078     FDiff2D ul,lr;
00079     bool found = false;
00080     ul.x = DBL_MAX;
00081     ul.y = DBL_MAX;
00082     lr.x = -DBL_MAX;
00083     lr.y = -DBL_MAX;
00084     for (int v=0; v< panoSize.y; v++) {
00085         for (int h=0; h < panoSize.x; h++) {
00086             if (panoAlpha(h,v)) {
00087                 // pixel is valid
00088                 if ( ul.x > h ) {
00089                     found=true;
00090                     ul.x = h;
00091                 }
00092                 if ( ul.y > v ) {
00093                     found=true;
00094                     ul.y = v;
00095                 }
00096                 if ( lr.x < h) {
00097                     found=true;
00098                     lr.x = h;
00099                 }
00100                 if ( lr.y < v) {
00101                     found=true;
00102                     lr.y = v;
00103                 }
00104             }
00105         }
00106     }
00107     if (!found) {
00108         // if nothing found, return current fov
00109         return FDiff2D(panorama.getOptions().getHFOV(), panorama.getOptions().getVFOV());
00110     }
00111     ul=ul/2.0;
00112     lr=lr/2.0;
00113     ul.x = ul.x - 180;
00114     ul.y = ul.y - 90;
00115     lr.x = lr.x - 180;
00116     lr.y = lr.y - 90;
00117     FDiff2D fov (2*std::max(fabs(ul.x), fabs(lr.x)), 2*std::max(fabs(ul.y), fabs(lr.y)));
00118     if(fov.x<40)
00119     {
00120         fov.x+=1;
00121     };
00122     return fov;
00123 }
00124 
00125 }

Generated on Fri Aug 22 01:25:43 2014 for Hugintrunk by  doxygen 1.3.9.1