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

Generated on 30 Aug 2015 for Hugintrunk by  doxygen 1.4.7