Hugin trunk 0.1
Loading...
Searching...
No Matches
CalculateFOV.cpp
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
26#include "CalculateFOV.h"
27
28#include <algorithm>
29#include <vigra/copyimage.hxx>
31
32namespace HuginBase {
33
35{
36 if (panorama.getNrOfImages() == 0) {
37 // no change
38 return hugin_utils::FDiff2D(panorama.getOptions().getHFOV(), panorama.getOptions().getVFOV());
39 }
40
41 vigra::Size2D panoSize(360*2,180*2);
42
43 // remap into minature pano.
44 PanoramaOptions opts;
45 opts.setHFOV(360);
47 opts.setWidth(panoSize.x);
48 opts.setHeight(panoSize.y);
49
50 // remap image
51 // DGSW - make sure the type is correct
52 vigra::BImage panoAlpha(panoSize.x, panoSize.y,static_cast< unsigned char >(0));
53 // vigra::BImage panoAlpha(panoSize.x, panoSize.y,0);
55 UIntSet activeImgs = panorama.getActiveImages();
56 for (UIntSet::iterator it = activeImgs.begin(); it != activeImgs.end(); ++it) {
57 // for (unsigned int imgNr=0; imgNr < getNrOfImages(); imgNr++) {
58 // DGSW FIXME - Unreferenced
59 // const PanoImage & img = getImage(*it);
60 remapped.setPanoImage(panorama.getSrcImage(*it), opts, vigra::Rect2D(0,0,panoSize.x,panoSize.y));
61 //remapped.setPanoImage(*this, *it, vigra::Size2D(img.getWidth(), img.getHeight()), opts);
62 // calculate alpha channel
63 remapped.calcAlpha();
64 // copy into global alpha channel.
65 vigra::copyImageIf(vigra_ext::applyRect(remapped.boundingBox(),
67 vigra_ext::applyRect(remapped.boundingBox(),
69 vigra_ext::applyRect(remapped.boundingBox(),
70 destImage(panoAlpha)));
71 }
72
73 // get field of view
75 bool found = false;
76 ul.x = DBL_MAX;
77 ul.y = DBL_MAX;
78 lr.x = -DBL_MAX;
79 lr.y = -DBL_MAX;
80 for (int v=0; v< panoSize.y; v++) {
81 for (int h=0; h < panoSize.x; h++) {
82 if (panoAlpha(h,v)) {
83 // pixel is valid
84 if ( ul.x > h ) {
85 found=true;
86 ul.x = h;
87 }
88 if ( ul.y > v ) {
89 found=true;
90 ul.y = v;
91 }
92 if ( lr.x < h) {
93 found=true;
94 lr.x = h;
95 }
96 if ( lr.y < v) {
97 found=true;
98 lr.y = v;
99 }
100 }
101 }
102 }
103 if (!found) {
104 // if nothing found, return current fov
105 return hugin_utils::FDiff2D(panorama.getOptions().getHFOV(), panorama.getOptions().getVFOV());
106 }
107 ul = ul / 2.0 - hugin_utils::FDiff2D(0.5, 0.5) - hugin_utils::FDiff2D(180, 90);
108 lr = lr / 2.0 + hugin_utils::FDiff2D(0.5, 0.5) - hugin_utils::FDiff2D(180, 90);
109 hugin_utils::FDiff2D fov(2 * std::max(fabs(ul.x), fabs(lr.x)), 2 * std::max(fabs(ul.y), fabs(lr.y)));
110 // the calculation above is done with a resolution of 1 deg
111 // for small fov the calculated fov can be a little bit too small
112 // so in this case add a small offset
113 if(fov.x<40)
114 {
115 fov.x+=1;
116 };
117 if (fov.y < 40)
118 {
119 fov.y += 1;
120 };
121 return fov;
122}
123
124}
Contains functions to transform whole images.
static hugin_utils::FDiff2D calcFOV(const PanoramaData &panorama)
struct to hold a image state for stitching
void setPanoImage(const SrcPanoImage &src, const PanoramaOptions &dest, vigra::Rect2D roi)
Model for a panorama.
Panorama image options.
void setHFOV(double h, bool keepView=true)
set the horizontal field of view.
void setProjection(ProjectionFormat f)
set the Projection format and adjust the hfov/vfov if nessecary
void setHeight(unsigned int h)
set panorama height
void setWidth(unsigned int w, bool keepView=true)
set panorama width keep the HFOV, if keepView=true
mainly consists of wrapper around the pano tools library, to assist in ressource management and to pr...
Definition wxcms.cpp:39
std::set< unsigned int > UIntSet
TDiff2D< double > FDiff2D
Definition hugin_math.h:162
vigra::pair< typename ROIImage< Image, Alpha >::mask_const_traverser, typename ROIImage< Image, Alpha >::MaskConstAccessor > srcMask(const ROIImage< Image, Alpha > &img)
Definition ROIImage.h:347
vigra::triple< typename ROIImage< Image, Alpha >::mask_const_traverser, typename ROIImage< Image, Alpha >::mask_const_traverser, typename ROIImage< Image, Alpha >::MaskConstAccessor > srcMaskRange(const ROIImage< Image, Alpha > &img)
Definition ROIImage.h:335
vigra::triple< ImgIter, ImgIter, ImgAcc > applyRect(vigra::Rect2D &r, vigra::triple< ImgIter, ImgIter, ImgAcc > img)
apply a roi to an image area
Definition ROIImage.h:46
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.
Definition threshold.h:41