ChoosyRemapper.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00023 #ifdef __WXMAC__
00024 #include "panoinc_WX.h"
00025 #include "panoinc.h"
00026 #endif
00027 
00028 #include "ChoosyRemapper.h"
00029 #include "ViewState.h"
00030 #include "TexCoordRemapper.h"
00031 #include "VertexCoordRemapper.h"
00032 
00033 ChoosyRemapper::ChoosyRemapper(HuginBase::Panorama *m_pano,
00034                                HuginBase::SrcPanoImage * image, VisualizationState *visualization_state)
00035   : MeshRemapper(m_pano, image, visualization_state)
00036 {
00037     selected_remapper = 0;
00038     selection = REMAP_NONE;
00039 }
00040 
00041 ChoosyRemapper::~ChoosyRemapper()
00042 {
00043     if (selected_remapper) delete selected_remapper;
00044 }
00045 
00046 void ChoosyRemapper::UpdateAndResetIndex()
00047 {
00048     MeshRemapper::UpdateAndResetIndex();
00049     // have a look at the output mode, find those where the poles cause problems
00050     // with the vetex remapper.
00051     HuginBase::PanoramaOptions *opts = visualization_state->GetOptions();
00052     bool pole = false;
00053     switch (opts->getProjection())
00054     {
00055         // the 'stretchy poles' cases.
00056         case HuginBase::PanoramaOptions::EQUIRECTANGULAR:
00057         case HuginBase::PanoramaOptions::MERCATOR:
00058         case HuginBase::PanoramaOptions::TRANSVERSE_MERCATOR:
00059         case HuginBase::PanoramaOptions::CYLINDRICAL:
00060         case HuginBase::PanoramaOptions::LAMBERT:
00061         case HuginBase::PanoramaOptions::MILLER_CYLINDRICAL:
00062 // FIXME ARCHITECTURAL is top MILLER and bottom LAMBERT. Will need different remapper for top and bottom half
00063 // currently the least distorted result is by treating it like a 'stretchy pole'
00064         case HuginBase::PanoramaOptions::ARCHITECTURAL:
00065         // the circular ones are especially important, they tend to stretch the
00066         // area over the pole covers over the entire image, it is difficult to
00067         // correct those.
00068         case HuginBase::PanoramaOptions::STEREOGRAPHIC:
00069         case HuginBase::PanoramaOptions::FULL_FRAME_FISHEYE:
00070         case HuginBase::PanoramaOptions::LAMBERT_AZIMUTHAL:
00071         case HuginBase::PanoramaOptions::HAMMER_AITOFF:
00072         case HuginBase::PanoramaOptions::ALBERS_EQUAL_AREA_CONIC:
00073         case HuginBase::PanoramaOptions::ORTHOGRAPHIC:
00074         case HuginBase::PanoramaOptions::EQUISOLID:
00075         case HuginBase::PanoramaOptions::THOBY_PROJECTION:
00076         // Add any projections where the poles maps to a big set of points here.
00077         case HuginBase::PanoramaOptions::PANINI:
00078         case HuginBase::PanoramaOptions::EQUI_PANINI:
00079                 case HuginBase::PanoramaOptions::BIPLANE:
00080                 case HuginBase::PanoramaOptions::TRIPLANE:
00081         case HuginBase::PanoramaOptions::GENERAL_PANINI:
00082             // check for pole crossing
00083         {
00084             OutputProjectionInfo *info = visualization_state->GetProjectionInfo();
00085             // get the pole in image coordinates
00086             transform.createTransform(*image,
00087                                       *(visualization_state->GetOptions()));
00088             double img_x, img_y;
00089             transform.transformImgCoord(img_x, img_y,
00090                                         info->GetNorthPoleX(),
00091                                         info->GetNorthPoleY());
00092             if (   img_y > 0.0 && img_y < height
00093                 && img_x > 0.0 && img_x < width)
00094             {
00095                 pole = true; // it covers this pole
00096             }
00097             if (opts->getProjection() ==
00098                             HuginBase::PanoramaOptions::ALBERS_EQUAL_AREA_CONIC)
00099             {
00100                 // always use a TexCoordRemapper for Alber's equal area conic.
00101                 pole = true;
00102                 // FIXME This is not sutible for panoramas containing many small
00103                 // images. To detect the poles in Alber's Equal area conic
00104                 // projetion, we need to account for their movement with
00105                 // changing parameters. Also the 180 degree seam goes at a 
00106                 // funny angle, and we need to account for this.
00107             }
00108             if (!pole)
00109             {
00110                 // check the other pole
00111                 transform.transformImgCoord(img_x, img_y,
00112                                            info->GetSouthPoleX(),
00113                                            info->GetSouthPoleY());
00114                 if (   img_y > 0.0 && img_y < height
00115                     && img_x > 0.0 && img_x < width)
00116                 {
00117                     pole = true; // it covers this pole.
00118                 }
00119             }
00120             if (pole)
00121             {
00122                 // the VertexCoordRemapper doesn't fair well with images where
00123                 // a single point on an image covers a range on the output.
00124                 // Use the TexCoordRemmaper instead.
00125                 if (selection != REMAP_TEX)
00126                 {
00127                     selection = REMAP_TEX;
00128                     if (selected_remapper)
00129                     {
00130                         delete selected_remapper;
00131                         selected_remapper = 0;
00132                     }
00133                     selected_remapper = new TexCoordRemapper(m_pano, 
00134                                                              image,
00135                                                              visualization_state);
00136                 }
00137                 break;            
00138             }
00139             // not breking to get a VertexCoordRemapper.
00140         }
00141         default:
00142             // A VertexCoordRemapper is generally the best. Create a new one
00143             // if we do not already have one.
00144             if (selection != REMAP_VERTEX)
00145             {
00146                 selection = REMAP_VERTEX;
00147                 if (selected_remapper)
00148                 {
00149                     delete selected_remapper;
00150                     selected_remapper = 0;
00151                 }
00152                 selected_remapper = new VertexCoordRemapper(m_pano, 
00153                                                             image,
00154                                                             visualization_state);
00155             }
00156             break;
00157     }
00158     // now we get the selected remapper to actually do the work.
00159     selected_remapper->UpdateAndResetIndex();
00160 }
00161 
00162 bool ChoosyRemapper::GetNextFaceCoordinates(Coords *result)
00163 {
00164     // just use the remapper created already:
00165     return selected_remapper->GetNextFaceCoordinates(result);
00166 }
00167 

Generated on 25 Oct 2014 for Hugintrunk by  doxygen 1.4.7