LayoutRemapper.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00024 #ifdef __WXMAC__
00025 #include "panoinc_WX.h"
00026 #include "panoinc.h"
00027 #endif
00028 
00029 #include <cmath>
00030 
00031 #include "LayoutRemapper.h"
00032 #include "ViewState.h"
00033 
00034 LayoutRemapper::LayoutRemapper(HuginBase::Panorama *m_pano,
00035                                HuginBase::SrcPanoImage* image,
00036                                VisualizationState *visualization_state)
00037         :MeshRemapper(m_pano, image, visualization_state),
00038          scale(0)
00039         
00040 {
00041     // We'll never use any different texture coordinates, so record them now:
00042     face.tex_c[0][0][0] = 0.0;
00043     face.tex_c[0][0][1] = 0.0;
00044     face.tex_c[0][1][0] = 0.0;
00045     face.tex_c[0][1][1] = 1.0;
00046     face.tex_c[1][0][0] = 1.0;
00047     face.tex_c[1][0][1] = 0.0;
00048     face.tex_c[1][1][0] = 1.0;
00049     face.tex_c[1][1][1] = 1.0;
00050 }
00051 
00052 void LayoutRemapper::UpdateAndResetIndex()
00053 {
00054 //    HuginBase::SrcPanoImage *src_img = visualization_state->GetSrcImage(image_number);
00055     
00056     // find the image size.
00057     double image_width = (double) image->getSize().width();
00058     double image_height = (double) image->getSize().height();
00059     
00060     // remap the middle of the image to find centre coordinates.
00061     double centre_x, centre_y;
00062     // create a transformation from source image to destination.
00063     transform.createInvTransform(*image, *(visualization_state->GetOptions()));
00064     transform.transformImgCoord(centre_x, centre_y,
00065                                 image_width / 2.0, image_height / 2.0);
00074     // work out the size to draw the image
00075     bool landscape = image_width > image_height;
00076     double preview_width, preview_height;
00077     if (landscape)
00078     {
00079         preview_width = scale;
00080         preview_height = scale / image_width * image_height;
00081     } else {
00082         preview_height = scale;
00083         preview_width = scale / image_height * image_width;
00084     }
00085     
00086     // find bounds for image drawing
00087     double offset_x = preview_width / 2.0;
00088     double offset_y = preview_height / 2.0;
00089     
00090     // find the roll of the image.
00091     double angle = image->getRoll() * (M_PI / 180.0) + (M_PI / 2.0);
00092     double rsin = std::sin(angle);
00093     double rcos = std::cos(angle);
00094     
00095     double rsin_x = rsin * offset_x;
00096     double rcos_x = rcos * offset_x;
00097     double rsin_y = rsin * offset_y;
00098     double rcos_y = rcos * offset_y;
00099     
00100     face.vertex_c[0][0][0] = -rsin_x - rcos_y + centre_x;
00101     face.vertex_c[0][0][1] = rcos_x -rsin_y + centre_y;
00102     face.vertex_c[0][1][0] = -rsin_x + rcos_y + centre_x;
00103     face.vertex_c[0][1][1] = rcos_x + rsin_y + centre_y;
00104     face.vertex_c[1][0][0] = rsin_x - rcos_y + centre_x;
00105     face.vertex_c[1][0][1] = -rcos_x - rsin_y + centre_y;
00106     face.vertex_c[1][1][0] = rsin_x + rcos_y + centre_x;
00107     face.vertex_c[1][1][1] = -rcos_x + rsin_y + centre_y;
00108     
00109     // Specify our one face next time GetNextFaceCoordinates is called.
00110     done = false;
00111 }
00112 
00113 bool LayoutRemapper::GetNextFaceCoordinates(Coords *result)
00114 {
00115     if (!done)
00116     {
00117         // point caller at our coordinates.
00118         result->tex_c = face.tex_c;
00119         result->vertex_c = face.vertex_c;
00120         // record that they have seen this face.
00121         done = true;
00122         return true;
00123     }
00124     // We've specified the one face required. No need for more.
00125     return false;
00126 }
00127 
00128 void LayoutRemapper::setScale(double scale_in)
00129 {
00130     scale = scale_in;
00131 }

Generated on 26 Nov 2014 for Hugintrunk by  doxygen 1.4.7