1 // -*- c-basic-offset: 4 -*-
2 /** @file FitPanorama.cpp
3  *
4  *  @author Pablo d'Angelo <pablo.dangelo@web.de>
5  *
6  *  $Id: Panorama.h 1947 2007-04-15 20:46:00Z dangelo $
7  *
8  * !! from Panorama.h 1947
9  *
10  *  This is free software; you can redistribute it and/or
11  *  modify it under the terms of the GNU General Public
12  *  License as published by the Free Software Foundation; either
13  *  version 2 of the License, or (at your option) any later version.
14  *
15  *  This software is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  *  Lesser General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public
21  *  License along with this software. If not, see
22  *  <http://www.gnu.org/licenses/>.
23  *
24  */
25 
26 #include "FitPanorama.h"
27 
28 #include <algorithm>
29 #include <panodata/PanoramaData.h>
30 #include <panotools/PanoToolsInterface.h>
31 #include <algorithms/nona/CalculateFOV.h>
32 
33 namespace HuginBase {
34 
fitPano(PanoramaData & panorama,double & HFOV,double & height)35 void CalculateFitPanorama::fitPano(PanoramaData& panorama, double& HFOV, double& height)
36 {
37     // FIXME: doesn't work properly for fisheye and mirror projections,
38     // it will not calculate a vfov bigger than 180.
39     hugin_utils::FDiff2D fov = CalculateFOV::calcFOV(panorama);
40 
41     // use estimated fov to calculate a suitable panorama height.
42     // calculate VFOV based on current panorama
43     PTools::Transform transf;
44     SrcPanoImage src;
45     src.setProjection(SrcPanoImage::EQUIRECTANGULAR);
46     src.setHFOV(360);
47     src.setSize(vigra::Size2D(360,180));
48 
49     // output pano with new hfov
50     PanoramaOptions opts = panorama.getOptions();
51     opts.setHFOV(fov.x, false);
52     transf.createInvTransform(src, opts);
53 
54     // limit fov to suitable range for this projection
55     fov.x = std::min(fov.x, panorama.getOptions().getMaxHFOV());
56     fov.y = std::min(fov.y, panorama.getOptions().getMaxVFOV());
57 
58     hugin_utils::FDiff2D pmiddle;
59     // special case for projections with max VFOV > 180 (fisheye, stereographic)
60     if (panorama.getOptions().getMaxVFOV() >  180 && fov.x > 180) {
61         transf.transform(pmiddle, hugin_utils::FDiff2D(180, 180 - fov.x / 2 + 0.01));
62     } else {
63         transf.transform(pmiddle, hugin_utils::FDiff2D(0, fov.y / 2));
64     }
65 
66     height = fabs(2*pmiddle.y);
67     HFOV = fov.x;
68 }
69 
70 
runAlgorithm()71 bool FitPanorama::runAlgorithm()
72 {
73     if( CalculateFitPanorama::runAlgorithm() )
74     {
75 
76         PanoramaOptions opts = o_panorama.getOptions();
77 
78         opts.setHFOV(getResultHorizontalFOV());
79         opts.setHeight(hugin_utils::roundi(getResultHeight()));
80 
81         o_panorama.setOptions(opts);
82 
83         return true; // let's hope so.
84 
85     }
86 
87     return false;
88 }
89 
90 } //namespace
91