Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
30 #include <nona/RemappedPanoImage.h>
31 
32 namespace 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.
66  vigra_ext::srcMaskRange(remapped)),
68  vigra_ext::srcMask(remapped)),
70  destImage(panoAlpha)));
71  }
72 
73  // get field of view
74  hugin_utils::FDiff2D ul, lr;
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;
108  lr=lr/2.0;
109  ul.x = ul.x - 180;
110  ul.y = ul.y - 90;
111  lr.x = lr.x - 180;
112  lr.y = lr.y - 90;
113  hugin_utils::FDiff2D fov(2 * std::max(fabs(ul.x), fabs(lr.x)), 2 * std::max(fabs(ul.y), fabs(lr.y)));
114  // the calculation above is done with a resolution of 1 deg
115  // for small fov the calculated fov can be a little bit too small
116  // so in this case add a small offset
117  if(fov.x<40)
118  {
119  fov.x+=1;
120  };
121  if (fov.y < 40)
122  {
123  fov.y += 1;
124  };
125  return fov;
126 }
127 
128 }
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
void setHeight(unsigned int h)
set panorama height
void setPanoImage(const SrcPanoImage &src, const PanoramaOptions &dest, vigra::Rect2D roi)
void copyImageIf(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc, MaskImageIterator mask_upperleft, MaskAccessor mask_acc, DestImageIterator dest_upperleft, DestAccessor dest_acc)
Definition: openmp_vigra.h:316
static hugin_utils::FDiff2D calcFOV(const PanoramaData &panorama)
Contains functions to transform whole images.
std::set< unsigned int > UIntSet
Definition: PanoramaData.h:51
virtual UIntSet getActiveImages() const =0
get active images
virtual const PanoramaOptions & getOptions() const =0
returns the options for this panorama
IMPEX double h[25][1024]
Definition: emor.cpp:169
Model for a panorama.
Definition: PanoramaData.h:81
TDiff2D< double > FDiff2D
Definition: hugin_math.h:150
vigra::pair< typename ROIImage< Image, Alpha >::image_traverser, typename ROIImage< Image, Alpha >::ImageAccessor > destImage(ROIImage< Image, Alpha > &img)
Definition: ROIImage.h:324
void setHFOV(double h, bool keepView=true)
set the horizontal field of view.
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
static T max(T x, T y)
Definition: svm.cpp:65
vigra::pair< typename ROIImage< Image, Alpha >::mask_const_traverser, typename ROIImage< Image, Alpha >::MaskConstAccessor > srcMask(const ROIImage< Image, Alpha > &img)
Definition: ROIImage.h:347
void calcAlpha()
calculate only the alpha channel.
virtual SrcPanoImage getSrcImage(unsigned imgNr) const =0
get a complete description of a source image
virtual std::size_t getNrOfImages() const =0
number of images.
void setProjection(ProjectionFormat f)
set the Projection format and adjust the hfov/vfov if nessecary
Panorama image options.
struct to hold a image state for stitching
void setWidth(unsigned int w, bool keepView=true)
set panorama width keep the HFOV, if keepView=true