ImagesPanel.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00028 #include "hugin_config.h"
00029 #include "panoinc_WX.h"
00030 #include "panoinc.h"
00031 #include <time.h>
00032 
00033 #include "base_wx/platform.h"
00034 #include "base_wx/wxPlatform.h"
00035 #include "base_wx/wxcms.h"
00036 #include <vector>
00037 #include <map>
00038 #include <functional>    // std::bind
00039 
00040 #include "hugin/ImagesPanel.h"
00041 #include "base_wx/CommandHistory.h"
00042 #include "hugin/TextKillFocusHandler.h"
00043 #include "hugin/CPEditorPanel.h"
00044 #include "hugin/ImagesList.h"
00045 #include "hugin/MainFrame.h"
00046 #include "hugin/huginApp.h"
00047 #include "icpfind/AutoCtrlPointCreator.h"
00048 #include "hugin/config_defaults.h"
00049 #include "base_wx/PTWXDlg.h"
00050 #include "base_wx/LensTools.h"
00051 #include "hugin/ImagesTree.h"
00052 #include "panodata/OptimizerSwitches.h"
00053 #include "base_wx/PanoCommand.h"
00054 
00055 #include <panodata/StandardImageVariableGroups.h>
00056 
00057 BEGIN_EVENT_TABLE(ImagesPanel, wxPanel)
00058     EVT_TREE_SEL_CHANGED(XRCID("images_tree_ctrl"), ImagesPanel::OnSelectionChanged )
00059     EVT_CHOICE     ( XRCID("images_lens_type"), ImagesPanel::OnLensTypeChanged)
00060     EVT_CHOICE     ( XRCID("images_group_mode"), ImagesPanel::OnGroupModeChanged)
00061     EVT_RADIOBOX   ( XRCID("images_column_radiobox"), ImagesPanel::OnDisplayModeChanged)
00062     EVT_CHOICE     ( XRCID("images_optimize_mode"), ImagesPanel::OnOptimizerSwitchChanged)
00063     EVT_CHOICE     ( XRCID("images_photo_optimize_mode"), ImagesPanel::OnPhotometricOptimizerSwitchChanged)
00064     EVT_TEXT_ENTER ( XRCID("images_focal_length"), ImagesPanel::OnFocalLengthChanged)
00065     EVT_TEXT_ENTER ( XRCID("images_crop_factor"),  ImagesPanel::OnCropFactorChanged)
00066     EVT_TEXT_ENTER ( XRCID("images_overlap"), ImagesPanel::OnMinimumOverlapChanged)
00067     EVT_TEXT_ENTER ( XRCID("images_maxev"), ImagesPanel::OnMaxEvDiffChanged)
00068     EVT_BUTTON     ( XRCID("images_feature_matching"), ImagesPanel::CPGenerate)
00069     EVT_BUTTON     ( XRCID("images_optimize"), ImagesPanel::OnOptimizeButton)
00070     EVT_BUTTON     ( XRCID("images_photo_optimize"), ImagesPanel::OnPhotometricOptimizeButton)
00071 END_EVENT_TABLE()
00072 
00073 ImagesPanel::ImagesPanel()
00074 {
00075     m_pano = 0;
00076     m_guiLevel=GUI_SIMPLE;
00077 }
00078 
00079 bool ImagesPanel::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
00080                       long style, const wxString& name)
00081 {
00082     if (! wxPanel::Create(parent, id, pos, size, style, name)) {
00083         return false;
00084     }
00085 
00086     wxXmlResource::Get()->LoadPanel(this, wxT("images_panel"));
00087     wxPanel * panel = XRCCTRL(*this, "images_panel", wxPanel);
00088     wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
00089     topsizer->Add(panel, 1, wxEXPAND, 0);
00090     SetSizer(topsizer);
00091 
00092     m_images_tree = XRCCTRL(*this, "images_tree_ctrl", ImagesTreeCtrl);
00093     DEBUG_ASSERT(m_images_tree);
00094 
00095     m_showImgNr = INT_MAX;
00096 
00097     m_matchingButton = XRCCTRL(*this, "images_feature_matching", wxButton);
00098     DEBUG_ASSERT(m_matchingButton);
00099 
00100     m_CPDetectorChoice = XRCCTRL(*this, "cpdetector_settings", wxChoice);
00101 
00102     // Image Preview
00103     m_smallImgCtrl = XRCCTRL(*this, "images_selected_image", wxStaticBitmap);
00104     DEBUG_ASSERT(m_smallImgCtrl);
00105 
00106     // empty bitmap with size (0,0) is not valid for wxStaticBitmap
00107     // so we create a bitmap with the background color of the static bitmap control
00108     wxImage image(1, 1, true);
00109     const wxColour imageBackgroundColor = m_smallImgCtrl->GetBackgroundColour();
00110     image.SetRGB(0, 0, imageBackgroundColor.Red(), imageBackgroundColor.Green(), imageBackgroundColor.Blue());
00111     m_empty = wxBitmap(image);
00112     m_smallImgCtrl->SetBitmap(m_empty);
00113 
00114     m_lenstype = XRCCTRL(*this, "images_lens_type", wxChoice);
00115     DEBUG_ASSERT(m_lenstype);
00116     FillLensProjectionList(m_lenstype);
00117     m_lenstype->SetSelection(0);
00118 
00119     m_focallength = XRCCTRL(*this, "images_focal_length", wxTextCtrl);
00120     DEBUG_ASSERT(m_focallength);
00121     m_focallength->PushEventHandler(new TextKillFocusHandler(this));
00122 
00123     m_cropfactor = XRCCTRL(*this, "images_crop_factor", wxTextCtrl);
00124     DEBUG_ASSERT(m_cropfactor);
00125     m_cropfactor->PushEventHandler(new TextKillFocusHandler(this));
00126 
00127     m_overlap = XRCCTRL(*this, "images_overlap", wxTextCtrl);
00128     DEBUG_ASSERT(m_overlap);
00129     m_overlap->PushEventHandler(new TextKillFocusHandler(this));
00130 
00131     m_maxEv = XRCCTRL(*this, "images_maxev", wxTextCtrl);
00132     DEBUG_ASSERT(m_maxEv);
00133     m_maxEv->PushEventHandler(new TextKillFocusHandler(this));
00134 
00135     FillGroupChoice();
00136 
00137     wxTreeEvent ev;
00138     OnSelectionChanged(ev);
00139     DEBUG_TRACE("end");
00140 
00141     m_optChoice = XRCCTRL(*this, "images_optimize_mode", wxChoice);
00142     DEBUG_ASSERT(m_optChoice);
00143 
00144     m_optPhotoChoice = XRCCTRL(*this, "images_photo_optimize_mode", wxChoice);
00145     DEBUG_ASSERT(m_optPhotoChoice);
00146 
00147     FillOptimizerChoice();
00148 
00149     wxConfigBase* config=wxConfigBase::Get();
00150     m_degDigits = config->Read(wxT("/General/DegreeFractionalDigitsEdit"),3);
00151     //read autopano generator settings
00152     cpdetector_config.Read(config,huginApp::Get()->GetDataPath()+wxT("default.setting"));
00153     //write current autopano generator settings
00154     cpdetector_config.Write(config);
00155     config->Flush();
00156     cpdetector_config.FillControl(m_CPDetectorChoice,true);
00157     Layout();
00158 
00159     return true;
00160 }
00161 
00162 void ImagesPanel::Init(HuginBase::Panorama * panorama)
00163 {
00164     m_pano = panorama;
00165     m_images_tree->Init(m_pano);
00166     // observe the panorama
00167     m_pano->addObserver(this);
00168 }
00169 
00170 void DeleteClientData(wxChoice* cb)
00171 {
00172     if(cb->HasClientUntypedData())
00173     {
00174         for(size_t i = 0; i < cb->GetCount(); i++)
00175         {
00176             delete static_cast<int*>(cb->GetClientData(i));
00177         };
00178     };
00179 };
00180 
00181 ImagesPanel::~ImagesPanel()
00182 {
00183     DEBUG_TRACE("dtor");
00184     m_focallength->PopEventHandler(true);
00185     m_cropfactor->PopEventHandler(true);
00186     m_overlap->PopEventHandler(true);
00187     m_maxEv->PopEventHandler(true);
00188     m_pano->removeObserver(this);
00189     wxChoice* group=XRCCTRL(*this,"images_group_mode", wxChoice);
00190     DeleteClientData(group);
00191     DeleteClientData(m_optChoice);
00192     DeleteClientData(m_optPhotoChoice);
00193     DEBUG_TRACE("dtor end");
00194 }
00195 
00196 // We need to override the default handling of size events because the
00197 // sizers set the virtual size but not the actual size. We reverse
00198 // the standard handling and fit the child to the parent rather than
00199 // fitting the parent around the child
00200 
00201 void ImagesPanel::OnSize( wxSizeEvent & e )
00202 {
00203     int winWidth, winHeight;
00204     GetClientSize(&winWidth, &winHeight);
00205     DEBUG_INFO( "image panel: " << winWidth <<"x"<< winHeight );
00206     UpdatePreviewImage();
00207 
00208     e.Skip();
00209 }
00210 
00211 void ImagesPanel::panoramaChanged(HuginBase::Panorama & pano)
00212 {
00213     //update optimizer choice selection
00214     int optSwitch=m_pano->getOptimizerSwitch();
00215     int found=wxNOT_FOUND;
00216     for(size_t i=0;i<m_optChoice->GetCount();i++)
00217     {
00218         if(optSwitch==*static_cast<int*>(m_optChoice->GetClientData(i)))
00219         {
00220             found=i;
00221             break;
00222         };
00223     };
00224     if(found==wxNOT_FOUND)
00225     {
00226         PanoCommand::GlobalCmdHist::getInstance().addCommand(
00227             new PanoCommand::UpdateOptimizerSwitchCmd(*m_pano, 0)
00228         );
00229     }
00230     else
00231     {
00232         m_optChoice->SetSelection(found);
00233     };
00234 
00235     //update photometric optimizer choice selection
00236     optSwitch=m_pano->getPhotometricOptimizerSwitch();
00237     found=wxNOT_FOUND;
00238     for(size_t i=0;i<m_optPhotoChoice->GetCount();i++)
00239     {
00240         if(optSwitch==*static_cast<int*>(m_optPhotoChoice->GetClientData(i)))
00241         {
00242             found=i;
00243             break;
00244         };
00245     };
00246     if(found==wxNOT_FOUND)
00247     {
00248         PanoCommand::GlobalCmdHist::getInstance().addCommand(
00249             new PanoCommand::UpdatePhotometricOptimizerSwitchCmd(*m_pano, 0)
00250         );
00251     }
00252     else
00253     {
00254         m_optPhotoChoice->SetSelection(found);
00255     };
00256     const HuginBase::PanoramaOptions opts = m_pano->getOptions();
00257     m_overlap->ChangeValue(hugin_utils::doubleTowxString(opts.outputStacksMinOverlap,3));
00258     m_maxEv->ChangeValue(hugin_utils::doubleTowxString(opts.outputLayersExposureDiff,2));
00259 }
00260 
00261 void ImagesPanel::panoramaImagesChanged(HuginBase::Panorama &pano, const HuginBase::UIntSet & _imgNr)
00262 {
00263     DEBUG_TRACE("");
00264 
00265     // update text field if selected
00266     const HuginBase::UIntSet & selected = m_images_tree->GetSelectedImages();
00267     DEBUG_DEBUG("nr of sel Images: " << selected.size());
00268     if (pano.getNrOfImages() == 0)
00269     {
00270         DisableImageCtrls();
00271         m_matchingButton->Disable();
00272     }
00273     else
00274     {
00275         m_matchingButton->Enable();
00276         wxTreeEvent ev;
00277         OnSelectionChanged(ev);
00278     };
00279     //enable/disable optimize buttons
00280     XRCCTRL(*this, "images_optimize", wxButton)->Enable(pano.getNrOfImages()>0);
00281     XRCCTRL(*this, "images_photo_optimize", wxButton)->Enable(pano.getNrOfImages()>1);
00282 }
00283 
00284 // #####  Here start the eventhandlers  #####
00285 
00287 void ImagesPanel::CPGenerate(wxCommandEvent & e)
00288 {
00289     HuginBase::UIntSet selImg = m_images_tree->GetSelectedImages();
00290     //if only one image is selected, run detector on all images, except for linefind
00291     wxString progName = cpdetector_config.settings[m_CPDetectorChoice->GetSelection()].GetProg().Lower();
00292     if ((selImg.size() == 0) || (selImg.size() == 1 && progName.Find(wxT("linefind")) == wxNOT_FOUND))
00293     {
00294         // add all images.
00295         selImg.clear();
00296         fill_set(selImg, 0, m_pano->getNrOfImages() - 1);
00297     }
00298 
00299     if (selImg.empty())
00300     {
00301         return;
00302     }
00303     RunCPGenerator(cpdetector_config.settings[m_CPDetectorChoice->GetSelection()], selImg);
00304 };
00305 
00306 void ImagesPanel::RunCPGenerator(const HuginBase::UIntSet& img)
00307 {
00308     RunCPGenerator(cpdetector_config.settings[m_CPDetectorChoice->GetSelection()], img);
00309 }
00310 
00311 void ImagesPanel::RunCPGenerator(CPDetectorSetting &setting, const HuginBase::UIntSet& img)
00312 {
00313     wxConfigBase* config=wxConfigBase::Get();
00314     long nFeatures = HUGIN_ASS_NCONTROLPOINTS;
00315     if(wxGetKeyState(WXK_COMMAND))
00316     {
00317         nFeatures = config->Read(wxT("/MainFrame/nControlPoints"), HUGIN_ASS_NCONTROLPOINTS);
00318         nFeatures = wxGetNumberFromUser(
00319                             _("Enter maximal number of control points per image pair"),
00320                             _("Points per Overlap"),
00321                             _("Control point detector option"), 
00322                             nFeatures, 1, 10000
00323                                  );
00324         if(nFeatures<1)
00325         {
00326             return;
00327         };
00328         config->Write(wxT("/MainFrame/nControlPoints"), nFeatures);
00329     }
00330     else
00331     {
00332         nFeatures = config->Read(wxT("/Assistant/nControlPoints"), HUGIN_ASS_NCONTROLPOINTS);
00333     };
00334 
00335     AutoCtrlPointCreator matcher;
00336     HuginBase::CPVector cps = matcher.automatch(setting, *m_pano, img, nFeatures, this);
00337     wxString msg;
00338     wxMessageBox(wxString::Format(_("Added %lu control points"), (unsigned long) cps.size()), _("Control point detector result"),wxOK|wxICON_INFORMATION,this);
00339     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00340             new PanoCommand::AddCtrlPointsCmd(*m_pano, cps)
00341                                            );
00342 
00343 };
00344 
00345 const wxString ImagesPanel::GetSelectedCPGenerator()
00346 {
00347     return cpdetector_config.settings[m_CPDetectorChoice->GetSelection()].GetCPDetectorDesc();
00348 };
00349 
00350 void ImagesPanel::OnSelectionChanged(wxTreeEvent & e)
00351 {
00352     const HuginBase::UIntSet & sel = m_images_tree->GetSelectedImages();
00353     DEBUG_DEBUG("selected Images: " << sel.size());
00354     if (sel.size() == 0)
00355     {
00356         // nothing to edit
00357         DisableImageCtrls();
00358     }
00359     else
00360     {
00361         // enable edit
00362         EnableImageCtrls();
00363         const HuginBase::SrcPanoImage& img = m_pano->getImage(*sel.begin());
00364         bool identical_projection=true;
00365         HuginBase::SrcPanoImage::Projection proj = img.getProjection();
00366         double focallength = HuginBase::SrcPanoImage::calcFocalLength(img.getProjection(), img.getHFOV(),
00367                 img.getCropFactor(),img.getSize());;
00368         double cropFactor=img.getCropFactor();
00369         for (HuginBase::UIntSet::const_iterator it = sel.begin(); it != sel.end(); ++it)
00370         {
00371             const HuginBase::SrcPanoImage& img2 = m_pano->getImage(*it);
00372             if(proj!=img2.getProjection())
00373             {
00374                 identical_projection=false;
00375             };
00376             double focallength2 = HuginBase::SrcPanoImage::calcFocalLength(img2.getProjection(), img2.getHFOV(),
00377                 img2.getCropFactor(),img2.getSize());
00378             if(focallength>0 && fabs(focallength-focallength2)>0.05)
00379             {
00380                 focallength=-1;
00381             };
00382             if(fabs(cropFactor-img2.getCropFactor())>0.1)
00383             {
00384                 cropFactor=-1;
00385             };
00386         };
00387 
00388         if(identical_projection)
00389         {
00390             SelectListValue(m_lenstype, proj);
00391         }
00392         else
00393         {
00394             m_lenstype->Select(wxNOT_FOUND);
00395         };
00396         if(focallength>0)
00397         {
00398             // use ChangeValue explicit, SetValue would create EVT_TEXT event which collides with our TextKillFocusHandler
00399             m_focallength->ChangeValue(hugin_utils::doubleTowxString(focallength,m_degDigits));
00400         }
00401         else
00402         {
00403             m_focallength->Clear();
00404         };
00405         if(cropFactor>0)
00406         {
00407             m_cropfactor->ChangeValue(hugin_utils::doubleTowxString(cropFactor,m_degDigits));
00408         }
00409         else
00410         {
00411             m_cropfactor->Clear();
00412         };
00413 
00414         if (sel.size() == 1)
00415         {
00416             ShowImage(*(sel.begin()));
00417         }
00418         else
00419         {
00420             m_smallImgCtrl->SetBitmap(m_empty);
00421             m_smallImgCtrl->GetParent()->Layout();
00422             m_smallImgCtrl->Refresh();
00423         };
00424     }
00425 }
00426 
00427 void ImagesPanel::DisableImageCtrls()
00428 {
00429     // disable controls
00430     m_lenstype->Disable();
00431     m_focallength->Disable();
00432     m_cropfactor->Disable();
00433     m_smallImgCtrl->SetBitmap(m_empty);
00434     m_smallImgCtrl->GetParent()->Layout();
00435     m_smallImgCtrl->Refresh();
00436 }
00437 
00438 void ImagesPanel::EnableImageCtrls()
00439 {
00440     // enable control if not already enabled
00441     m_lenstype->Enable();
00442     m_focallength->Enable();
00443     m_cropfactor->Enable();
00444 }
00445 
00446 void ImagesPanel::ShowImage(unsigned int imgNr)
00447 {
00448     m_showImgNr = imgNr;
00449     UpdatePreviewImage();
00450 }
00451 
00452 void ImagesPanel::UpdatePreviewImage()
00453 {
00454     if (m_showImgNr < 0 || m_showImgNr >= m_pano->getNrOfImages())
00455     {
00456         return;
00457     }
00458     ImageCache::EntryPtr cacheEntry = ImageCache::getInstance().getSmallImageIfAvailable(
00459             m_pano->getImage(m_showImgNr).getFilename());
00460     if (!cacheEntry.get())
00461     {
00462         // image currently isn't loaded.
00463         // Instead of loading and displaying the image now, request it for
00464         // later. Then the user can switch between images in the list quickly,
00465         // even when not all images previews are in the cache.
00466         thumbnail_request = ImageCache::getInstance().requestAsyncSmallImage(
00467                 m_pano->getImage(m_showImgNr).getFilename());
00468         // When the image is ready, try this function again.
00469         thumbnail_request->ready.push_back(
00470             std::bind(&ImagesPanel::UpdatePreviewImage, this)
00471             );
00472     } else {
00473         // forget any request now the image has loaded.
00474         thumbnail_request = ImageCache::RequestPtr();
00475         wxImage img = imageCacheEntry2wxImage(cacheEntry); 
00476 
00477         double iRatio = img.GetWidth() / (double) img.GetHeight();
00478 
00479         wxSize sz;
00480         // estimate image size
00481         
00482         sz = m_smallImgCtrl->GetContainingSizer()->GetSize();
00483         double sRatio = (double)sz.GetWidth() / sz.GetHeight();
00484         if (iRatio > sRatio) {
00485             // image is wider than screen, display landscape
00486             sz.SetHeight((int) (sz.GetWidth() / iRatio));
00487         } else {
00488             // portrait
00489             sz.SetWidth((int) (sz.GetHeight() * iRatio));
00490         }
00491         // Make sure the size is positive:
00492         // on a small window, m_smallImgCtrl can have 0 width.
00493         sz.IncTo(wxSize(1,1));
00494         wxImage scaled = img.Scale(sz.GetWidth(),sz.GetHeight());
00495         // now apply color profile
00496         if (!cacheEntry->iccProfile->empty() || huginApp::Get()->HasMonitorProfile())
00497         {
00498             HuginBase::Color::CorrectImage(scaled, *(cacheEntry->iccProfile), huginApp::Get()->GetMonitorProfile());
00499         };
00500         m_smallImgCtrl->SetBitmap(wxBitmap(scaled));
00501         m_smallImgCtrl->GetParent()->Layout();
00502         m_smallImgCtrl->Refresh();
00503     }
00504 }
00505 
00506 void ImagesPanel::ReloadCPDetectorSettings()
00507 {
00508     cpdetector_config.Read(); 
00509     cpdetector_config.FillControl(m_CPDetectorChoice,true);
00510     m_CPDetectorChoice->InvalidateBestSize();
00511     m_CPDetectorChoice->GetParent()->Layout();
00512     Refresh();
00513 };
00514 
00515 void ImagesPanel::OnLensTypeChanged (wxCommandEvent & e)
00516 {
00517     size_t var = GetSelectedValue(m_lenstype);
00518     HuginBase::UIntSet images = m_images_tree->GetSelectedImages();
00519     if(images.size()>0)
00520     {
00521         const HuginBase::SrcPanoImage & img = m_pano->getImage(*(images.begin()));
00522         double focal_length = HuginBase::SrcPanoImage::calcFocalLength(img.getProjection(), img.getHFOV(), img.getCropFactor(), img.getSize());
00523         std::vector<PanoCommand::PanoCommand*> commands;
00524         commands.push_back(new PanoCommand::ChangeImageProjectionCmd(*m_pano, images,(HuginBase::SrcPanoImage::Projection) var));
00525         commands.push_back(new PanoCommand::UpdateFocalLengthCmd(*m_pano, images, focal_length));
00526         PanoCommand::GlobalCmdHist::getInstance().addCommand(
00527             new PanoCommand::CombinedPanoCommand(*m_pano, commands)
00528         );
00529     };
00530 };
00531 
00532 void ImagesPanel::OnFocalLengthChanged(wxCommandEvent & e)
00533 {
00534     if (m_pano->getNrOfImages() == 0)
00535     {
00536         return;
00537     };
00538 
00539     wxString text = m_focallength->GetValue();
00540     if(text.IsEmpty())
00541     {
00542         return;
00543     };
00544     double val;
00545     if (!hugin_utils::str2double(text, val))
00546     {
00547         return;
00548     }
00549     //no negative values, no zero input please
00550     if (val<0.1)
00551     {
00552         wxBell();
00553         return;
00554     };
00555     
00556     HuginBase::UIntSet images = m_images_tree->GetSelectedImages();
00557     const HuginBase::SrcPanoImage& srcImg = m_pano->getImage(*(images.begin()));
00558     if (srcImg.getProjection() == HuginBase::SrcPanoImage::FISHEYE_ORTHOGRAPHIC)
00559     {
00560         double hfov=srcImg.calcHFOV(srcImg.getProjection(), val, srcImg.getCropFactor(), srcImg.getSize());
00561         if(hfov>190)
00562         {
00563             if(wxMessageBox(
00564                 wxString::Format(_("You have given a field of view of %.2f degrees.\n But the orthographic projection is limited to a field of view of 180 degress.\nDo you want still use that high value?"), hfov),
00565 #ifdef __WXMSW__
00566                 _("Hugin"),
00567 #else
00568                 wxT(""),
00569 #endif
00570                 wxICON_EXCLAMATION | wxYES_NO)==wxNO)
00571             {
00572                 wxTreeEvent dummy;
00573                 OnSelectionChanged(dummy);
00574                 return;
00575             };
00576         };
00577     };
00578     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00579         new PanoCommand::UpdateFocalLengthCmd(*m_pano, images, val)
00580     );
00581 }
00582 
00583 void ImagesPanel::OnCropFactorChanged(wxCommandEvent & e)
00584 {
00585     if (m_pano->getNrOfImages() == 0)
00586     {
00587         return;
00588     };
00589 
00590     wxString text = m_cropfactor->GetValue();
00591     if(text.IsEmpty())
00592     {
00593         return;
00594     };
00595     double val;
00596     if (!hugin_utils::str2double(text, val))
00597     {
00598         return;
00599     }
00600     //no negative values, no zero input please
00601     if (val<0.1)
00602     {
00603         wxBell();
00604         return;
00605     };
00606 
00607     HuginBase::UIntSet images = m_images_tree->GetSelectedImages();
00608     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00609         new PanoCommand::UpdateCropFactorCmd(*m_pano,images,val)
00610     );
00611 }
00612 
00613 void ImagesPanel::OnMinimumOverlapChanged(wxCommandEvent & e)
00614 {
00615     wxString text = m_overlap->GetValue();
00616     if(text.IsEmpty())
00617     {
00618         return;
00619     };
00620     double val;
00621     if (!hugin_utils::str2double(text, val))
00622     {
00623         return;
00624     }
00625     if(fabs(val)<0.001 || val>1)
00626     {
00627         wxMessageBox(_("The minimum overlap has to be greater than 0 and smaller than 1."),
00628 #ifdef _WIN32
00629             _("Hugin"),
00630 #else
00631             wxT(""),
00632 #endif
00633             wxOK | wxICON_INFORMATION, this);
00634         return;
00635     };
00636     if (val < 0)
00637     {
00638         val = -1;
00639     };
00640     HuginBase::PanoramaOptions opt = m_pano->getOptions();
00641     opt.outputStacksMinOverlap=val;
00642     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00643         new PanoCommand::SetPanoOptionsCmd(*m_pano,opt)
00644     );
00645 };
00646 
00647 void ImagesPanel::OnMaxEvDiffChanged(wxCommandEvent& e)
00648 {
00649     wxString text = m_maxEv->GetValue();
00650     if(text.IsEmpty())
00651     {
00652         return;
00653     };
00654     double val;
00655     if (!hugin_utils::str2double(text, val))
00656     {
00657         return;
00658     }
00659     if(val<0)
00660     {
00661         wxMessageBox(_("The maximum Ev difference has to be greater than 0."),
00662 #ifdef _WIN32
00663             _("Hugin"),
00664 #else
00665             wxT(""),
00666 #endif
00667             wxOK | wxICON_INFORMATION, this);
00668         return;
00669     };
00670     HuginBase::PanoramaOptions opt = m_pano->getOptions();
00671     opt.outputLayersExposureDiff=val;
00672     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00673         new PanoCommand::SetPanoOptionsCmd(*m_pano,opt)
00674     );
00675 };
00676 
00677 void ImagesPanel::FillGroupChoice()
00678 {
00679     wxChoice* group=XRCCTRL(*this,"images_group_mode", wxChoice);
00680     size_t sel=group->GetSelection();
00681     DeleteClientData(group);
00682     group->Clear();
00683     int* i=new int;
00684     *i=ImagesTreeCtrl::GROUP_NONE;
00685     group->Append(_("None"), i);
00686     i=new int;
00687     *i=ImagesTreeCtrl::GROUP_LENS;
00688     group->Append(_("Lens"), i);
00689     if(m_guiLevel>GUI_SIMPLE)
00690     {
00691         i=new int;
00692         *i=ImagesTreeCtrl::GROUP_STACK;
00693         group->Append(_("Stacks"), i);
00694         if(m_guiLevel==GUI_EXPERT)
00695         {
00696             i=new int;
00697             *i=ImagesTreeCtrl::GROUP_OUTPUTLAYERS;
00698             group->Append(_("Output layers"), i);
00699             i=new int;
00700             *i=ImagesTreeCtrl::GROUP_OUTPUTSTACK;
00701             group->Append(_("Output stacks"), i);
00702         };
00703     };
00704     if((m_guiLevel==GUI_ADVANCED && sel>2) || (m_guiLevel==GUI_SIMPLE && sel>1))
00705     {
00706         sel=0;
00707     };
00708     group->SetSelection(sel);
00709     wxCommandEvent dummy;
00710     OnGroupModeChanged(dummy);
00711 };
00712 
00713 void ImagesPanel::FillOptimizerChoice()
00714 {
00715     DeleteClientData(m_optChoice);
00716     m_optChoice->Clear();
00717     int* i=new int;
00718     *i=HuginBase::OPT_PAIR;
00719     m_optChoice->Append(_("Positions (incremental, starting from anchor)"), i);
00720     i=new int;
00721     *i=HuginBase::OPT_POSITION;
00722     m_optChoice->Append(_("Positions (y,p,r)"), i);
00723     i=new int;
00724     *i=(HuginBase::OPT_POSITION | HuginBase::OPT_VIEW);
00725     m_optChoice->Append(_("Positions and View (y,p,r,v)"), i);
00726     i=new int;
00727     *i=(HuginBase::OPT_POSITION | HuginBase::OPT_BARREL);
00728     m_optChoice->Append(_("Positions and Barrel Distortion (y,p,r,b)"), i);
00729     i=new int;
00730     *i=(HuginBase::OPT_POSITION | HuginBase::OPT_VIEW | HuginBase::OPT_BARREL);
00731     m_optChoice->Append(_("Positions, View and Barrel (y,p,r,v,b)"), i);
00732     i=new int;
00733     *i=HuginBase::OPT_ALL;
00734     if(m_guiLevel==GUI_EXPERT)
00735     {
00736         m_optChoice->Append(_("Everything without translation"), i);
00737     }
00738     else
00739     {
00740         m_optChoice->Append(_("Everything"), i);
00741     };
00742     if(m_guiLevel==GUI_EXPERT)
00743     {
00744         i=new int;
00745         *i=(HuginBase::OPT_POSITION | HuginBase::OPT_TRANSLATION);
00746         m_optChoice->Append(_("Positions and Translation (y,p,r,x,y,z)"), i);
00747         i=new int;
00748         *i=(HuginBase::OPT_POSITION | HuginBase::OPT_TRANSLATION | HuginBase::OPT_VIEW);
00749         m_optChoice->Append(_("Positions, Translation and View (y,p,r,x,y,z,v)"), i);
00750         i=new int;
00751         *i=(HuginBase::OPT_POSITION | HuginBase::OPT_TRANSLATION | HuginBase::OPT_BARREL);
00752         m_optChoice->Append(_("Positions, Translation and Barrel (y,p,r,x,y,z,b)"), i);
00753         i=new int;
00754         *i=(HuginBase::OPT_POSITION | HuginBase::OPT_TRANSLATION | HuginBase::OPT_VIEW | HuginBase::OPT_BARREL);
00755         m_optChoice->Append(_("Positions, Translation, View and Barrel (y,p,r,x,y,z,v,b)"), i);
00756     };
00757     i=new int;
00758     *i=0;
00759     m_optChoice->Append(_("Custom parameters"), i);
00760 
00761     DeleteClientData(m_optPhotoChoice);
00762     m_optPhotoChoice->Clear();
00763     i=new int;
00764     *i=(HuginBase::OPT_EXPOSURE | HuginBase::OPT_VIGNETTING | HuginBase::OPT_RESPONSE);
00765     m_optPhotoChoice->Append(_("Low dynamic range"), i);
00766     i=new int;
00767     *i=(HuginBase::OPT_EXPOSURE | HuginBase::OPT_VIGNETTING | HuginBase::OPT_RESPONSE | HuginBase::OPT_WHITEBALANCE);
00768     m_optPhotoChoice->Append(_("Low dynamic range, variable white balance"), i);
00769     if(m_guiLevel>GUI_SIMPLE)
00770     {
00771         i=new int;
00772         *i=(HuginBase::OPT_VIGNETTING | HuginBase::OPT_RESPONSE);
00773         m_optPhotoChoice->Append(_("High dynamic range, fixed exposure"), i);
00774         i=new int;
00775         *i=(HuginBase::OPT_WHITEBALANCE | HuginBase::OPT_VIGNETTING | HuginBase::OPT_RESPONSE);
00776         m_optPhotoChoice->Append(_("High dynamic range, variable white balance, fixed exposure"), i);
00777     };
00778     i=new int;
00779     *i=0;
00780     m_optPhotoChoice->Append(_("Custom parameters"), i);
00781     m_optChoice->GetParent()->Layout();
00782     Refresh();
00783 };
00784 
00785 wxString ImagesPanel::GetCurrentOptimizerString()
00786 {
00787     return m_optChoice->GetString(m_optChoice->GetSelection());
00788 };
00789 
00790 void ImagesPanel::OnGroupModeChanged(wxCommandEvent & e)
00791 {
00792     wxChoice* group=XRCCTRL(*this,"images_group_mode", wxChoice);
00793     ImagesTreeCtrl::GroupMode mode=ImagesTreeCtrl::GroupMode(*static_cast<int*>(group->GetClientData(group->GetSelection())));
00794     m_images_tree->SetGroupMode(mode);
00795     XRCCTRL(*this, "images_text_overlap", wxStaticText)->Show(mode==ImagesTreeCtrl::GROUP_OUTPUTSTACK);
00796     m_overlap->Show(mode==ImagesTreeCtrl::GROUP_OUTPUTSTACK);
00797     m_overlap->Enable(mode==ImagesTreeCtrl::GROUP_OUTPUTSTACK);
00798     XRCCTRL(*this, "images_text_maxev", wxStaticText)->Show(mode==ImagesTreeCtrl::GROUP_OUTPUTLAYERS);
00799     m_maxEv->Show(mode==ImagesTreeCtrl::GROUP_OUTPUTLAYERS);
00800     m_maxEv->Enable(mode==ImagesTreeCtrl::GROUP_OUTPUTLAYERS);
00801     Layout();
00802     Refresh();
00803 };
00804 
00805 void ImagesPanel::OnDisplayModeChanged(wxCommandEvent & e)
00806 {
00807     wxRadioBox* display=XRCCTRL(*this,"images_column_radiobox", wxRadioBox);
00808     m_images_tree->SetDisplayMode((ImagesTreeCtrl::DisplayMode)display->GetSelection());
00809 };
00810 
00811 void ImagesPanel::OnOptimizerSwitchChanged(wxCommandEvent &e)
00812 {
00813     int optSwitch=*static_cast<int*>(m_optChoice->GetClientData(m_optChoice->GetSelection()));
00814     if(optSwitch!=m_pano->getOptimizerSwitch())
00815     {
00816         PanoCommand::GlobalCmdHist::getInstance().addCommand(
00817             new PanoCommand::UpdateOptimizerSwitchCmd(*m_pano,optSwitch)
00818         );
00819     };
00820 };
00821 
00822 void ImagesPanel::OnPhotometricOptimizerSwitchChanged(wxCommandEvent &e)
00823 {
00824     int optSwitch=*static_cast<int*>(m_optPhotoChoice->GetClientData(m_optPhotoChoice->GetSelection()));
00825     if(optSwitch!=m_pano->getPhotometricOptimizerSwitch())
00826     {
00827         PanoCommand::GlobalCmdHist::getInstance().addCommand(
00828             new PanoCommand::UpdatePhotometricOptimizerSwitchCmd(*m_pano,optSwitch)
00829         );
00830     };
00831 };
00832 
00833 void ImagesPanel::SetGuiLevel(GuiLevel newGuiLevel)
00834 {
00835     m_guiLevel=newGuiLevel;
00836     m_images_tree->SetGuiLevel(newGuiLevel);
00837     FillGroupChoice();
00838     FillOptimizerChoice();
00839     wxStaticText* textlabel=XRCCTRL(*this, "images_mode_text", wxStaticText);
00840     switch(m_guiLevel)
00841     {
00842         case GUI_SIMPLE:
00843             textlabel->SetLabel(_("Simple interface"));
00844             break;
00845         case GUI_ADVANCED:
00846             textlabel->SetLabel(_("Advanced interface"));
00847             break;
00848         case GUI_EXPERT:
00849             textlabel->SetLabel(_("Expert interface"));
00850             break;
00851     };
00852     textlabel->GetParent()->Layout();
00853     textlabel->Refresh();
00854     panoramaChanged(*m_pano);
00855 };
00856 
00857 void ImagesPanel::OnOptimizeButton(wxCommandEvent &e)
00858 {
00859     MainFrame::Get()->OnOptimize(e);
00860 };
00861 
00862 void ImagesPanel::OnPhotometricOptimizeButton(wxCommandEvent &e)
00863 {
00864     MainFrame::Get()->OnPhotometricOptimize(e);
00865 };
00866 
00867 IMPLEMENT_DYNAMIC_CLASS(ImagesPanel, wxPanel)
00868 
00869 ImagesPanelXmlHandler::ImagesPanelXmlHandler()
00870                 : wxXmlResourceHandler()
00871 {
00872     AddWindowStyles();
00873 }
00874 
00875 wxObject *ImagesPanelXmlHandler::DoCreateResource()
00876 {
00877     XRC_MAKE_INSTANCE(cp, ImagesPanel)
00878 
00879     cp->Create(m_parentAsWindow,
00880                    GetID(),
00881                    GetPosition(), GetSize(),
00882                    GetStyle(wxT("style")),
00883                    GetName());
00884 
00885     SetupWindow( cp);
00886     return cp;
00887 }
00888 
00889 bool ImagesPanelXmlHandler::CanHandle(wxXmlNode *node)
00890 {
00891     return IsOfClass(node, wxT("ImagesPanel"));
00892 }
00893 
00894 IMPLEMENT_DYNAMIC_CLASS(ImagesPanelXmlHandler, wxXmlResourceHandler)

Generated on 16 Oct 2017 for Hugintrunk by  doxygen 1.4.7