Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FitPanorama.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
26 #include "FitPanorama.h"
27 
28 #include <algorithm>
29 #include <panodata/PanoramaData.h>
33 
34 namespace HuginBase {
35 
36 void CalculateFitPanorama::fitPano(PanoramaData& panorama, double& HFOV, double& height)
37 {
38  // FIXME: doesn't work properly for fisheye and mirror projections,
39  // it will not calculate a vfov bigger than 180.
41 
42  // use estimated fov to calculate a suitable panorama height.
43  // calculate VFOV based on current panorama
44  PTools::Transform transf;
45  SrcPanoImage src;
46  src.setProjection(SrcPanoImage::EQUIRECTANGULAR);
47  src.setHFOV(360);
48  src.setSize(vigra::Size2D(360,180));
49 
50  // output pano with new hfov
51  PanoramaOptions opts = panorama.getOptions();
52  opts.setHFOV(fov.x, false);
53  transf.createInvTransform(src, opts);
54 
55  // limit fov to suitable range for this projection
56  fov.x = std::min(fov.x, panorama.getOptions().getMaxHFOV());
57  fov.y = std::min(fov.y, panorama.getOptions().getMaxVFOV());
58 
59  // special treatment for rectilinear projection
61  {
62  // first calculate the maximal vertical fov for maximal horizontal fov
64  transf.transform(pedge, fov / 2.0);
65  // with this maximal vfov calculate the output roi for each active image
66  // to get the maximal vertical area covered by images
67  HuginBase::PanoramaOptions tempOpts = panorama.getOptions();
68  tempOpts.setHFOV(fov.x);
69  tempOpts.setHeight(fabs(2 * pedge.y));
70  tempOpts.setROI(vigra::Rect2D(0, 0, tempOpts.getWidth(), tempOpts.getHeight()));
71  vigra::Rect2D roi;
72  for (const auto& i : panorama.getActiveImages())
73  {
74  roi |= estimateOutputROI(panorama, tempOpts, i);
75  };
76  height = 2.0 * std::max(tempOpts.getHeight() / 2.0 - roi.top(), roi.bottom() - tempOpts.getHeight() / 2.0);
77  }
78  else
79  {
80  hugin_utils::FDiff2D pmiddle;
81  // special case for projections with max VFOV > 180 (fisheye, stereographic)
82  if (panorama.getOptions().getMaxVFOV() > 180 && fov.x > 180)
83  {
84  transf.transform(pmiddle, hugin_utils::FDiff2D(180, 180 - fov.x / 2 + 0.01));
85  }
86  else
87  {
88  transf.transform(pmiddle, hugin_utils::FDiff2D(0, fov.y / 2));
89  };
90 
91  height = fabs(2 * pmiddle.y);
92  };
93  HFOV = fov.x;
94 }
95 
96 
98 {
100  {
101 
103 
106 
107  o_panorama.setOptions(opts);
108 
109  return true; // let's hope so.
110 
111  }
112 
113  return false;
114 }
115 
116 } //namespace
PanoramaOptions::ProjectionFormat getProjection() const
void setHeight(unsigned int h)
set panorama height
int roundi(T x)
Definition: hugin_math.h:73
vigra::Rect2D estimateOutputROI(const PanoramaData &pano, const PanoramaOptions &opts, unsigned i, const double maxLength)
static hugin_utils::FDiff2D calcFOV(const PanoramaData &panorama)
unsigned int getHeight() const
get panorama height
double getMaxHFOV() const
get maximum possible hfov with current projection
virtual bool runAlgorithm()
implementation of the algorithm.
Definition: FitPanorama.h:56
static void fitPano(PanoramaData &panorama, double &HFOV, double &height)
Definition: FitPanorama.cpp:36
bool transform(double &x_dest, double &y_dest, double x_src, double y_src) const
excecute transform
double HFOV
virtual UIntSet getActiveImages() const =0
get active images
void createInvTransform(const vigra::Diff2D &srcSize, VariableMap srcVars, Lens::LensProjectionFormat srcProj, const vigra::Diff2D &destSize, PanoramaOptions::ProjectionFormat destProj, const std::vector< double > &destProjParam, double destHFOV, const vigra::Diff2D &origSrcSize)
create image-&gt;pano transformation
virtual void setOptions(const PanoramaOptions &opt)=0
set new output settings This is not used directly for optimizing/stiching, but it can be feed into ru...
double getMaxVFOV() const
get maximum possible vfov with current projection
virtual double getResultHeight()
Definition: FitPanorama.h:75
virtual const PanoramaOptions & getOptions() const =0
returns the options for this panorama
Model for a panorama.
Definition: PanoramaData.h:81
void setROI(const vigra::Rect2D &val)
void setHFOV(double h, bool keepView=true)
set the horizontal field of view.
unsigned int getWidth() const
virtual double getResultHorizontalFOV()
Definition: FitPanorama.h:68
virtual bool runAlgorithm()
implementation of the algorithm.
Definition: FitPanorama.cpp:97
static T max(T x, T y)
Definition: svm.cpp:65
Holds transformations for Image -&gt; Pano and the other way.
void setSize(vigra::Size2D val)
Set the image size in pixels.
All variables of a source image.
Definition: SrcPanoImage.h:194
Panorama image options.
static T min(T x, T y)
Definition: svm.cpp:62