PreviewFrame.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00027 // use toggle buttons or uncomment check boxes
00028 
00029 //#ifndef __WXMAC__
00030 #define USE_TOGGLE_BUTTON 1
00031 //#endif
00032 //wxMac now has toggle buttons.
00033 
00034 #include <config.h>
00035 
00036 #include "panoinc_WX.h"
00037 
00038 #include "panoinc.h"
00039 
00040 #include "base_wx/platform.h"
00041 #include "hugin/config_defaults.h"
00042 #include "hugin/PreviewFrame.h"
00043 #include "hugin/huginApp.h"
00044 #include "hugin/PreviewPanel.h"
00045 #include "hugin/ImagesPanel.h"
00046 #include "base_wx/CommandHistory.h"
00047 #include "base_wx/PanoCommand.h"
00048 #include "hugin/TextKillFocusHandler.h"
00049 #include "algorithms/nona/FitPanorama.h"
00050 #include "algorithms/basic/CalculateMeanExposure.h"
00051 #include "base_wx/wxPlatform.h"
00052 
00053 #include <vigra_ext/ImageTransforms.h>
00054 
00055 extern "C" {
00056 #include <pano13/queryfeature.h>
00057 }
00058 
00059 // a random id, hope this doesn't break something..
00060 enum {
00061     ID_PROJECTION_CHOICE = wxID_HIGHEST +1,
00062     ID_BLEND_CHOICE,
00063     ID_UPDATE_BUTTON,
00064     ID_OUTPUTMODE_CHOICE,
00065     ID_EXPOSURE_TEXT,
00066     ID_EXPOSURE_SPIN,
00067     ID_EXPOSURE_DEFAULT,
00068     ID_TOGGLE_BUT = wxID_HIGHEST+100,
00069     PROJ_PARAM_NAMES_ID = wxID_HIGHEST+1000,
00070     PROJ_PARAM_VAL_ID = wxID_HIGHEST+1100,
00071     PROJ_PARAM_SLIDER_ID = wxID_HIGHEST+1200,
00072     PROJ_PARAM_RESET_ID = wxID_HIGHEST+1250,
00073     ID_FULL_SCREEN = wxID_HIGHEST+1700,
00074     ID_UNDO = wxID_HIGHEST+1701,
00075     ID_REDO = wxID_HIGHEST+1702
00076 };
00077 
00078 BEGIN_EVENT_TABLE(PreviewFrame, wxFrame)
00079     EVT_CLOSE(PreviewFrame::OnClose)
00080 //    EVT_CHECKBOX(-1, PreviewFrame::OnAutoPreviewToggle)
00081     EVT_TOOL(XRCID("preview_center_tool"), PreviewFrame::OnCenterHorizontally)
00082     EVT_TOOL(XRCID("preview_fit_pano_tool"), PreviewFrame::OnFitPano)
00083     EVT_TOOL(XRCID("preview_straighten_pano_tool"), PreviewFrame::OnStraighten)
00084     EVT_TOOL(XRCID("preview_auto_update_tool"), PreviewFrame::OnAutoPreviewToggle)
00085     EVT_TOOL(XRCID("preview_update_tool"), PreviewFrame::OnUpdate)
00086     EVT_TOOL(XRCID("preview_show_all_tool"), PreviewFrame::OnShowAll)
00087     EVT_TOOL(XRCID("preview_show_none_tool"), PreviewFrame::OnShowNone)
00088     EVT_TOOL(XRCID("preview_num_transform"), PreviewFrame::OnNumTransform)
00089     EVT_TEXT_ENTER( -1 , PreviewFrame::OnTextCtrlChanged)
00090 
00091     EVT_BUTTON(ID_EXPOSURE_DEFAULT, PreviewFrame::OnDefaultExposure)
00092     EVT_SPIN_DOWN(ID_EXPOSURE_SPIN, PreviewFrame::OnDecreaseExposure)
00093     EVT_SPIN_UP(ID_EXPOSURE_SPIN, PreviewFrame::OnIncreaseExposure)
00094     EVT_CHOICE(ID_BLEND_CHOICE, PreviewFrame::OnBlendChoice)
00095     EVT_CHOICE(ID_PROJECTION_CHOICE, PreviewFrame::OnProjectionChoice)
00096     EVT_CHOICE(ID_OUTPUTMODE_CHOICE, PreviewFrame::OnOutputChoice)
00097 #ifdef USE_TOGGLE_BUTTON
00098     EVT_TOGGLEBUTTON(-1, PreviewFrame::OnChangeDisplayedImgs)
00099 #else
00100     EVT_CHECKBOX(-1, PreviewFrame::OnChangeDisplayedImgs)
00101 #endif
00102 #ifndef __WXMAC__
00103         EVT_SCROLL_CHANGED(PreviewFrame::OnChangeFOV)
00104 #else
00105  #if wxCHECK_VERSION(2,9,0)
00106         EVT_SCROLL_CHANGED(PreviewFrame::OnChangeFOV)
00107  #else
00108         EVT_SCROLL_THUMBRELEASE(PreviewFrame::OnChangeFOV)
00109         EVT_SCROLL_ENDSCROLL(PreviewFrame::OnChangeFOV)
00110         EVT_SCROLL_THUMBTRACK(PreviewFrame::OnChangeFOV)
00111  #endif
00112 #endif
00113         EVT_TOOL(ID_FULL_SCREEN, PreviewFrame::OnFullScreen)
00114     EVT_TOOL(ID_UNDO, PreviewFrame::OnUndo)
00115     EVT_TOOL(ID_REDO, PreviewFrame::OnRedo)
00116     EVT_BUTTON(PROJ_PARAM_RESET_ID, PreviewFrame::OnProjParameterReset)
00117 END_EVENT_TABLE()
00118 
00119 #define PF_STYLE (wxMAXIMIZE_BOX | wxMINIMIZE_BOX | wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN)
00120 
00121 PreviewFrame::PreviewFrame(wxFrame * frame, HuginBase::Panorama &pano)
00122     : wxFrame(frame,-1, _("Panorama preview"), wxDefaultPosition, wxDefaultSize,
00123               PF_STYLE),
00124       m_pano(pano)
00125 {
00126         DEBUG_TRACE("");
00127 
00128     m_oldProjFormat = -1;
00129     m_ToolBar = wxXmlResource::Get()->LoadToolBar(this, wxT("preview_toolbar"));
00130     DEBUG_ASSERT(m_ToolBar);
00131     // create tool bar
00132     SetToolBar(m_ToolBar);
00133 
00134     m_topsizer = new wxBoxSizer( wxVERTICAL );
00135 
00136     m_ToggleButtonSizer = new wxStaticBoxSizer(
00137         new wxStaticBox(this, -1, _("displayed images")),
00138     wxHORIZONTAL );
00139 
00140         m_ButtonPanel = new wxScrolledWindow(this, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
00141         // Set min height big enough to display scrollbars as well
00142     m_ButtonPanel->SetSizeHints(20, 42);
00143         //Horizontal scroll bars only
00144         m_ButtonPanel->SetScrollRate(10, 0);
00145     m_ButtonSizer = new wxBoxSizer(wxHORIZONTAL);
00146     m_ButtonPanel->SetAutoLayout(true);
00147         m_ButtonPanel->SetSizer(m_ButtonSizer);
00148                                                 
00149         m_ToggleButtonSizer->Add(m_ButtonPanel, 1, wxEXPAND, 0);
00150 
00151     m_topsizer->Add(m_ToggleButtonSizer, 0, wxEXPAND | wxALL, 5);
00152 
00153     wxFlexGridSizer * flexSizer = new wxFlexGridSizer(2,0,5,5);
00154     flexSizer->AddGrowableCol(0);
00155     flexSizer->AddGrowableRow(0);
00156 
00157     // create our preview panel
00158     m_PreviewPanel = new PreviewPanel();
00159     m_PreviewPanel->Create(this);
00160     m_PreviewPanel->Init(this, &pano);
00161 
00162     flexSizer->Add(m_PreviewPanel,
00163                   1,        // not vertically stretchable
00164                   wxEXPAND | // horizontally stretchable
00165                   wxALL,    // draw border all around
00166                   5);       // border width
00167 
00168 
00169     m_VFOVSlider = new wxSlider(this, -1, 1,
00170                                 1, 180,
00171                                 wxDefaultPosition, wxDefaultSize,
00172                                 wxSL_VERTICAL | wxSL_AUTOTICKS,
00173                                 wxDefaultValidator,
00174                                 _("VFOV"));
00175     m_VFOVSlider->SetLineSize(2);
00176     m_VFOVSlider->SetPageSize(10);
00177 #if wxCHECK_VERSION(3,0,0)
00178     m_VFOVSlider->SetTickFreq(5);
00179 #else
00180     m_VFOVSlider->SetTickFreq(5,0);
00181 #endif
00182     m_VFOVSlider->SetToolTip(_("drag to change the vertical field of view"));
00183 
00184     flexSizer->Add(m_VFOVSlider, 0, wxEXPAND);
00185 
00186     m_HFOVSlider = new wxSlider(this, -1, 1,
00187                                 1, 360,
00188                                 wxDefaultPosition, wxDefaultSize,
00189                                 wxSL_HORIZONTAL | wxSL_AUTOTICKS,
00190                                 wxDefaultValidator,
00191                                 _("HFOV"));
00192     m_HFOVSlider->SetPageSize(10);
00193     m_HFOVSlider->SetLineSize(2);
00194 #if wxCHECK_VERSION(3,0,0)
00195     m_HFOVSlider->SetTickFreq(5);
00196 #else
00197     m_HFOVSlider->SetTickFreq(5,0);
00198 #endif
00199 
00200     m_HFOVSlider->SetToolTip(_("drag to change the horizontal field of view"));
00201 
00202     flexSizer->Add(m_HFOVSlider, 0, wxEXPAND);
00203 
00204     m_topsizer->Add(flexSizer,
00205                   1,        // vertically stretchable
00206                   wxEXPAND | // horizontally stretchable
00207                   wxALL,    // draw border all around
00208                   5);       // border width
00209 
00210     wxStaticBoxSizer * blendModeSizer = new wxStaticBoxSizer(
00211         new wxStaticBox(this, -1, _("Preview Options")),
00212         wxHORIZONTAL);
00213 
00214     blendModeSizer->Add(new wxStaticText(this, -1, _("projection (f):")),
00215                         0,        // not vertically strechable
00216                         wxALL | wxALIGN_CENTER_VERTICAL, // draw border all around
00217                         5);       // border width
00218     m_ProjectionChoice = new wxChoice(this, ID_PROJECTION_CHOICE,
00219                                       wxDefaultPosition, wxDefaultSize);
00220 
00221     /* populate with all available projection types */
00222     int nP = panoProjectionFormatCount();
00223     for(int n=0; n < nP; n++) {
00224         pano_projection_features proj;
00225         if (panoProjectionFeaturesQuery(n, &proj)) {
00226             wxString str2(proj.name, wxConvLocal);
00227             m_ProjectionChoice->Append(wxGetTranslation(str2));
00228         }
00229     }
00230     m_ProjectionChoice->SetSelection(2);
00231 
00232     blendModeSizer->Add(m_ProjectionChoice,
00233                         0,
00234                         wxALL | wxALIGN_CENTER_VERTICAL,
00235                         5);
00236 
00238     // Blend mode
00239     blendModeSizer->Add(new wxStaticText(this, -1, _("Blend mode:")),
00240                         0,        // not vertically strechable
00241                         wxALL | wxALIGN_CENTER_VERTICAL, // draw border all around
00242                         5);       // border width
00243 
00244     m_choices[0] = _("normal");
00245     m_choices[1] = _("difference");
00246 
00247     int oldMode = wxConfigBase::Get()->Read(wxT("/PreviewFrame/blendMode"), 0l);
00248     if (oldMode > 1) oldMode = 0;
00249     m_BlendModeChoice = new wxChoice(this, ID_BLEND_CHOICE,
00250                                      wxDefaultPosition, wxDefaultSize,
00251                                      2, m_choices);
00252     m_BlendModeChoice->SetSelection((PreviewPanel::BlendMode) oldMode);
00253 
00254     blendModeSizer->Add(m_BlendModeChoice,
00255                         0,
00256                         wxALL | wxALIGN_CENTER_VERTICAL,
00257                         5);
00258 
00260     // LDR, HDR
00261     blendModeSizer->Add(new wxStaticText(this, -1, _("Output:")),
00262                         0,        // not vertically strechable
00263                         wxALL | wxALIGN_CENTER_VERTICAL, // draw border all around
00264                         5);       // border width
00265 
00266     m_choices[0] = _("LDR");
00267     m_choices[1] = _("HDR");
00268     m_outputModeChoice = new wxChoice(this, ID_OUTPUTMODE_CHOICE,
00269                                       wxDefaultPosition, wxDefaultSize,
00270                                       2, m_choices);
00271     m_outputModeChoice->SetSelection(0);
00272     blendModeSizer->Add(m_outputModeChoice,
00273                         0,
00274                         wxALL | wxALIGN_CENTER_VERTICAL,
00275                         5);
00276 
00278     // exposure
00279     blendModeSizer->Add(new wxStaticText(this, -1, _("EV:")),
00280                           0,        // not vertically strechable
00281                           wxALL | wxALIGN_CENTER_VERTICAL, // draw border all around
00282                           5);       // border width
00283     
00284     m_defaultExposureBut = new wxBitmapButton(this, ID_EXPOSURE_DEFAULT,
00285                                               wxArtProvider::GetBitmap(wxART_REDO));
00286     blendModeSizer->Add(m_defaultExposureBut, 0, wxLEFT | wxRIGHT, 5);
00287 
00288 //    m_decExposureBut = new wxBitmapButton(this, ID_EXPOSURE_DECREASE,
00289 //                                          wxArtProvider::GetBitmap(wxART_GO_BACK));
00290 //    blendModeSizer->Add(m_decExposureBut);
00291 
00292     m_exposureTextCtrl = new wxTextCtrl(this, ID_EXPOSURE_TEXT, wxT("0"),
00293                                         wxDefaultPosition,wxSize(50,-1), wxTE_PROCESS_ENTER);
00294     blendModeSizer->Add(m_exposureTextCtrl,
00295                           0,        // not vertically strechable
00296                           wxLEFT | wxTOP | wxBOTTOM  | wxALIGN_CENTER_VERTICAL, // draw border all around
00297                           5);       // border width
00298 //    m_incExposureBut = new wxBitmapButton(this, ID_EXPOSURE_INCREASE,
00299 //                                          wxArtProvider::GetBitmap(wxART_GO_FORWARD));
00300     m_exposureSpinBut = new wxSpinButton(this, ID_EXPOSURE_SPIN, wxDefaultPosition,
00301                                          wxDefaultSize, wxSP_VERTICAL);
00302     m_exposureSpinBut->SetRange(-0x8000, 0x7fff);
00303     m_exposureSpinBut->SetValue(0);
00304     blendModeSizer->Add(m_exposureSpinBut, 0, wxALIGN_CENTER_VERTICAL);
00305 
00306     m_topsizer->Add(blendModeSizer, 0, wxEXPAND | wxALL, 5);
00307 
00308     m_projParamSizer = new wxStaticBoxSizer(
00309     new wxStaticBox(this, -1, _("Projection Parameters")),
00310      wxHORIZONTAL);
00311 
00312     wxBitmapButton * resetProjButton=new wxBitmapButton(this, PROJ_PARAM_RESET_ID, 
00313         wxArtProvider::GetBitmap(wxART_REDO));
00314     resetProjButton->SetToolTip(_("Resets the projection's parameters to their default values."));
00315     m_projParamSizer->Add(resetProjButton, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
00316 
00317     m_projParamNamesLabel.resize(PANO_PROJECTION_MAX_PARMS);
00318     m_projParamTextCtrl.resize(PANO_PROJECTION_MAX_PARMS);
00319     m_projParamSlider.resize(PANO_PROJECTION_MAX_PARMS);
00320 
00321     for (int i=0; i < PANO_PROJECTION_MAX_PARMS; i++) {
00322 
00323         m_projParamNamesLabel[i] = new wxStaticText(this, PROJ_PARAM_NAMES_ID+i, _("param:"));
00324         m_projParamSizer->Add(m_projParamNamesLabel[i],
00325                         0,        // not vertically strechable
00326                         wxALL | wxALIGN_CENTER_VERTICAL, // draw border all around
00327                         5);       // border width
00328         m_projParamTextCtrl[i] = new wxTextCtrl(this, PROJ_PARAM_VAL_ID+i, wxT("0"),
00329                                     wxDefaultPosition, wxSize(35,-1), wxTE_PROCESS_ENTER);
00330         m_projParamTextCtrl[i]->PushEventHandler(new TextKillFocusHandler(this));
00331         m_projParamSizer->Add(m_projParamTextCtrl[i],
00332                         0,        // not vertically strechable
00333                         wxALL | wxALIGN_CENTER_VERTICAL, // draw border all around
00334                         5);       // border width
00335 
00336         m_projParamSlider[i] = new wxSlider(this, PROJ_PARAM_SLIDER_ID+i, 0, -90, 90);
00337         m_projParamSizer->Add(m_projParamSlider[i],
00338                         1,        // not vertically strechable
00339                         wxALL | wxALIGN_CENTER_VERTICAL, // draw border all around
00340                         5);       // border width
00341     }
00342 
00343     m_topsizer->Add(m_projParamSizer, 0, wxEXPAND | wxALL, 5);
00344 
00345     // do not show projection param sizer
00346     m_topsizer->Show(m_projParamSizer, false, true);
00347 
00348     wxConfigBase * config = wxConfigBase::Get();
00349 
00350     // add a status bar
00351     CreateStatusBar(3);
00352     int widths[3] = {-3, 150, 150};
00353     SetStatusWidths(3, widths);
00354     SetStatusText(_("Left click to define new center point, right click to move point to horizon."),0);
00355     SetStatusText(wxT(""),1);
00356     SetStatusText(wxT(""),2);
00357 
00358     // the initial size as calculated by the sizers
00359     this->SetSizer( m_topsizer );
00360     m_topsizer->SetSizeHints( this );
00361 
00362     // set the minimize icon
00363 #ifdef __WXMSW__
00364     wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/hugin.ico"),wxBITMAP_TYPE_ICO);
00365 #else
00366     wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/hugin.png"),wxBITMAP_TYPE_PNG);
00367 #endif
00368     SetIcon(myIcon);
00369 
00370     m_pano.addObserver(this);
00371 
00372     RestoreFramePosition(this, wxT("PreviewFrame"));
00373     
00374     m_PreviewPanel->SetBlendMode((PreviewPanel::BlendMode)oldMode );
00375 
00376     long aup = config->Read(wxT("/PreviewFrame/autoUpdate"),0l);
00377     m_PreviewPanel->SetAutoUpdate(aup != 0);
00378 
00379     m_ToolBar->ToggleTool(XRCID("preview_auto_update_tool"), aup !=0);
00380 
00381 #ifdef __WXMSW__
00382     // wxFrame does have a strange background color on Windows..
00383     this->SetBackgroundColour(m_PreviewPanel->GetBackgroundColour());
00384 #endif
00385 
00386     if (config->Read(wxT("/PreviewFrame/isShown"), 0l) != 0) {
00387         Show();
00388     }
00389     SetStatusText(_("Center panorama with left mouse button, set horizon with right button"),0);
00390     wxAcceleratorEntry entries[3];
00391 #ifdef __WXMAC
00392     entries[0].Set(wxACCEL_CMD,(int)'F',ID_FULL_SCREEN);
00393 #else
00394     entries[0].Set(wxACCEL_NORMAL,WXK_F11,ID_FULL_SCREEN);
00395 #endif
00396     entries[1].Set(wxACCEL_CMD,(int)'Z',ID_UNDO);
00397     entries[2].Set(wxACCEL_CMD,(int)'R',ID_REDO);
00398     wxAcceleratorTable accel(3, entries);
00399     SetAcceleratorTable(accel);
00400 #ifdef __WXGTK__
00401     // set explicit focus to button panel, otherwise the hotkey F11 is not right processed
00402     m_ButtonPanel->SetFocus();
00403 #endif
00404 }
00405 
00406 PreviewFrame::~PreviewFrame()
00407 {
00408     DEBUG_TRACE("dtor writing config");
00409     wxConfigBase * config = wxConfigBase::Get();
00410 
00411     StoreFramePosition(this, wxT("PreviewFrame"));
00412 
00413     if ( (!this->IsIconized()) && (! this->IsMaximized()) && this->IsShown()) {
00414         config->Write(wxT("/PreviewFrame/isShown"), 1l);
00415     } else {
00416         config->Write(wxT("/PreviewFrame/isShown"), 0l);
00417     }
00418 
00419     bool checked = m_ToolBar->GetToolState(XRCID("preview_auto_update_tool"));
00420     config->Write(wxT("/PreviewFrame/autoUpdate"), checked ? 1l: 0l);
00421     config->Write(wxT("/PreviewFrame/blendMode"), m_BlendModeChoice->GetSelection());
00422     for (int i=0; i < PANO_PROJECTION_MAX_PARMS; i++)
00423     {
00424         m_projParamTextCtrl[i]->PopEventHandler(true);
00425     };
00426     m_pano.removeObserver(this);
00427     DEBUG_TRACE("dtor end");
00428 }
00429 
00430 void PreviewFrame::OnChangeDisplayedImgs(wxCommandEvent & e)
00431 {
00432     int id = e.GetId() - ID_TOGGLE_BUT;
00433     int nImg = m_pano.getNrOfImages();
00434     HuginBase::UIntSet activeImages = m_pano.getActiveImages();
00435     DEBUG_DEBUG("toggle_button_id: " << id << " nImg:" << nImg << "  m_ToggleButtons.size(): " << m_ToggleButtons.size());
00436     if (id >= 0 && id < nImg) {
00437         if (e.IsChecked()) {
00438             activeImages.insert(id);
00439         } else {
00440             activeImages.erase(id);
00441         }
00442 //        m_PreviewPanel->SetDisplayedImages(m_displayedImgs);
00443         PanoCommand::GlobalCmdHist::getInstance().addCommand(
00444             new PanoCommand::SetActiveImagesCmd(m_pano, activeImages)
00445         );
00446     } else {
00447         DEBUG_ERROR("invalid Togglebutton ID");
00448     }
00449 }
00450 
00451 void PreviewFrame::panoramaChanged(HuginBase::Panorama &pano)
00452 {
00453     const HuginBase::PanoramaOptions & opts = pano.getOptions();
00454 
00455     wxString projection;
00456     m_ProjectionChoice->SetSelection(opts.getProjection());
00457     m_VFOVSlider->Enable( opts.fovCalcSupported(opts.getProjection()) );
00458 
00459     m_outputModeChoice->SetSelection(opts.outputMode);
00460     if (opts.outputMode == HuginBase::PanoramaOptions::OUTPUT_HDR) {
00461         /*
00462         m_exposureTextCtrl->Hide();
00463         m_defaultExposureBut->Hide();
00464         m_decExposureBut->Hide();
00465         m_incExposureBut->Hide();
00466         */
00467     } else {
00468         /*
00469         m_exposureTextCtrl->Show();
00470         m_defaultExposureBut->Show();
00471         m_decExposureBut->Show();
00472         m_incExposureBut->Show();
00473         */
00474     }
00475     m_exposureTextCtrl->SetValue(wxString(hugin_utils::doubleToString(opts.outputExposureValue,2).c_str(), wxConvLocal));
00476 
00477     bool activeImgs = pano.getActiveImages().size() > 0;
00478     m_ToolBar->EnableTool(XRCID("preview_center_tool"), activeImgs);
00479     m_ToolBar->EnableTool(XRCID("preview_fit_pano_tool"), activeImgs);
00480     m_ToolBar->EnableTool(XRCID("preview_update_tool"), activeImgs);
00481     m_ToolBar->EnableTool(XRCID("preview_num_transform"), activeImgs);
00482     m_ToolBar->EnableTool(XRCID("preview_straighten_pano_tool"), pano.getNrOfImages() > 0);
00483 
00484     // TODO: enable display of parameters and set their limits, if projection has some.
00485     int nParam = opts.m_projFeatures.numberOfParameters;
00486     bool relayout = false;
00487     // if the projection format has changed
00488     if (opts.getProjection() != m_oldProjFormat) {
00489         DEBUG_DEBUG("Projection format changed");
00490         if (nParam) {
00491             // show parameters and update labels.
00492             m_topsizer->Show(m_projParamSizer, true, true);
00493             int i;
00494             for (i=0; i < nParam; i++) {
00495                 const pano_projection_parameter * pp = & (opts.m_projFeatures.parm[i]);
00496                 wxString str2(pp->name, wxConvLocal);
00497                 str2 = wxGetTranslation(str2);
00498                 m_projParamNamesLabel[i]->SetLabel(str2);
00499                 m_projParamSlider[i]->SetRange(hugin_utils::roundi(pp->minValue), hugin_utils::roundi(pp->maxValue));
00500             }
00501             for(;i < PANO_PROJECTION_MAX_PARMS; i++) {
00502                 m_projParamNamesLabel[i]->Hide();
00503                 m_projParamSlider[i]->Hide();
00504                 m_projParamTextCtrl[i]->Hide();
00505             }
00506             relayout = true;
00507         } else {
00508             m_topsizer->Show(m_projParamSizer, false, true);
00509             relayout = true;
00510         }
00511     }
00512     if (nParam) {
00513         // display new values
00514         std::vector<double> params = opts.getProjectionParameters();
00515         assert((int) params.size() == nParam);
00516         for (int i=0; i < nParam; i++) {
00517             wxString val = wxString(hugin_utils::doubleToString(params[i],1).c_str(), wxConvLocal);
00518             m_projParamTextCtrl[i]->SetValue(wxString(val.wc_str(), wxConvLocal));
00519             m_projParamSlider[i]->SetValue(hugin_utils::roundi(params[i]));
00520         }
00521     }
00522     if (relayout) {
00523         m_topsizer->Layout();
00524         Refresh();
00525     }
00526     SetStatusText(_("Center panorama with left mouse button, set horizon with right button"),0);
00527     SetStatusText(wxString::Format(wxT("%.1f x %.1f"), opts.getHFOV(), opts.getVFOV()),2);
00528     m_HFOVSlider->SetValue(hugin_utils::roundi(opts.getHFOV()));
00529     m_VFOVSlider->SetValue(hugin_utils::roundi(opts.getVFOV()));
00530 
00531     m_oldProjFormat = opts.getProjection();
00532     updatePano();
00533 }
00534 
00535 void PreviewFrame::panoramaImagesChanged(HuginBase::Panorama &pano, const HuginBase::UIntSet &changed)
00536 {
00537     DEBUG_TRACE("");
00538 
00539     bool dirty = false;
00540 
00541     unsigned int nrImages = pano.getNrOfImages();
00542     unsigned int nrButtons = m_ToggleButtons.size();
00543 
00544 //    m_displayedImgs.clear();
00545 
00546     // remove items for nonexisting images
00547     for (int i=nrButtons-1; i>=(int)nrImages; i--)
00548     {
00549         m_ButtonSizer->Detach(m_ToggleButtons[i]);
00550         delete m_ToggleButtons[i];
00551         m_ToggleButtons.pop_back();
00552         dirty = true;
00553     }
00554 
00555     // add buttons
00556     if ( nrImages >= nrButtons ) {
00557         for(HuginBase::UIntSet::const_iterator it = changed.begin(); it != changed.end(); ++it){
00558             if (*it >= nrButtons) {
00559                 // create new item.
00560 //                wxImage * bmp = new wxImage(sz.GetWidth(), sz.GetHeight());
00561 #ifdef USE_TOGGLE_BUTTON
00562                 wxToggleButton * but = new wxToggleButton(m_ButtonPanel,
00563                                                           ID_TOGGLE_BUT + *it,
00564                                                           wxString::Format(wxT("%d"),*it),
00565                                                           wxDefaultPosition, wxDefaultSize,
00566                                                           wxBU_EXACTFIT);
00567 #else
00568                 wxCheckBox * but = new wxCheckBox(m_ButtonPanel,
00569                                                   ID_TOGGLE_BUT + *it,
00570                                                   wxString::Format(wxT("%d"),*it));
00571 #endif
00572                 wxSize sz = but->GetSize();
00573 //                but->SetSize(res.GetWidth(),sz.GetHeight());
00574                 // HACK.. set fixed width. that should work
00575                 // better than all that stupid dialogunit stuff, that
00576                 // breaks on wxWin 2.5
00577                 but->SetSize(20, sz.GetHeight());
00578                 but->SetValue(true);
00579                 m_ButtonSizer->Add(but,
00580                                    0,
00581                                    wxLEFT | wxTOP,
00582                                    5);
00583                 m_ToggleButtons.push_back(but);
00584                 dirty = true;
00585             }
00586         }
00587     }
00588 
00589     // update existing items
00590     HuginBase::UIntSet displayedImages = m_pano.getActiveImages();
00591     for (unsigned i=0; i < nrImages; i++) {
00592         m_ToggleButtons[i]->SetValue(set_contains(displayedImages, i));
00593         wxFileName tFilename(wxString (pano.getImage(i).getFilename().c_str(), HUGIN_CONV_FILENAME));
00594         m_ToggleButtons[i]->SetToolTip(tFilename.GetFullName());
00595     }
00596 
00597     if (dirty) {
00598 #if wxCHECK_VERSION(3,0,0)
00599         m_ButtonSizer->FitInside(m_ButtonPanel);
00600 #else
00601                 m_ButtonSizer->SetVirtualSizeHints(m_ButtonPanel);
00602 #endif
00603                 // Layout();
00604                 DEBUG_INFO("New m_ButtonPanel width: " << (m_ButtonPanel->GetSize()).GetWidth());
00605                 DEBUG_INFO("New m_ButtonPanel Height: " << (m_ButtonPanel->GetSize()).GetHeight());
00606     }
00607     updatePano();
00608 }
00609 
00610 
00611 void PreviewFrame::OnClose(wxCloseEvent& event)
00612 {
00613     DEBUG_TRACE("OnClose")
00614     // do not close, just hide if we're not forced
00615     if (event.CanVeto()) {
00616         event.Veto();
00617         Hide();
00618         DEBUG_DEBUG("hiding");
00619     } else {
00620         DEBUG_DEBUG("closing");
00621         this->Destroy();
00622     }
00623 }
00624 
00625 void PreviewFrame::OnAutoPreviewToggle(wxCommandEvent & e)
00626 {
00627     m_PreviewPanel->SetAutoUpdate(e.IsChecked());
00628     if (e.IsChecked()) {
00629         m_PreviewPanel->ForceUpdate();
00630     }
00631 }
00632 
00633 #if 0
00634 // need to add the wxChoice somewhere
00635 void PreviewFrame::OnProjectionChanged()
00636 {
00637     PanoramaOptions opt = m_pano.getOptions();
00638     int lt = m_ProjectionChoice->GetSelection();
00639     wxString Ip;
00640     switch ( lt ) {
00641     case PanoramaOptions::RECTILINEAR:       Ip = _("Rectilinear"); break;
00642     case PanoramaOptions::CYLINDRICAL:       Ip = _("Cylindrical"); break;
00643     case PanoramaOptions::EQUIRECTANGULAR:   Ip = _("Equirectangular"); break;
00644     }
00645     opt.projectionFormat = (PanoramaOptions::ProjectionFormat) lt;
00646     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00647         new PanoCommand::SetPanoOptionsCmd( pano, opt )
00648         );
00649     DEBUG_DEBUG ("Projection changed: "  << lt << ":" << Ip )
00650 
00651 
00652 }
00653 #endif
00654 
00655 void PreviewFrame::OnCenterHorizontally(wxCommandEvent & e)
00656 {
00657     if (m_pano.getActiveImages().size() == 0) return;
00658 
00659     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00660         new PanoCommand::CenterPanoCmd(m_pano)
00661         );
00662 }
00663 
00664 void PreviewFrame::OnStraighten(wxCommandEvent & e)
00665 {
00666     if (m_pano.getNrOfImages() == 0) return;
00667 
00668     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00669         new PanoCommand::StraightenPanoCmd(m_pano)
00670         );
00671 }
00672 
00673 void PreviewFrame::OnUpdate(wxCommandEvent& event)
00674 {
00675     m_PreviewPanel->ForceUpdate();
00676 }
00677 
00678 void PreviewFrame::updatePano()
00679 {
00680     if (m_ToolBar->GetToolState(XRCID("preview_auto_update_tool"))) {
00681         m_PreviewPanel->ForceUpdate();
00682     }
00683 }
00684 
00685 void PreviewFrame::OnFitPano(wxCommandEvent & e)
00686 {
00687     if (m_pano.getActiveImages().size() == 0) return;
00688 
00689     DEBUG_TRACE("");
00690     HuginBase::PanoramaOptions opt = m_pano.getOptions();
00691     HuginBase::CalculateFitPanorama fitPano(m_pano);
00692     fitPano.run();
00693     opt.setHFOV(fitPano.getResultHorizontalFOV());
00694     opt.setHeight(hugin_utils::roundi(fitPano.getResultHeight()));
00695 
00696     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00697         new PanoCommand::SetPanoOptionsCmd( m_pano, opt )
00698         );
00699 
00700     DEBUG_INFO ( "new fov: [" << opt.getHFOV() << " "<< opt.getVFOV() << "] => height: " << opt.getHeight() );
00701     updatePano();
00702 }
00703 
00704 void PreviewFrame::OnShowAll(wxCommandEvent & e)
00705 {
00706     if (m_pano.getNrOfImages() == 0) return;
00707 
00708     DEBUG_ASSERT(m_pano.getNrOfImages() == m_ToggleButtons.size());
00709     HuginBase::UIntSet displayedImgs;
00710     for (unsigned int i=0; i < m_pano.getNrOfImages(); i++) {
00711         displayedImgs.insert(i);
00712     }
00713     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00714         new PanoCommand::SetActiveImagesCmd(m_pano, displayedImgs)
00715         );
00716     updatePano();
00717 }
00718 
00719 void PreviewFrame::OnShowNone(wxCommandEvent & e)
00720 {
00721     if (m_pano.getNrOfImages() == 0) return;
00722 
00723     DEBUG_ASSERT(m_pano.getNrOfImages() == m_ToggleButtons.size());
00724     for (unsigned int i=0; i < m_pano.getNrOfImages(); i++) {
00725         m_ToggleButtons[i]->SetValue(false);
00726     }
00727     HuginBase::UIntSet displayedImgs;
00728     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00729         new PanoCommand::SetActiveImagesCmd(m_pano, displayedImgs)
00730         );
00731     updatePano();
00732 }
00733 
00734 void PreviewFrame::OnNumTransform(wxCommandEvent & e)
00735 {
00736     if (m_pano.getNrOfImages() == 0) return;
00737 
00738     wxDialog dlg;
00739     wxXmlResource::Get()->LoadDialog(&dlg, this, wxT("dlg_numtrans"));
00740     dlg.CentreOnParent();
00741     if (dlg.ShowModal() == wxID_OK ) {
00742         wxString text = XRCCTRL(dlg, "numtrans_yaw", wxTextCtrl)->GetValue();
00743         double y;
00744         if (!hugin_utils::str2double(text, y)) {
00745             wxLogError(_("Yaw value must be numeric."));
00746             return;
00747         }
00748         text = XRCCTRL(dlg, "numtrans_pitch", wxTextCtrl)->GetValue();
00749         double p;
00750         if (!hugin_utils::str2double(text, p)) {
00751             wxLogError(_("Pitch value must be numeric."));
00752             return;
00753         }
00754         text = XRCCTRL(dlg, "numtrans_roll", wxTextCtrl)->GetValue();
00755         double r;
00756         if (!hugin_utils::str2double(text, r)) {
00757             wxLogError(_("Roll value must be numeric."));
00758             return;
00759         }
00760         PanoCommand::GlobalCmdHist::getInstance().addCommand(
00761             new PanoCommand::RotatePanoCmd(m_pano, y, p, r)
00762             );
00763         // update preview panel
00764         updatePano();
00765     } else {
00766         DEBUG_DEBUG("Numerical transform canceled");
00767     }
00768 }
00769 
00770 void PreviewFrame::OnTextCtrlChanged(wxCommandEvent & e)
00771 {
00772     HuginBase::PanoramaOptions opts = m_pano.getOptions();
00773     if (e.GetEventObject() == m_exposureTextCtrl) {
00774         // exposure
00775         wxString text = m_exposureTextCtrl->GetValue();
00776         DEBUG_INFO ("target exposure = " << text.mb_str(wxConvLocal) );
00777         double p = 0;
00778         if (text != wxT("")) {
00779             if (!hugin_utils::str2double(text, p)) {
00780                 wxLogError(_("Value must be numeric."));
00781                 return;
00782             }
00783         }
00784         opts.outputExposureValue = p;
00785     } else {
00786         int nParam = opts.m_projFeatures.numberOfParameters;
00787         std::vector<double> para = opts.getProjectionParameters();
00788         for (int i = 0; i < nParam; i++) {
00789             if (e.GetEventObject() == m_projParamTextCtrl[i]) {
00790                 wxString text = m_projParamTextCtrl[i]->GetValue();
00791                 DEBUG_INFO ("param " << i << ":  = " << text.mb_str(wxConvLocal) );
00792                 double p = 0;
00793                 if (text != wxT("")) {
00794                     if (!hugin_utils::str2double(text, p)) {
00795                         wxLogError(_("Value must be numeric."));
00796                         return;
00797                     }
00798                 }
00799                 para[i] = p;
00800             }
00801         }
00802         opts.setProjectionParameters(para);
00803     }
00804     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00805             new PanoCommand::SetPanoOptionsCmd( m_pano, opts )
00806                                            );
00807     // update preview panel
00808     updatePano();
00809 
00810 }
00811 
00812 void PreviewFrame::OnProjParameterReset(wxCommandEvent &e)
00813 {
00814     HuginBase::PanoramaOptions opts = m_pano.getOptions();
00815     opts.resetProjectionParameters();
00816     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00817         new PanoCommand::SetPanoOptionsCmd(m_pano, opts)
00818         );
00819 };
00820 
00821 void PreviewFrame::OnChangeFOV(wxScrollEvent & e)
00822 {
00823     DEBUG_TRACE("");
00824 
00825     HuginBase::PanoramaOptions opt = m_pano.getOptions();
00826 
00827     if (e.GetEventObject() == m_HFOVSlider) {
00828         DEBUG_DEBUG("HFOV changed (slider): " << e.GetInt() << " == " << m_HFOVSlider->GetValue());
00829         opt.setHFOV(e.GetInt());
00830     } else if (e.GetEventObject() == m_VFOVSlider) {
00831         DEBUG_DEBUG("VFOV changed (slider): " << e.GetInt());
00832         opt.setVFOV(e.GetInt());
00833     } else {
00834         int nParam = opt.m_projFeatures.numberOfParameters;
00835         std::vector<double> para = opt.getProjectionParameters();
00836         for (int i = 0; i < nParam; i++) {
00837             if (e.GetEventObject() == m_projParamSlider[i]) {
00838                 // update
00839                 para[i] = e.GetInt();
00840             }
00841         }
00842         opt.setProjectionParameters(para);
00843                 opt.setHFOV(m_HFOVSlider->GetValue());
00844                 opt.setVFOV(m_VFOVSlider->GetValue());
00845     }
00846 
00847     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00848         new PanoCommand::SetPanoOptionsCmd( m_pano, opt )
00849         );
00850 }
00851 
00852 void PreviewFrame::OnBlendChoice(wxCommandEvent & e)
00853 {
00854     if (e.GetEventObject() == m_BlendModeChoice) {
00855         int sel = e.GetSelection();
00856         switch (sel) {
00857         case 0:
00858             m_PreviewPanel->SetBlendMode(PreviewPanel::BLEND_COPY);
00859             break;
00860         case 1:
00861             m_PreviewPanel->SetBlendMode(PreviewPanel::BLEND_DIFFERENCE);
00862             break;
00863         default:
00864             DEBUG_WARN("Unknown blend mode selected");
00865         }
00866     } else {
00867         DEBUG_WARN("wxChoice event from unknown object received");
00868     }
00869 }
00870 
00871 
00872 void PreviewFrame::OnDefaultExposure( wxCommandEvent & e )
00873 {
00874     if (m_pano.getNrOfImages() > 0) {
00875         HuginBase::PanoramaOptions opt = m_pano.getOptions();
00876         opt.outputExposureValue = HuginBase::CalculateMeanExposure::calcMeanExposure(m_pano);
00877         PanoCommand::GlobalCmdHist::getInstance().addCommand(
00878                 new PanoCommand::SetPanoOptionsCmd( m_pano, opt )
00879                                                );
00880         updatePano();
00881     }
00882 }
00883 
00884 void PreviewFrame::OnIncreaseExposure( wxSpinEvent & e )
00885 {
00886     HuginBase::PanoramaOptions opt = m_pano.getOptions();
00887     opt.outputExposureValue = opt.outputExposureValue + 1.0/3;
00888     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00889             new PanoCommand::SetPanoOptionsCmd( m_pano, opt )
00890                                             );
00891     updatePano();
00892 }
00893 
00894 void PreviewFrame::OnDecreaseExposure( wxSpinEvent & e )
00895 {
00896     HuginBase::PanoramaOptions opt = m_pano.getOptions();
00897     opt.outputExposureValue = opt.outputExposureValue - 1.0/3;
00898     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00899             new PanoCommand::SetPanoOptionsCmd( m_pano, opt )
00900                                            );
00901     updatePano();
00902 }
00903 
00904 void PreviewFrame::OnProjectionChoice( wxCommandEvent & e )
00905 {
00906     if (e.GetEventObject() == m_ProjectionChoice) {
00907         HuginBase::PanoramaOptions opt = m_pano.getOptions();
00908         int lt = m_ProjectionChoice->GetSelection();
00909         wxString Ip;
00910         opt.setProjection((HuginBase::PanoramaOptions::ProjectionFormat) lt);
00911         PanoCommand::GlobalCmdHist::getInstance().addCommand(
00912                 new PanoCommand::SetPanoOptionsCmd( m_pano, opt )
00913                                             );
00914         DEBUG_DEBUG ("Projection changed: "  << lt);
00915         updatePano();
00916 
00917     } else {
00918         DEBUG_WARN("wxChoice event from unknown object received");
00919     }
00920 }
00921 
00922 void PreviewFrame::OnOutputChoice( wxCommandEvent & e)
00923 {
00924     if (e.GetEventObject() == m_outputModeChoice) {
00925         HuginBase::PanoramaOptions opt = m_pano.getOptions();
00926         int lt = m_outputModeChoice->GetSelection();
00927         wxString Ip;
00928         opt.outputMode = ((HuginBase::PanoramaOptions::OutputMode) lt);
00929         PanoCommand::GlobalCmdHist::getInstance().addCommand(
00930                 new PanoCommand::SetPanoOptionsCmd( m_pano, opt )
00931                                                );
00932         updatePano();
00933 
00934     } else {
00935         DEBUG_WARN("wxChoice event from unknown object received");
00936     }
00937 }
00938 
00940 void PreviewFrame::updateProgressDisplay()
00941 {
00942     wxString msg;
00943     if (!m_message.empty())
00944     {
00945         msg = wxGetTranslation(wxString(m_message.c_str(), wxConvLocal));
00946         if (!m_filename.empty())
00947         {
00948             msg.Append(wxT(" "));
00949             msg.Append(wxString(ProgressDisplay::m_filename.c_str(), HUGIN_CONV_FILENAME));
00950         };
00951     };
00952     GetStatusBar()->SetStatusText(msg, 0);
00953 
00954 #ifdef __WXMSW__
00955     UpdateWindow(NULL);
00956 #endif
00957 }
00958 
00959 void PreviewFrame::OnFullScreen(wxCommandEvent & e)
00960 {
00961     ShowFullScreen(!IsFullScreen(), wxFULLSCREEN_NOBORDER | wxFULLSCREEN_NOCAPTION);
00962 #ifdef __WXGTK__
00963     //workaround a wxGTK bug that also the toolbar is hidden, but not requested to hide
00964     GetToolBar()->Show(true);
00965 #endif
00966     m_PreviewPanel->ForceUpdate();
00967 };
00968 
00969 void PreviewFrame::OnUndo(wxCommandEvent &e)
00970 {
00971     if(PanoCommand::GlobalCmdHist::getInstance().canUndo())
00972     {
00973         wxCommandEvent dummy(wxEVT_COMMAND_MENU_SELECTED, XRCID("ID_EDITUNDO"));
00974         m_parent->GetEventHandler()->AddPendingEvent(dummy);
00975     }
00976     else
00977     {
00978         wxBell();
00979     };
00980 };
00981 
00982 void PreviewFrame::OnRedo(wxCommandEvent &e)
00983 {
00984     if(PanoCommand::GlobalCmdHist::getInstance().canRedo())
00985     {
00986         wxCommandEvent dummy(wxEVT_COMMAND_MENU_SELECTED, XRCID("ID_EDITREDO"));
00987         m_parent->GetEventHandler()->AddPendingEvent(dummy);
00988     }
00989     else
00990     {
00991         wxBell();
00992     };
00993 };
00994 

Generated on 3 May 2016 for Hugintrunk by  doxygen 1.4.7