ImagesPanel.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00028 #include <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->SetValue(hugin_utils::doubleTowxString(opts.outputStacksMinOverlap,3));
00258     m_maxEv->SetValue(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             m_focallength->SetValue(hugin_utils::doubleTowxString(focallength,m_degDigits));
00399         }
00400         else
00401         {
00402             m_focallength->Clear();
00403         };
00404         if(cropFactor>0)
00405         {
00406             m_cropfactor->SetValue(hugin_utils::doubleTowxString(cropFactor,m_degDigits));
00407         }
00408         else
00409         {
00410             m_cropfactor->Clear();
00411         };
00412 
00413         if (sel.size() == 1)
00414         {
00415             ShowImage(*(sel.begin()));
00416         }
00417         else
00418         {
00419             m_smallImgCtrl->SetBitmap(m_empty);
00420             m_smallImgCtrl->GetParent()->Layout();
00421             m_smallImgCtrl->Refresh();
00422         };
00423     }
00424 }
00425 
00426 void ImagesPanel::DisableImageCtrls()
00427 {
00428     // disable controls
00429     m_lenstype->Disable();
00430     m_focallength->Disable();
00431     m_cropfactor->Disable();
00432     m_smallImgCtrl->SetBitmap(m_empty);
00433     m_smallImgCtrl->GetParent()->Layout();
00434     m_smallImgCtrl->Refresh();
00435 }
00436 
00437 void ImagesPanel::EnableImageCtrls()
00438 {
00439     // enable control if not already enabled
00440     m_lenstype->Enable();
00441     m_focallength->Enable();
00442     m_cropfactor->Enable();
00443 }
00444 
00445 void ImagesPanel::ShowImage(unsigned int imgNr)
00446 {
00447     m_showImgNr = imgNr;
00448     UpdatePreviewImage();
00449 }
00450 
00451 void ImagesPanel::UpdatePreviewImage()
00452 {
00453     if (m_showImgNr < 0 || m_showImgNr >= m_pano->getNrOfImages())
00454     {
00455         return;
00456     }
00457     ImageCache::EntryPtr cacheEntry = ImageCache::getInstance().getSmallImageIfAvailable(
00458             m_pano->getImage(m_showImgNr).getFilename());
00459     if (!cacheEntry.get())
00460     {
00461         // image currently isn't loaded.
00462         // Instead of loading and displaying the image now, request it for
00463         // later. Then the user can switch between images in the list quickly,
00464         // even when not all images previews are in the cache.
00465         thumbnail_request = ImageCache::getInstance().requestAsyncSmallImage(
00466                 m_pano->getImage(m_showImgNr).getFilename());
00467         // When the image is ready, try this function again.
00468         thumbnail_request->ready.push_back(
00469             std::bind(&ImagesPanel::UpdatePreviewImage, this)
00470             );
00471     } else {
00472         // forget any request now the image has loaded.
00473         thumbnail_request = ImageCache::RequestPtr();
00474         wxImage img = imageCacheEntry2wxImage(cacheEntry); 
00475 
00476         double iRatio = img.GetWidth() / (double) img.GetHeight();
00477 
00478         wxSize sz;
00479         // estimate image size
00480         
00481         sz = m_smallImgCtrl->GetContainingSizer()->GetSize();
00482         double sRatio = (double)sz.GetWidth() / sz.GetHeight();
00483         if (iRatio > sRatio) {
00484             // image is wider than screen, display landscape
00485             sz.SetHeight((int) (sz.GetWidth() / iRatio));
00486         } else {
00487             // portrait
00488             sz.SetWidth((int) (sz.GetHeight() * iRatio));
00489         }
00490         // Make sure the size is positive:
00491         // on a small window, m_smallImgCtrl can have 0 width.
00492         sz.IncTo(wxSize(1,1));
00493         wxImage scaled = img.Scale(sz.GetWidth(),sz.GetHeight());
00494         // now apply color profile
00495         if (!cacheEntry->iccProfile->empty() || huginApp::Get()->HasMonitorProfile())
00496         {
00497             HuginBase::Color::CorrectImage(scaled, *(cacheEntry->iccProfile), huginApp::Get()->GetMonitorProfile());
00498         };
00499         m_smallImgCtrl->SetBitmap(wxBitmap(scaled));
00500         m_smallImgCtrl->GetParent()->Layout();
00501         m_smallImgCtrl->Refresh();
00502     }
00503 }
00504 
00505 void ImagesPanel::ReloadCPDetectorSettings()
00506 {
00507     cpdetector_config.Read(); 
00508     cpdetector_config.FillControl(m_CPDetectorChoice,true);
00509     m_CPDetectorChoice->InvalidateBestSize();
00510     m_CPDetectorChoice->GetParent()->Layout();
00511     Refresh();
00512 };
00513 
00514 void ImagesPanel::OnLensTypeChanged (wxCommandEvent & e)
00515 {
00516     size_t var = GetSelectedValue(m_lenstype);
00517     HuginBase::UIntSet images = m_images_tree->GetSelectedImages();
00518     if(images.size()>0)
00519     {
00520         const HuginBase::SrcPanoImage & img = m_pano->getImage(*(images.begin()));
00521         double focal_length = HuginBase::SrcPanoImage::calcFocalLength(img.getProjection(), img.getHFOV(), img.getCropFactor(), img.getSize());
00522         std::vector<PanoCommand::PanoCommand*> commands;
00523         commands.push_back(new PanoCommand::ChangeImageProjectionCmd(*m_pano, images,(HuginBase::SrcPanoImage::Projection) var));
00524         commands.push_back(new PanoCommand::UpdateFocalLengthCmd(*m_pano, images, focal_length));
00525         PanoCommand::GlobalCmdHist::getInstance().addCommand(
00526             new PanoCommand::CombinedPanoCommand(*m_pano, commands)
00527         );
00528     };
00529 };
00530 
00531 void ImagesPanel::OnFocalLengthChanged(wxCommandEvent & e)
00532 {
00533     if (m_pano->getNrOfImages() == 0)
00534     {
00535         return;
00536     };
00537 
00538     wxString text = m_focallength->GetValue();
00539     if(text.IsEmpty())
00540     {
00541         return;
00542     };
00543     double val;
00544     if (!hugin_utils::str2double(text, val))
00545     {
00546         return;
00547     }
00548     //no negative values, no zero input please
00549     if (val<0.1)
00550     {
00551         wxBell();
00552         return;
00553     };
00554     
00555     HuginBase::UIntSet images = m_images_tree->GetSelectedImages();
00556     const HuginBase::SrcPanoImage& srcImg = m_pano->getImage(*(images.begin()));
00557     if (srcImg.getProjection() == HuginBase::SrcPanoImage::FISHEYE_ORTHOGRAPHIC)
00558     {
00559         double hfov=srcImg.calcHFOV(srcImg.getProjection(), val, srcImg.getCropFactor(), srcImg.getSize());
00560         if(hfov>190)
00561         {
00562             if(wxMessageBox(
00563                 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),
00564 #ifdef __WXMSW__
00565                 _("Hugin"),
00566 #else
00567                 wxT(""),
00568 #endif
00569                 wxICON_EXCLAMATION | wxYES_NO)==wxNO)
00570             {
00571                 wxTreeEvent dummy;
00572                 OnSelectionChanged(dummy);
00573                 return;
00574             };
00575         };
00576     };
00577     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00578         new PanoCommand::UpdateFocalLengthCmd(*m_pano, images, val)
00579     );
00580 }
00581 
00582 void ImagesPanel::OnCropFactorChanged(wxCommandEvent & e)
00583 {
00584     if (m_pano->getNrOfImages() == 0)
00585     {
00586         return;
00587     };
00588 
00589     wxString text = m_cropfactor->GetValue();
00590     if(text.IsEmpty())
00591     {
00592         return;
00593     };
00594     double val;
00595     if (!hugin_utils::str2double(text, val))
00596     {
00597         return;
00598     }
00599     //no negative values, no zero input please
00600     if (val<0.1)
00601     {
00602         wxBell();
00603         return;
00604     };
00605 
00606     HuginBase::UIntSet images = m_images_tree->GetSelectedImages();
00607     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00608         new PanoCommand::UpdateCropFactorCmd(*m_pano,images,val)
00609     );
00610 }
00611 
00612 void ImagesPanel::OnMinimumOverlapChanged(wxCommandEvent & e)
00613 {
00614     wxString text = m_overlap->GetValue();
00615     if(text.IsEmpty())
00616     {
00617         return;
00618     };
00619     double val;
00620     if (!hugin_utils::str2double(text, val))
00621     {
00622         return;
00623     }
00624     if(fabs(val)<0.001 || val>1)
00625     {
00626         wxMessageBox(_("The minimum overlap has to be greater than 0 and smaller than 1."),
00627 #ifdef _WIN32
00628             _("Hugin"),
00629 #else
00630             wxT(""),
00631 #endif
00632             wxOK | wxICON_INFORMATION, this);
00633         return;
00634     };
00635     if (val < 0)
00636     {
00637         val = -1;
00638     };
00639     HuginBase::PanoramaOptions opt = m_pano->getOptions();
00640     opt.outputStacksMinOverlap=val;
00641     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00642         new PanoCommand::SetPanoOptionsCmd(*m_pano,opt)
00643     );
00644 };
00645 
00646 void ImagesPanel::OnMaxEvDiffChanged(wxCommandEvent& e)
00647 {
00648     wxString text = m_maxEv->GetValue();
00649     if(text.IsEmpty())
00650     {
00651         return;
00652     };
00653     double val;
00654     if (!hugin_utils::str2double(text, val))
00655     {
00656         return;
00657     }
00658     if(val<0)
00659     {
00660         wxMessageBox(_("The maximum Ev difference has to be greater than 0."),
00661 #ifdef _WIN32
00662             _("Hugin"),
00663 #else
00664             wxT(""),
00665 #endif
00666             wxOK | wxICON_INFORMATION, this);
00667         return;
00668     };
00669     HuginBase::PanoramaOptions opt = m_pano->getOptions();
00670     opt.outputLayersExposureDiff=val;
00671     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00672         new PanoCommand::SetPanoOptionsCmd(*m_pano,opt)
00673     );
00674 };
00675 
00676 void ImagesPanel::FillGroupChoice()
00677 {
00678     wxChoice* group=XRCCTRL(*this,"images_group_mode", wxChoice);
00679     size_t sel=group->GetSelection();
00680     DeleteClientData(group);
00681     group->Clear();
00682     int* i=new int;
00683     *i=ImagesTreeCtrl::GROUP_NONE;
00684     group->Append(_("None"), i);
00685     i=new int;
00686     *i=ImagesTreeCtrl::GROUP_LENS;
00687     group->Append(_("Lens"), i);
00688     if(m_guiLevel>GUI_SIMPLE)
00689     {
00690         i=new int;
00691         *i=ImagesTreeCtrl::GROUP_STACK;
00692         group->Append(_("Stacks"), i);
00693         if(m_guiLevel==GUI_EXPERT)
00694         {
00695             i=new int;
00696             *i=ImagesTreeCtrl::GROUP_OUTPUTLAYERS;
00697             group->Append(_("Output layers"), i);
00698             i=new int;
00699             *i=ImagesTreeCtrl::GROUP_OUTPUTSTACK;
00700             group->Append(_("Output stacks"), i);
00701         };
00702     };
00703     if((m_guiLevel==GUI_ADVANCED && sel>2) || (m_guiLevel==GUI_SIMPLE && sel>1))
00704     {
00705         sel=0;
00706     };
00707     group->SetSelection(sel);
00708     wxCommandEvent dummy;
00709     OnGroupModeChanged(dummy);
00710 };
00711 
00712 void ImagesPanel::FillOptimizerChoice()
00713 {
00714     DeleteClientData(m_optChoice);
00715     m_optChoice->Clear();
00716     int* i=new int;
00717     *i=HuginBase::OPT_PAIR;
00718     m_optChoice->Append(_("Positions (incremental, starting from anchor)"), i);
00719     i=new int;
00720     *i=HuginBase::OPT_POSITION;
00721     m_optChoice->Append(_("Positions (y,p,r)"), i);
00722     i=new int;
00723     *i=(HuginBase::OPT_POSITION | HuginBase::OPT_VIEW);
00724     m_optChoice->Append(_("Positions and View (y,p,r,v)"), i);
00725     i=new int;
00726     *i=(HuginBase::OPT_POSITION | HuginBase::OPT_BARREL);
00727     m_optChoice->Append(_("Positions and Barrel Distortion (y,p,r,b)"), i);
00728     i=new int;
00729     *i=(HuginBase::OPT_POSITION | HuginBase::OPT_VIEW | HuginBase::OPT_BARREL);
00730     m_optChoice->Append(_("Positions, View and Barrel (y,p,r,v,b)"), i);
00731     i=new int;
00732     *i=HuginBase::OPT_ALL;
00733     if(m_guiLevel==GUI_EXPERT)
00734     {
00735         m_optChoice->Append(_("Everything without translation"), i);
00736     }
00737     else
00738     {
00739         m_optChoice->Append(_("Everything"), i);
00740     };
00741     if(m_guiLevel==GUI_EXPERT)
00742     {
00743         i=new int;
00744         *i=(HuginBase::OPT_POSITION | HuginBase::OPT_TRANSLATION);
00745         m_optChoice->Append(_("Positions and Translation (y,p,r,x,y,z)"), i);
00746         i=new int;
00747         *i=(HuginBase::OPT_POSITION | HuginBase::OPT_TRANSLATION | HuginBase::OPT_VIEW);
00748         m_optChoice->Append(_("Positions, Translation and View (y,p,r,x,y,z,v)"), i);
00749         i=new int;
00750         *i=(HuginBase::OPT_POSITION | HuginBase::OPT_TRANSLATION | HuginBase::OPT_BARREL);
00751         m_optChoice->Append(_("Positions, Translation and Barrel (y,p,r,x,y,z,b)"), i);
00752         i=new int;
00753         *i=(HuginBase::OPT_POSITION | HuginBase::OPT_TRANSLATION | HuginBase::OPT_VIEW | HuginBase::OPT_BARREL);
00754         m_optChoice->Append(_("Positions, Translation, View and Barrel (y,p,r,x,y,z,v,b)"), i);
00755     };
00756     i=new int;
00757     *i=0;
00758     m_optChoice->Append(_("Custom parameters"), i);
00759 
00760     DeleteClientData(m_optPhotoChoice);
00761     m_optPhotoChoice->Clear();
00762     i=new int;
00763     *i=(HuginBase::OPT_EXPOSURE | HuginBase::OPT_VIGNETTING | HuginBase::OPT_RESPONSE);
00764     m_optPhotoChoice->Append(_("Low dynamic range"), i);
00765     i=new int;
00766     *i=(HuginBase::OPT_EXPOSURE | HuginBase::OPT_VIGNETTING | HuginBase::OPT_RESPONSE | HuginBase::OPT_WHITEBALANCE);
00767     m_optPhotoChoice->Append(_("Low dynamic range, variable white balance"), i);
00768     if(m_guiLevel>GUI_SIMPLE)
00769     {
00770         i=new int;
00771         *i=(HuginBase::OPT_VIGNETTING | HuginBase::OPT_RESPONSE);
00772         m_optPhotoChoice->Append(_("High dynamic range, fixed exposure"), i);
00773         i=new int;
00774         *i=(HuginBase::OPT_WHITEBALANCE | HuginBase::OPT_VIGNETTING | HuginBase::OPT_RESPONSE);
00775         m_optPhotoChoice->Append(_("High dynamic range, variable white balance, fixed exposure"), i);
00776     };
00777     i=new int;
00778     *i=0;
00779     m_optPhotoChoice->Append(_("Custom parameters"), i);
00780     m_optChoice->GetParent()->Layout();
00781     Refresh();
00782 };
00783 
00784 wxString ImagesPanel::GetCurrentOptimizerString()
00785 {
00786     return m_optChoice->GetString(m_optChoice->GetSelection());
00787 };
00788 
00789 void ImagesPanel::OnGroupModeChanged(wxCommandEvent & e)
00790 {
00791     wxChoice* group=XRCCTRL(*this,"images_group_mode", wxChoice);
00792     ImagesTreeCtrl::GroupMode mode=ImagesTreeCtrl::GroupMode(*static_cast<int*>(group->GetClientData(group->GetSelection())));
00793     m_images_tree->SetGroupMode(mode);
00794     XRCCTRL(*this, "images_text_overlap", wxStaticText)->Show(mode==ImagesTreeCtrl::GROUP_OUTPUTSTACK);
00795     m_overlap->Show(mode==ImagesTreeCtrl::GROUP_OUTPUTSTACK);
00796     m_overlap->Enable(mode==ImagesTreeCtrl::GROUP_OUTPUTSTACK);
00797     XRCCTRL(*this, "images_text_maxev", wxStaticText)->Show(mode==ImagesTreeCtrl::GROUP_OUTPUTLAYERS);
00798     m_maxEv->Show(mode==ImagesTreeCtrl::GROUP_OUTPUTLAYERS);
00799     m_maxEv->Enable(mode==ImagesTreeCtrl::GROUP_OUTPUTLAYERS);
00800     Layout();
00801     Refresh();
00802 };
00803 
00804 void ImagesPanel::OnDisplayModeChanged(wxCommandEvent & e)
00805 {
00806     wxRadioBox* display=XRCCTRL(*this,"images_column_radiobox", wxRadioBox);
00807     m_images_tree->SetDisplayMode((ImagesTreeCtrl::DisplayMode)display->GetSelection());
00808 };
00809 
00810 void ImagesPanel::OnOptimizerSwitchChanged(wxCommandEvent &e)
00811 {
00812     int optSwitch=*static_cast<int*>(m_optChoice->GetClientData(m_optChoice->GetSelection()));
00813     if(optSwitch!=m_pano->getOptimizerSwitch())
00814     {
00815         PanoCommand::GlobalCmdHist::getInstance().addCommand(
00816             new PanoCommand::UpdateOptimizerSwitchCmd(*m_pano,optSwitch)
00817         );
00818     };
00819 };
00820 
00821 void ImagesPanel::OnPhotometricOptimizerSwitchChanged(wxCommandEvent &e)
00822 {
00823     int optSwitch=*static_cast<int*>(m_optPhotoChoice->GetClientData(m_optPhotoChoice->GetSelection()));
00824     if(optSwitch!=m_pano->getPhotometricOptimizerSwitch())
00825     {
00826         PanoCommand::GlobalCmdHist::getInstance().addCommand(
00827             new PanoCommand::UpdatePhotometricOptimizerSwitchCmd(*m_pano,optSwitch)
00828         );
00829     };
00830 };
00831 
00832 void ImagesPanel::SetGuiLevel(GuiLevel newGuiLevel)
00833 {
00834     m_guiLevel=newGuiLevel;
00835     m_images_tree->SetGuiLevel(newGuiLevel);
00836     FillGroupChoice();
00837     FillOptimizerChoice();
00838     wxStaticText* textlabel=XRCCTRL(*this, "images_mode_text", wxStaticText);
00839     switch(m_guiLevel)
00840     {
00841         case GUI_SIMPLE:
00842             textlabel->SetLabel(_("Simple interface"));
00843             break;
00844         case GUI_ADVANCED:
00845             textlabel->SetLabel(_("Advanced interface"));
00846             break;
00847         case GUI_EXPERT:
00848             textlabel->SetLabel(_("Expert interface"));
00849             break;
00850     };
00851     textlabel->GetParent()->Layout();
00852     textlabel->Refresh();
00853     panoramaChanged(*m_pano);
00854 };
00855 
00856 void ImagesPanel::OnOptimizeButton(wxCommandEvent &e)
00857 {
00858     MainFrame::Get()->OnOptimize(e);
00859 };
00860 
00861 void ImagesPanel::OnPhotometricOptimizeButton(wxCommandEvent &e)
00862 {
00863     MainFrame::Get()->OnPhotometricOptimize(e);
00864 };
00865 
00866 IMPLEMENT_DYNAMIC_CLASS(ImagesPanel, wxPanel)
00867 
00868 ImagesPanelXmlHandler::ImagesPanelXmlHandler()
00869                 : wxXmlResourceHandler()
00870 {
00871     AddWindowStyles();
00872 }
00873 
00874 wxObject *ImagesPanelXmlHandler::DoCreateResource()
00875 {
00876     XRC_MAKE_INSTANCE(cp, ImagesPanel)
00877 
00878     cp->Create(m_parentAsWindow,
00879                    GetID(),
00880                    GetPosition(), GetSize(),
00881                    GetStyle(wxT("style")),
00882                    GetName());
00883 
00884     SetupWindow( cp);
00885     return cp;
00886 }
00887 
00888 bool ImagesPanelXmlHandler::CanHandle(wxXmlNode *node)
00889 {
00890     return IsOfClass(node, wxT("ImagesPanel"));
00891 }
00892 
00893 IMPLEMENT_DYNAMIC_CLASS(ImagesPanelXmlHandler, wxXmlResourceHandler)

Generated on 9 Dec 2016 for Hugintrunk by  doxygen 1.4.7