Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LayoutRemapper.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
24 #include "panoinc_WX.h"
25 #include "panoinc.h"
26 
27 #include <cmath>
28 
29 #include "LayoutRemapper.h"
30 #include "ViewState.h"
31 
34  VisualizationState *visualization_state)
35  :MeshRemapper(m_pano, image, visualization_state),
36  m_layoutScale(0)
37 
38 {
39  // We'll never use any different texture coordinates, so record them now:
40  face.tex_c[0][0][0] = 0.0;
41  face.tex_c[0][0][1] = 0.0;
42  face.tex_c[0][1][0] = 0.0;
43  face.tex_c[0][1][1] = 1.0;
44  face.tex_c[1][0][0] = 1.0;
45  face.tex_c[1][0][1] = 0.0;
46  face.tex_c[1][1][0] = 1.0;
47  face.tex_c[1][1][1] = 1.0;
48 }
49 
51 {
52 // HuginBase::SrcPanoImage *src_img = visualization_state->GetSrcImage(image_number);
53 
54  // find the image size.
55  double image_width = (double) image->getSize().width();
56  double image_height = (double) image->getSize().height();
57 
58  // remap the middle of the image to find centre coordinates.
59  double centre_x, centre_y;
60  // create a transformation from source image to destination.
62  transform.transformImgCoord(centre_x, centre_y,
63  image_width / 2.0, image_height / 2.0);
72  // work out the size to draw the image
73  bool landscape = image_width > image_height;
74  double preview_width, preview_height;
75  if (landscape)
76  {
77  preview_width = m_layoutScale;
78  preview_height = m_layoutScale / image_width * image_height;
79  } else {
80  preview_height = m_layoutScale;
81  preview_width = m_layoutScale / image_height * image_width;
82  }
83 
84  // find bounds for image drawing
85  double offset_x = preview_width / 2.0;
86  double offset_y = preview_height / 2.0;
87 
88  // find the roll of the image.
89  double angle = image->getRoll() * (M_PI / 180.0) + (M_PI / 2.0);
90  double rsin = std::sin(angle);
91  double rcos = std::cos(angle);
92 
93  double rsin_x = rsin * offset_x;
94  double rcos_x = rcos * offset_x;
95  double rsin_y = rsin * offset_y;
96  double rcos_y = rcos * offset_y;
97 
98  face.vertex_c[0][0][0] = -rsin_x - rcos_y + centre_x;
99  face.vertex_c[0][0][1] = rcos_x -rsin_y + centre_y;
100  face.vertex_c[0][1][0] = -rsin_x + rcos_y + centre_x;
101  face.vertex_c[0][1][1] = rcos_x + rsin_y + centre_y;
102  face.vertex_c[1][0][0] = rsin_x - rcos_y + centre_x;
103  face.vertex_c[1][0][1] = -rcos_x - rsin_y + centre_y;
104  face.vertex_c[1][1][0] = rsin_x + rcos_y + centre_x;
105  face.vertex_c[1][1][1] = -rcos_x + rsin_y + centre_y;
106 
107  // Specify our one face next time GetNextFaceCoordinates is called.
108  done = false;
109 }
110 
112 {
113  if (!done)
114  {
115  // point caller at our coordinates.
116  result->tex_c = face.tex_c;
117  result->vertex_c = face.vertex_c;
118  // record that they have seen this face.
119  done = true;
120  return true;
121  }
122  // We've specified the one face required. No need for more.
123  return false;
124 }
125 
126 void LayoutRemapper::setScale(double scale_in)
127 {
128  m_layoutScale = scale_in;
129 }
An abstract base class for objects that calculate an approximate remap specified by quadrilatrials...
Definition: MeshRemapper.h:43
void setScale(double scale)
Set the size to draw the images.
A class for exchanging pointers to coordinates.
Definition: MeshRemapper.h:60
HuginBase::SrcPanoImage * image
Definition: MeshRemapper.h:85
LayoutRemapper(HuginBase::Panorama *m_pano, HuginBase::SrcPanoImage *image, VisualizationState *visualization_state)
include file for the hugin project
double(* tex_c)[2][2]
The coordinate in the source image ranging from 0 to 1.
Definition: MeshRemapper.h:64
VisualizationState * visualization_state
Definition: MeshRemapper.h:83
Model for a panorama.
Definition: Panorama.h:152
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 UpdateAndResetIndex()
HuginBase::PTools::Transform transform
A transform to use to remap the images.
Definition: MeshRemapper.h:96
include file for the hugin project
bool transformImgCoord(double &x_dest, double &y_dest, double x_src, double y_src) const
like transform, but return image coordinates, not cartesian coordinates
double vertex_c[2][2][2]
Definition: MeshRemapper.h:75
double m_layoutScale
virtual HuginBase::PanoramaOptions * GetOptions()
Definition: ViewState.cpp:468
virtual bool GetNextFaceCoordinates(Coords *result)
Get the texture and vertex coordinates for the next face.
double tex_c[2][2][2]
Definition: MeshRemapper.h:74
Define a remapper to use in the layout mode.
ArrayCoords face
double(* vertex_c)[2][2]
The coordinate in the panorama, in its pixel space.
Definition: MeshRemapper.h:66
All variables of a source image.
Definition: SrcPanoImage.h:194
#define M_PI
Definition: GaborFilter.cpp:34