Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OutputProjectionInfo.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
23 #include "OutputProjectionInfo.h"
24 
26 {
27  proj = output;
28  // create the transformation from lat/long to the output image.
29  HuginBase::SrcPanoImage fake_image;
30  fake_image.setProjection(HuginBase::SrcPanoImage::EQUIRECTANGULAR);
31  fake_image.setSize(vigra::Size2D(360, 180));
32  fake_image.setHFOV(360.0);
33  transform.createInvTransform(fake_image, *output);
34  // sometimes we want to go back again
35  reverse_transform.createTransform(fake_image, *output);
36  // now grab the frequently used values
37  double x, y;
38  transform.transformImgCoord(x, y, 0.0, 90.0);
39  x_add_360 = x * -2.0 + output->getSize()->x;
40  radius = -x + output->getSize()->x / 2.0;
41  transform.transformImgCoord(x, y, 180.0, 0.0);
42  y_add_360 = -y * 2.0 + output->getSize()->y;
43  north_pole_x = x;
44  north_pole_y = y;
45  transform.transformImgCoord(x, y, 180.0, 180.0);
46  south_pole_x = x;
47  south_pole_y = y;
48  transform.transformImgCoord(x, y, 180.0, 90.0);
49  middle_x = x;
50  middle_y = y;
51  transform.transformImgCoord(x, y, 120.0, 90.0);
52  lower_x = x;
53  transform.transformImgCoord(x, y, 240.0, 90.0);
54  upper_x = x;
55  transform.transformImgCoord(x, y, 180.0, 60.0);
56  lower_y = y;
57  transform.transformImgCoord(x, y, 180.0, 120.0);
58  upper_y = y;
59  switch (output->getProjection())
60  {
70  // The poles are on the sides.
71  // ...or at least they can be detected from the sides (disk-likes)
72  // I've offset the noth pole slightly as the detection rate was
73  // not 100%
74  transform.transformImgCoord(x, y, 0.5, 90.0);
75  north_pole_x = x;
76  north_pole_y = y;
77  transform.transformImgCoord(x, y, 359.5, 90.0);
78  south_pole_x = x;
79  south_pole_y = y;
80  break;
81  default:
82  break;
83  }
84 }
85 
86 // Some of the properties defined above change with height in some projections.
87 // We have to convert an output point to elevation, and then find the boundaries
88 // for +/- 180 degree seam detection at that elevation.
89 const double OutputProjectionInfo::GetUpperX(const double y) const
90 {
91  double temp, pitch, result;
92  reverse_transform.transformImgCoord(temp, pitch, 180, y);
93  transform.transformImgCoord(result, temp, 240.0, pitch);
94  return result;
95 }
96 
97 const double OutputProjectionInfo::GetLowerX(const double y) const
98 {
99  double temp, pitch, result;
100  reverse_transform.transformImgCoord(temp, pitch, 180, y);
101  transform.transformImgCoord(result, temp, 120.0, pitch);
102  return result;
103 }
104 
105 // correction also changes, this is needed to move the detected vertices.
106 const double OutputProjectionInfo::GetXAdd360(const double y) const
107 {
108  double temp, pitch, result;
109  reverse_transform.transformImgCoord(temp, pitch, 180, y);
110  transform.transformImgCoord(result, temp, 0.0, pitch);
111  return result * -2.0 + proj->getSize()->x;
112 }
113 
114 
115 // Use the transformations to get arbitary points.
116 
117 bool OutputProjectionInfo::AngularToImage(double &image_x, double &image_y,
118  double yaw, double pitch)
119 {
120  return transform.transformImgCoord(image_x, image_y,
121  yaw + 180.0, pitch + 90.0);
122 }
123 
124 bool OutputProjectionInfo::ImageToAngular(double &yaw, double &pitch,
125  double image_x, double image_y)
126 {
127  bool r = reverse_transform.transformImgCoord(yaw, pitch, image_x, image_y);
128  yaw -= 180.0;
129  pitch -= 90.0;
130  return r;
131 }
132 
PanoramaOptions::ProjectionFormat getProjection() const
HuginBase::PTools::Transform transform
const double GetUpperX() const
OutputProjectionInfo(HuginBase::PanoramaOptions *output)
HuginBase::PanoramaOptions * proj
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
bool AngularToImage(double &image_x, double &image_y, double yaw, double pitch)
const double GetXAdd360() const
const double GetLowerX() const
bool transformImgCoord(double &x_dest, double &y_dest, double x_src, double y_src) const
like transform, but return image coordinates, not cartesian coordinates
void setSize(vigra::Size2D val)
Set the image size in pixels.
All variables of a source image.
Definition: SrcPanoImage.h:194
Panorama image options.
vigra::Size2D getSize() const
get size of output image
bool ImageToAngular(double &yaw, double &pitch, double image_x, double image_y)
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
HuginBase::PTools::Transform reverse_transform