Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CalculateOptimalScale.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
26 #include "CalculateOptimalScale.h"
27 
29 
30 
31 namespace HuginBase {
32 
35 {
36  if (panorama.getNrOfImages() == 0)
37  return 1;
38 
39  PanoramaOptions opt = panorama.getOptions();
40  double scale = 0;
41 
42  for (unsigned i = 0; i < panorama.getNrOfImages(); i++) {
43  double s = calcOptimalPanoScale(panorama.getSrcImage(i), opt);
44  if (scale < s) {
45  scale = s;
46  }
47  }
48 
49  return scale;
50 }
51 
52 
57  const PanoramaOptions & dest)
58 {
59  // calculate the input pixel per output pixel ratio at the panorama center.
60 
61  PTools::Transform transf;
62  SrcPanoImage timg = src;
63  timg.setRoll(0);
64  timg.setPitch(0);
65  timg.setYaw(0);
66  timg.setX(0);
67  timg.setY(0);
68  timg.setZ(0);
69  transf.createTransform(timg, dest);
72 
73  transf.transform(imgp1, hugin_utils::FDiff2D(0, 0));
74  transf.transform(imgp2, hugin_utils::FDiff2D(1, 1));
75  double dist = hugin_utils::norm(imgp2-imgp1);
76 
77  return dist / sqrt(2.0);
78 
79  /*
80  // calculate average pixel density of each image
81  // and use the highest one to calculate the width
82  double density=0;
83  double w = imgSize.x;
84  switch (imgProj) {
85  case Lens::RECTILINEAR:
86  density = 1/RAD_TO_DEG(atan(2*tan(DEG_TO_RAD(v)/2)/w));
87  break;
88  case Lens::CIRCULAR_FISHEYE:
89  case Lens::FULL_FRAME_FISHEYE:
90  // if we assume the linear fisheye model: r = f * theta
91  // then we get the same pixel density as for cylindrical and equirect
92  case Lens::EQUIRECTANGULAR:
93  case Lens::PANORAMIC:
94  density = w / v;
95  break;
96  }
97  // TODO: use density properly based on the output projection.
98  double width = roundi(density * opt.getHFOV());
99  */
100 }
101 
102 
103 } //namespace
static double calcOptimalPanoScale(const SrcPanoImage &src, const PanoramaOptions &dest)
function to calculate the scaling factor so that the distances in the input image and panorama image ...
double norm(T t)
Definition: hugin_math.h:175
bool transform(double &x_dest, double &y_dest, double x_src, double y_src) const
excecute transform
static double calcOptimalScale(PanoramaData &panorama)
virtual const PanoramaOptions & getOptions() const =0
returns the options for this panorama
Model for a panorama.
Definition: PanoramaData.h:81
Holds transformations for Image -&gt; Pano and the other way.
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.
All variables of a source image.
Definition: SrcPanoImage.h:194
Panorama image options.
void createTransform(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)
initialize pano-&gt;image transformation