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 #ifdef __WXMAC__
25 #include "panoinc_WX.h"
26 #include "panoinc.h"
27 #endif
28 
29 #include <cmath>
30 
31 #include "LayoutRemapper.h"
32 #include "ViewState.h"
33 
36  VisualizationState *visualization_state)
37  :MeshRemapper(m_pano, image, visualization_state),
38  m_layoutScale(0)
39 
40 {
41  // We'll never use any different texture coordinates, so record them now:
42  face.tex_c[0][0][0] = 0.0;
43  face.tex_c[0][0][1] = 0.0;
44  face.tex_c[0][1][0] = 0.0;
45  face.tex_c[0][1][1] = 1.0;
46  face.tex_c[1][0][0] = 1.0;
47  face.tex_c[1][0][1] = 0.0;
48  face.tex_c[1][1][0] = 1.0;
49  face.tex_c[1][1][1] = 1.0;
50 }
51 
53 {
54 // HuginBase::SrcPanoImage *src_img = visualization_state->GetSrcImage(image_number);
55 
56  // find the image size.
57  double image_width = (double) image->getSize().width();
58  double image_height = (double) image->getSize().height();
59 
60  // remap the middle of the image to find centre coordinates.
61  double centre_x, centre_y;
62  // create a transformation from source image to destination.
64  transform.transformImgCoord(centre_x, centre_y,
65  image_width / 2.0, image_height / 2.0);
74  // work out the size to draw the image
75  bool landscape = image_width > image_height;
76  double preview_width, preview_height;
77  if (landscape)
78  {
79  preview_width = m_layoutScale;
80  preview_height = m_layoutScale / image_width * image_height;
81  } else {
82  preview_height = m_layoutScale;
83  preview_width = m_layoutScale / image_height * image_width;
84  }
85 
86  // find bounds for image drawing
87  double offset_x = preview_width / 2.0;
88  double offset_y = preview_height / 2.0;
89 
90  // find the roll of the image.
91  double angle = image->getRoll() * (M_PI / 180.0) + (M_PI / 2.0);
92  double rsin = std::sin(angle);
93  double rcos = std::cos(angle);
94 
95  double rsin_x = rsin * offset_x;
96  double rcos_x = rcos * offset_x;
97  double rsin_y = rsin * offset_y;
98  double rcos_y = rcos * offset_y;
99 
100  face.vertex_c[0][0][0] = -rsin_x - rcos_y + centre_x;
101  face.vertex_c[0][0][1] = rcos_x -rsin_y + centre_y;
102  face.vertex_c[0][1][0] = -rsin_x + rcos_y + centre_x;
103  face.vertex_c[0][1][1] = rcos_x + rsin_y + centre_y;
104  face.vertex_c[1][0][0] = rsin_x - rcos_y + centre_x;
105  face.vertex_c[1][0][1] = -rcos_x - rsin_y + centre_y;
106  face.vertex_c[1][1][0] = rsin_x + rcos_y + centre_x;
107  face.vertex_c[1][1][1] = -rcos_x + rsin_y + centre_y;
108 
109  // Specify our one face next time GetNextFaceCoordinates is called.
110  done = false;
111 }
112 
114 {
115  if (!done)
116  {
117  // point caller at our coordinates.
118  result->tex_c = face.tex_c;
119  result->vertex_c = face.vertex_c;
120  // record that they have seen this face.
121  done = true;
122  return true;
123  }
124  // We've specified the one face required. No need for more.
125  return false;
126 }
127 
128 void LayoutRemapper::setScale(double scale_in)
129 {
130  m_layoutScale = scale_in;
131 }
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