wxLensDB.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00010 /*  This program is free software; you can redistribute it and/or
00011  *  modify it under the terms of the GNU General Public
00012  *  License as published by the Free Software Foundation; either
00013  *  version 2 of the License, or (at your option) any later version.
00014  *
00015  *  This software is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *  General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public
00021  *  License along with this software. If not, see
00022  *  <http://www.gnu.org/licenses/>.
00023  *
00024  */
00025 
00026 #include "panoinc_WX.h"
00027 #include "panoinc.h"
00028 #include "wxLensDB.h"
00029 #include "lensdb/LensDB.h"
00030 #include "platform.h"
00031 #include "base_wx/wxPlatform.h"
00032 #include "panodata/ImageVariableTranslate.h"
00033 #include "panodata/ImageVariableGroup.h"
00034 #include "base_wx/PanoCommand.h"
00035 #include <set>
00036 
00038 class LoadLensDBDialog : public wxDialog
00039 {
00040 public:
00042     explicit LoadLensDBDialog(wxWindow *parent);
00043     void SetLensName(std::string lensname);
00044     std::string GetLensName() const;
00045     void SetFocalLength(double focal);
00046     double GetFocalLength() const;
00047     void SetAperture(double aperture);
00048     double GetAperture() const;
00049     void SetSubjectDistance(double distance);
00050     double GetSubjectDistance() const;
00051     bool GetLoadDistortion() const;
00052     bool GetLoadVignetting() const;
00053 
00054 protected:
00056     void OnOk(wxCommandEvent & e);
00057     void OnCheckChanged(wxCommandEvent & e);
00058 
00059 private:
00060     void FillLensList();
00061     wxChoice *m_lenslist;
00062     wxCheckBox *m_loadDistortion;
00063     wxCheckBox *m_loadVignetting;
00064     double m_focal;
00065     double m_aperture;
00066     double m_distance;
00067     HuginBase::LensDB::LensList m_lensNames;
00068     DECLARE_EVENT_TABLE()
00069 };
00070 
00071 BEGIN_EVENT_TABLE(LoadLensDBDialog,wxDialog)
00072     EVT_BUTTON(wxID_OK, LoadLensDBDialog::OnOk)
00073     EVT_CHOICE(XRCID("load_lens_lenschoice"), LoadLensDBDialog::OnCheckChanged)
00074     EVT_CHECKBOX(XRCID("load_lens_distortion"), LoadLensDBDialog::OnCheckChanged)
00075     EVT_CHECKBOX(XRCID("load_lens_vignetting"), LoadLensDBDialog::OnCheckChanged)
00076 END_EVENT_TABLE()
00077 
00078 LoadLensDBDialog::LoadLensDBDialog(wxWindow *parent)
00079 {
00080     // load our children. some children might need special
00081     // initialization. this will be done later.
00082     wxXmlResource::Get()->LoadDialog(this, parent, wxT("load_lens_dlg"));
00083 
00084     //set parameters
00085     wxConfigBase * config = wxConfigBase::Get();
00086     // get display size
00087     int dx,dy;
00088     wxDisplaySize(&dx,&dy);
00089     int w = config->Read(wxT("/LoadLensDialog/width"),-1l);
00090     int h = config->Read(wxT("/LoadLensDialog/height"),-1l);
00091     if (w>0 && w<=dx && h>0 && h<=dy)
00092     {
00093         SetClientSize(w,h);
00094     }
00095     else
00096     {
00097         Fit();
00098     }
00099     //position
00100     int x = config->Read(wxT("/LoadLensDialog/positionX"),-1l);
00101     int y = config->Read(wxT("/LoadLensDialog/positionY"),-1l);
00102     if ( y >= 0 && x >= 0) 
00103     {
00104         this->Move(x, y);
00105     } 
00106     else 
00107     {
00108         this->Move(0, 44);
00109     };
00110     bool b;
00111     config->Read(wxT("/LoadLensDialog/loadDistortion"), &b, true);
00112     m_loadDistortion = XRCCTRL(*this, "load_lens_distortion", wxCheckBox);
00113     m_loadDistortion->SetValue(b);
00114     config->Read(wxT("/LoadLensDialog/loadVignetting"), &b, true);
00115     m_loadVignetting = XRCCTRL(*this, "load_lens_vignetting", wxCheckBox);
00116     m_loadVignetting->SetValue(b);
00117     m_lenslist=XRCCTRL(*this,"load_lens_lenschoice", wxChoice);
00118     FillLensList();
00119 };
00120 
00121 void LoadLensDBDialog::FillLensList()
00122 {
00123     if (HuginBase::LensDB::LensDB::GetSingleton().GetLensNames(true, true, false, m_lensNames))
00124     {
00125         wxArrayString lensnames;
00126         for (HuginBase::LensDB::LensList::const_iterator it = m_lensNames.begin(); it != m_lensNames.end(); ++it)
00127         {
00128             wxString s((*it).c_str(), wxConvLocal);
00129             wxString cam = s.AfterFirst(wxT('|'));
00130             if (!cam.empty())
00131             {
00132                 s = wxString::Format(_("Camera %s (%s)"), cam.c_str(), s.BeforeFirst(wxT('|')).c_str());
00133             };
00134             lensnames.Add(s);
00135         };
00136         m_lenslist->Append(lensnames);
00137     };
00138 };
00139 
00140 void LoadLensDBDialog::SetLensName(std::string lensname)
00141 {
00142     if (!lensname.empty() && !m_lensNames.empty())
00143     {
00144         HuginBase::LensDB::LensList::const_iterator it=std::find(m_lensNames.begin(), m_lensNames.end(), lensname);
00145         if (it != m_lensNames.end())
00146         {
00147             m_lenslist->SetSelection(it - m_lensNames.begin());
00148         };
00149     };
00150     wxCommandEvent dummy;
00151     OnCheckChanged(dummy);
00152 };
00153 
00154 std::string LoadLensDBDialog::GetLensName() const
00155 {
00156     return m_lensNames[m_lenslist->GetSelection()];
00157 };
00158 
00159 void LoadLensDBDialog::SetFocalLength(double focal)
00160 {
00161     m_focal=focal;
00162     XRCCTRL(*this,"load_lens_focallength",wxTextCtrl)->SetValue(hugin_utils::doubleTowxString(m_focal,1));
00163 };
00164 
00165 double LoadLensDBDialog::GetFocalLength() const
00166 {
00167     return m_focal;
00168 };
00169 
00170 void LoadLensDBDialog::SetAperture(double aperture)
00171 {
00172     m_aperture=aperture;
00173     XRCCTRL(*this,"load_lens_aperture",wxTextCtrl)->SetValue(hugin_utils::doubleTowxString(m_aperture,1));
00174 };
00175 
00176 double LoadLensDBDialog::GetAperture() const
00177 {
00178     return m_aperture;
00179 };
00180 
00181 void LoadLensDBDialog::SetSubjectDistance(double distance)
00182 {
00183     m_distance=distance;
00184     XRCCTRL(*this,"load_lens_distance",wxTextCtrl)->SetValue(hugin_utils::doubleTowxString(m_distance,0));
00185 };
00186 
00187 double LoadLensDBDialog::GetSubjectDistance() const
00188 {
00189     return m_distance;
00190 };
00191 
00192 bool LoadLensDBDialog::GetLoadDistortion() const
00193 {
00194     return m_loadDistortion->GetValue();
00195 };
00196 
00197 bool LoadLensDBDialog::GetLoadVignetting() const
00198 {
00199     return m_loadVignetting->GetValue();
00200 };
00201 
00202 // utility functions
00203 bool str2double(wxWindow* parent, wxString s, double & d)
00204 {
00205     if (!hugin_utils::stringToDouble(std::string(s.mb_str(wxConvLocal)), d)) 
00206     {
00207         wxMessageBox(wxString::Format(_("The input \"%s\" is not a valid number."),s.c_str()),_("Warning"), wxOK | wxICON_ERROR, parent);
00208         return false;
00209     }
00210     return true;
00211 }
00212 
00213 void LoadLensDBDialog::OnOk(wxCommandEvent & e)
00214 {
00215     if(!m_loadDistortion->GetValue() && !m_loadVignetting->GetValue())
00216     {
00217         return;
00218     };
00219     if(m_lenslist->GetSelection()==wxNOT_FOUND)
00220     {
00221         wxBell();
00222         return;
00223     };
00224     if(!str2double(this,XRCCTRL(*this,"load_lens_focallength",wxTextCtrl)->GetValue(),m_focal))
00225     {
00226         return;
00227     };
00228     if(m_loadVignetting->GetValue())
00229     {
00230         wxString val = XRCCTRL(*this, "load_lens_aperture", wxTextCtrl)->GetValue().Trim();
00231         if (val.empty())
00232         {
00233             m_aperture = 0;
00234         }
00235         else
00236         {
00237             if (!str2double(this, val, m_aperture))
00238             {
00239                 return;
00240             };
00241         };
00242         val = XRCCTRL(*this, "load_lens_distance", wxTextCtrl)->GetValue().Trim();
00243         if (val.empty())
00244         {
00245             m_distance = 0;
00246         }
00247         else
00248         {
00249             if (!str2double(this, val, m_distance))
00250             {
00251                 return;
00252             };
00253         };
00254     };
00255     //store selected options
00256     wxConfigBase * config = wxConfigBase::Get();
00257     wxSize sz = this->GetClientSize();
00258     config->Write(wxT("/LoadLensDialog/width"), sz.GetWidth());
00259     config->Write(wxT("/LoadLensDialog/height"), sz.GetHeight());
00260     wxPoint ps = this->GetPosition();
00261     config->Write(wxT("/LoadLensDialog/positionX"), ps.x);
00262     config->Write(wxT("/LoadLensDialog/positionY"), ps.y);
00263     config->Write(wxT("/LoadLensDialog/loadDistortion"),m_loadDistortion->GetValue());
00264     config->Write(wxT("/LoadLensDialog/loadVignetting"),m_loadVignetting->GetValue());
00265     config->Flush(); 
00266     e.Skip();
00267 };
00268 
00269 void LoadLensDBDialog::OnCheckChanged(wxCommandEvent & e)
00270 {
00271     int sel=m_lenslist->GetSelection();
00272     XRCCTRL(*this,"wxID_OK",wxButton)->Enable(sel!=wxNOT_FOUND && (m_loadDistortion->GetValue() || m_loadVignetting->GetValue()));
00273 };
00274 
00275 bool ApplyLensDBParameters(wxWindow * parent, HuginBase::Panorama *pano, HuginBase::UIntSet images, PanoCommand::PanoCommand*& cmd)
00276 {
00277     LoadLensDBDialog dlg(parent);
00278     const HuginBase::SrcPanoImage & img=pano->getImage(*images.begin());
00279     dlg.SetLensName(img.getDBLensName());
00280     dlg.SetFocalLength(img.getExifFocalLength());
00281     dlg.SetAperture(img.getExifAperture());
00282     dlg.SetSubjectDistance(img.getExifDistance());
00283     if(dlg.ShowModal()==wxID_OK)
00284     {
00285         HuginBase::LensDB::LensDB & lensDB=HuginBase::LensDB::LensDB::GetSingleton();
00286         const double focal=dlg.GetFocalLength();
00287         const std::string lensname = dlg.GetLensName();
00288         std::vector<PanoCommand::PanoCommand*> cmds;
00289         HuginBase::BaseSrcPanoImage::Projection proj;
00290         if(lensDB.GetProjection(lensname, proj))
00291         {
00292             cmds.push_back(new PanoCommand::ChangeImageProjectionCmd(*pano,images,proj));
00293         };
00294         vigra::Rect2D cropRect;
00295         if(lensDB.GetCrop(lensname, focal, img.getSize(), cropRect))
00296         {
00297             cmds.push_back(new PanoCommand::ChangeImageCropModeCmd(*pano, images, img.isCircularCrop() ? HuginBase::BaseSrcPanoImage::CROP_CIRCLE : HuginBase::BaseSrcPanoImage::CROP_RECTANGLE));
00298             cmds.push_back(new PanoCommand::ChangeImageCropRectCmd(*pano, images, cropRect));
00299         };
00300         //load lens distortion from database
00301         if(dlg.GetLoadDistortion())
00302         {
00303             double hfov;
00304             if (lensDB.GetFov(lensname, focal, hfov))
00305             {
00306                 // calculate FOV for given image, take different aspect ratios into account
00307                 const double newFocal = HuginBase::SrcPanoImage::calcFocalLength(img.getProjection(), hfov, img.getCropFactor(), vigra::Size2D(3000, 2000));
00308                 const double newFov = HuginBase::SrcPanoImage::calcHFOV(img.getProjection(), newFocal, img.getCropFactor(), img.getSize());
00309                 std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> linkedVariables;
00310                 linkedVariables.insert(HuginBase::ImageVariableGroup::IVE_HFOV);
00311                 cmds.push_back(new PanoCommand::ChangePartImagesLinkingCmd(*pano, images, linkedVariables,
00312                     true,HuginBase::StandardImageVariableGroups::getLensVariables()));
00313                 cmds.push_back(new PanoCommand::ChangeImageHFOVCmd(*pano, images, newFov));
00314             };
00315             std::vector<double> dist;
00316             if(lensDB.GetDistortion(lensname, focal, dist))
00317             {
00318                 if (dist.size() == 3)
00319                 {
00320                     dist.push_back(1.0 - dist[0] - dist[1] - dist[2]);
00321                     std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> linkedVariables;
00322                     linkedVariables.insert(HuginBase::ImageVariableGroup::IVE_RadialDistortion);
00323                     cmds.push_back(new PanoCommand::ChangePartImagesLinkingCmd(*pano, images, linkedVariables,
00324                         true, HuginBase::StandardImageVariableGroups::getLensVariables()));
00325                     cmds.push_back(new PanoCommand::ChangeImageRadialDistortionCmd(*pano, images, dist));
00326                 };
00327             };
00328         };
00329         if(dlg.GetLoadVignetting())
00330         {
00331             std::vector<double> vig;
00332             if (lensDB.GetVignetting(lensname, focal, dlg.GetAperture(), dlg.GetSubjectDistance(), vig))
00333             {
00334                 if (vig.size() == 4)
00335                 {
00336                     std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> linkedVariables;
00337                     linkedVariables.insert(HuginBase::ImageVariableGroup::IVE_RadialVigCorrCoeff);
00338                     cmds.push_back(new PanoCommand::ChangePartImagesLinkingCmd(*pano, images, linkedVariables,
00339                         true, HuginBase::StandardImageVariableGroups::getLensVariables()));
00340                     cmds.push_back(new PanoCommand::ChangeImageRadialVigCorrCoeffCmd(*pano, images, vig));
00341                 };
00342             };
00343         };
00344         cmd=new PanoCommand::CombinedPanoCommand(*pano, cmds);
00345         return true;
00346     };
00347     return false;
00348 };
00349 
00351 class SaveLensDBDialog : public wxDialog
00352 {
00353 public:
00355     explicit SaveLensDBDialog(wxWindow *parent);
00356     void SetCameraMaker(std::string maker);
00357     std::string GetCameraMaker() const;
00358     void SetCameraModel(std::string model);
00359     std::string GetCameraModel() const;
00360     void SetLensName(std::string lensname);
00361     std::string GetLensName() const;
00362     std::string GetLensMaker() const;
00363     void SetFocalLength(double focal);
00364     double GetFocalLength() const;
00365     void SetAperture(double aperture);
00366     double GetAperture() const;
00367     void SetSubjectDistance(double distance);
00368     double GetSubjectDistance() const;
00369     bool GetSaveDistortion() const;
00370     bool GetSaveVignetting() const;
00371     void DeactivateSaveVignetting();
00372 
00373 protected:
00375     void OnOk(wxCommandEvent & e);
00376     void OnCheckChanged(wxCommandEvent & e);
00377 
00378 private:
00379     wxCheckBox *m_saveDistortion;
00380     wxCheckBox *m_saveVignetting;
00381     double m_focal;
00382     double m_aperture;
00383     double m_distance;
00384     DECLARE_EVENT_TABLE()
00385 };
00386 
00387 BEGIN_EVENT_TABLE(SaveLensDBDialog,wxDialog)
00388     EVT_BUTTON(wxID_OK, SaveLensDBDialog::OnOk)
00389     EVT_CHECKBOX(XRCID("save_lens_distortion"), SaveLensDBDialog::OnCheckChanged)
00390     EVT_CHECKBOX(XRCID("save_lens_vignetting"), SaveLensDBDialog::OnCheckChanged)
00391 END_EVENT_TABLE()
00392 
00393 SaveLensDBDialog::SaveLensDBDialog(wxWindow *parent)
00394 {
00395     // load our children. some children might need special
00396     // initialization. this will be done later.
00397     wxXmlResource::Get()->LoadDialog(this, parent, wxT("save_lens_dlg"));
00398 
00399     //set parameters
00400     wxConfigBase * config = wxConfigBase::Get();
00401     // get display size
00402     int dx,dy;
00403     wxDisplaySize(&dx,&dy);
00404     int w = config->Read(wxT("/SaveLensDialog/width"),-1l);
00405     int h = config->Read(wxT("/SaveLensDialog/height"),-1l);
00406     if (w>0 && w<=dx && h>0 && h<=dy)
00407     {
00408         SetClientSize(w,h);
00409     }
00410     else
00411     {
00412         Fit();
00413     }
00414     //position
00415     int x = config->Read(wxT("/SaveLensDialog/positionX"),-1l);
00416     int y = config->Read(wxT("/SaveLensDialog/positionY"),-1l);
00417     if ( y >= 0 && x >= 0) 
00418     {
00419         this->Move(x, y);
00420     } 
00421     else 
00422     {
00423         this->Move(0, 44);
00424     };
00425     bool b;
00426     config->Read(wxT("/SaveLensDialog/saveDistortion"),&b,true);
00427     m_saveDistortion=XRCCTRL(*this,"save_lens_distortion",wxCheckBox);
00428     m_saveDistortion->SetValue(b);
00429     config->Read(wxT("/SaveLensDialog/saveVignetting"),&b,true);
00430     m_saveVignetting=XRCCTRL(*this,"save_lens_vignetting",wxCheckBox);
00431     m_saveVignetting->SetValue(b);
00432 };
00433 
00434 void SaveLensDBDialog::SetCameraMaker(std::string maker)
00435 {
00436     if(!maker.empty())
00437     {
00438         XRCCTRL(*this,"save_lens_camera_maker",wxTextCtrl)->SetValue(wxString(maker.c_str(), wxConvLocal));
00439     };
00440 };
00441 
00442 std::string SaveLensDBDialog::GetCameraMaker() const
00443 {
00444     return std::string(XRCCTRL(*this,"save_lens_camera_maker",wxTextCtrl)->GetValue().Trim().mb_str(wxConvLocal));
00445 };
00446 
00447 void SaveLensDBDialog::SetCameraModel(std::string model)
00448 {
00449     if(!model.empty())
00450     {
00451         XRCCTRL(*this,"save_lens_camera_model",wxTextCtrl)->SetValue(wxString(model.c_str(), wxConvLocal));
00452     };
00453 };
00454 
00455 std::string SaveLensDBDialog::GetCameraModel() const
00456 {
00457     return std::string(XRCCTRL(*this,"save_lens_camera_model",wxTextCtrl)->GetValue().Trim().mb_str(wxConvLocal));
00458 };
00459 
00460 void SaveLensDBDialog::SetLensName(std::string lensname)
00461 {
00462     if(!lensname.empty())
00463     {
00464         XRCCTRL(*this,"save_lens_name",wxTextCtrl)->SetValue(wxString(lensname.c_str(), wxConvLocal));
00465     };
00466 };
00467 
00468 std::string SaveLensDBDialog::GetLensName() const
00469 {
00470     return std::string(XRCCTRL(*this,"save_lens_name",wxTextCtrl)->GetValue().Trim().mb_str(wxConvLocal));
00471 };
00472 
00473 std::string SaveLensDBDialog::GetLensMaker() const
00474 {
00475     return std::string(XRCCTRL(*this,"save_lens_maker",wxTextCtrl)->GetValue().Trim().mb_str(wxConvLocal));
00476 };
00477 
00478 void SaveLensDBDialog::SetFocalLength(double focal)
00479 {
00480     m_focal=focal;
00481     XRCCTRL(*this,"save_lens_focallength",wxTextCtrl)->SetValue(hugin_utils::doubleTowxString(m_focal,1));
00482 };
00483 
00484 double SaveLensDBDialog::GetFocalLength() const
00485 {
00486     return m_focal;
00487 };
00488 
00489 void SaveLensDBDialog::SetAperture(double aperture)
00490 {
00491     m_aperture=aperture;
00492     XRCCTRL(*this,"save_lens_aperture",wxTextCtrl)->SetValue(hugin_utils::doubleTowxString(m_aperture,1));
00493 };
00494 
00495 double SaveLensDBDialog::GetAperture() const
00496 {
00497     return m_aperture;
00498 };
00499 
00500 void SaveLensDBDialog::SetSubjectDistance(double distance)
00501 {
00502     m_distance=distance;
00503     XRCCTRL(*this,"save_lens_distance",wxTextCtrl)->SetValue(hugin_utils::doubleTowxString(m_distance,0));
00504 };
00505 
00506 double SaveLensDBDialog::GetSubjectDistance() const
00507 {
00508     return m_distance;
00509 };
00510 
00511 bool SaveLensDBDialog::GetSaveDistortion() const
00512 {
00513     return m_saveDistortion->GetValue();
00514 };
00515 
00516 bool SaveLensDBDialog::GetSaveVignetting() const
00517 {
00518     return m_saveVignetting->GetValue();
00519 };
00520 
00521 void SaveLensDBDialog::DeactivateSaveVignetting()
00522 {
00523     m_saveVignetting->SetValue(false);
00524     m_saveVignetting->Disable();
00525 };
00526 
00527 void SaveLensDBDialog::OnOk(wxCommandEvent & e)
00528 {
00529     if(!m_saveDistortion->GetValue() && !m_saveVignetting->GetValue())
00530     {
00531         return;
00532     };
00533     if(GetLensName().empty() && (GetCameraMaker().empty() || GetCameraModel().empty()))
00534     {
00535         wxMessageBox(_("There is too little information for saving data into database. Please check your input!"),_("Warning"),wxOK|wxICON_ERROR,this);
00536         return;
00537     };
00538     if(!str2double(this,XRCCTRL(*this,"save_lens_focallength",wxTextCtrl)->GetValue(),m_focal))
00539     {
00540         return;
00541     };
00542     if(m_saveVignetting->GetValue())
00543     {
00544         wxString val = XRCCTRL(*this, "save_lens_aperture", wxTextCtrl)->GetValue().Trim();
00545         if (val.empty())
00546         {
00547             m_aperture = 0;
00548         }
00549         else
00550         {
00551             if (!str2double(this, val, m_aperture))
00552             {
00553                 return;
00554             };
00555         };
00556         val = XRCCTRL(*this, "save_lens_distance", wxTextCtrl)->GetValue().Trim();
00557         if (val.empty())
00558         {
00559             m_distance = 0;
00560         }
00561         else
00562         {
00563             if (!str2double(this, val, m_distance))
00564             {
00565                 return;
00566             };
00567         };
00568     };
00569     //store selected options
00570     wxConfigBase * config = wxConfigBase::Get();
00571     wxSize sz = this->GetClientSize();
00572     config->Write(wxT("/SaveLensDialog/width"), sz.GetWidth());
00573     config->Write(wxT("/SaveLensDialog/height"), sz.GetHeight());
00574     wxPoint ps = this->GetPosition();
00575     config->Write(wxT("/SaveLensDialog/positionX"), ps.x);
00576     config->Write(wxT("/SaveLensDialog/positionY"), ps.y);
00577     config->Write(wxT("/SaveLensDialog/saveDistortion"),m_saveDistortion->GetValue());
00578     if(m_saveVignetting->IsEnabled())
00579     {
00580         config->Write(wxT("/SaveLensDialog/saveVignetting"),m_saveVignetting->GetValue());
00581     };
00582     config->Flush(); 
00583     e.Skip();
00584 };
00585 
00586 void SaveLensDBDialog::OnCheckChanged(wxCommandEvent & e)
00587 {
00588     XRCCTRL(*this,"wxID_OK",wxButton)->Enable(m_saveDistortion->GetValue() || m_saveVignetting->GetValue());
00589 };
00590 
00591 bool SaveLensParameters(wxWindow * parent, const HuginBase::SrcPanoImage& img, bool includeVignetting)
00592 {
00593     HuginBase::LensDB::LensDB& lensDB=HuginBase::LensDB::LensDB::GetSingleton();
00594     // show dialog
00595     SaveLensDBDialog lensDlg(parent);
00596     lensDlg.SetCameraMaker(img.getExifMake());
00597     lensDlg.SetCameraModel(img.getExifModel());
00598     lensDlg.SetLensName(img.getDBLensName());
00599     lensDlg.SetFocalLength(img.getExifFocalLength());
00600     lensDlg.SetAperture(img.getExifAperture());
00601     lensDlg.SetSubjectDistance(img.getExifDistance());
00602     if (!includeVignetting)
00603     {
00604         lensDlg.DeactivateSaveVignetting();
00605     };
00606     if (lensDlg.ShowModal() != wxID_OK)
00607     {
00608         return false;
00609     };
00610     const std::string camMaker = lensDlg.GetCameraMaker();
00611     const std::string camModel = lensDlg.GetCameraModel();
00612     std::string lensname = lensDlg.GetLensName();
00613     const double focal = lensDlg.GetFocalLength();
00614     if (lensname.empty())
00615     {
00616         //empty lensname, assuming it is a compact camera
00617         lensname = camMaker + "|" + camModel;
00618     };
00619     // unknown crop factor, remember it
00620     if (img.getExifCropFactor() < 0.1 && !camMaker.empty() && !camModel.empty())
00621     {
00622         lensDB.SaveCameraCrop(camMaker, camModel, img.getCropFactor());
00623     };
00624     if (lensDlg.GetSaveDistortion())
00625     {
00626         const double newFocallength = HuginBase::SrcPanoImage::calcFocalLength(img.getProjection(), img.getHFOV(), img.getCropFactor(), img.getSize());
00627         const double newHFOV = HuginBase::SrcPanoImage::calcHFOV(img.getProjection(), newFocallength, img.getCropFactor(), vigra::Size2D(3000, 2000));
00628         // save information with higher weight
00629         if (!lensDB.SaveLensFov(lensname, lensDlg.GetFocalLength(), newHFOV, 75))
00630         {
00631             wxMessageBox(_("Could not save information into database."), _("Error"), wxOK | wxICON_ERROR, parent);
00632             return false;
00633         };
00634         if (!lensDB.SaveDistortion(lensname, focal, img.getRadialDistortion(), 75))
00635         {
00636             wxMessageBox(_("Could not save information into database."), _("Error"), wxOK | wxICON_ERROR, parent);
00637             return false;
00638         };
00639     };
00640     if(lensDlg.GetSaveVignetting())
00641     {
00642         if (!lensDB.SaveVignetting(lensname, focal, lensDlg.GetAperture(), lensDlg.GetSubjectDistance(), img.getRadialVigCorrCoeff(), 75))
00643         {
00644             wxMessageBox(_("Could not save information into database."), _("Error"), wxOK | wxICON_ERROR, parent);
00645             return false;
00646         };
00647     };
00648     return true;
00649 };
00650 

Generated on 24 Jun 2016 for Hugintrunk by  doxygen 1.4.7