PanoOutputDialog.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00011 /*  This is free software; you can redistribute it and/or
00012  *  modify it under the terms of the GNU General Public
00013  *  License as published by the Free Software Foundation; either
00014  *  version 2 of the License, or (at your option) any later version.
00015  *
00016  *  This software is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  *  Lesser General Public License for more details.
00020  *
00021  *  You should have received a copy of the GNU General Public
00022  *  License along with this software. If not, see
00023  *  <http://www.gnu.org/licenses/>.
00024  *
00025  */
00026 
00027 #include "hugin/PanoOutputDialog.h"
00028 #include "base_wx/wxPlatform.h"
00029 #include "panoinc.h"
00030 
00031 #include "hugin/huginApp.h"
00032 #include "base_wx/platform.h"
00033 #include "hugin/config_defaults.h"
00034 #include "algorithms/basic/LayerStacks.h"
00035 #include "algorithms/basic/CalculateOptimalScale.h"
00036 
00037 BEGIN_EVENT_TABLE(PanoOutputDialog,wxDialog)
00038     EVT_BUTTON(wxID_OK, PanoOutputDialog::OnOk)
00039     EVT_CHECKBOX(XRCID("output_normal"), PanoOutputDialog::OnOutputChanged)
00040     EVT_CHECKBOX(XRCID("output_fused_blended"), PanoOutputDialog::OnOutputChanged)
00041     EVT_CHECKBOX(XRCID("output_blended_fused"), PanoOutputDialog::OnOutputChanged)
00042     EVT_CHECKBOX(XRCID("output_hdr"), PanoOutputDialog::OnOutputChanged)
00043     EVT_CHOICE(XRCID("output_ldr_format"), PanoOutputDialog::OnLDRFormatChanged)
00044     EVT_CHOICE(XRCID("output_hdr_format"), PanoOutputDialog::OnHDRFormatChanged)
00045     EVT_SPINCTRL(XRCID("output_width"), PanoOutputDialog::OnWidthChanged)
00046     EVT_SPINCTRL(XRCID("output_height"), PanoOutputDialog::OnHeightChanged)
00047 END_EVENT_TABLE()
00048 
00049 PanoOutputDialog::PanoOutputDialog(wxWindow *parent, HuginBase::Panorama& pano, GuiLevel guiLevel) : m_pano(pano), m_aspect(0)
00050 {
00051     // load our children. some children might need special
00052     // initialization. this will be done later.
00053     wxXmlResource::Get()->LoadDialog(this, parent, wxT("pano_output_dialog"));
00054 
00055 #ifdef __WXMSW__
00056     wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/hugin.ico"),wxBITMAP_TYPE_ICO);
00057 #else
00058     wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/hugin.png"),wxBITMAP_TYPE_PNG);
00059 #endif
00060     SetIcon(myIcon);
00061     //set parameters
00062     wxConfigBase * cfg = wxConfigBase::Get();
00063     //position
00064     int x = cfg->Read(wxT("/PanoOutputDialog/positionX"),-1l);
00065     int y = cfg->Read(wxT("/PanoOutputDialog/positionY"),-1l);
00066     if ( y >= 0 && x >= 0) 
00067     {
00068         this->Move(x, y);
00069     } 
00070     else 
00071     {
00072         this->Move(0, 44);
00073     };
00074     // get number of stacks and exposure layers
00075     m_guiLevel=guiLevel;
00076     HuginBase::UIntSet images=getImagesinROI(m_pano, m_pano.getActiveImages());
00077     m_stacks=getHDRStacks(m_pano, images, m_pano.getOptions());
00078     m_exposureLayers=getExposureLayers(m_pano, images, m_pano.getOptions());
00079     // set initial width
00080     m_newOpt = m_pano.getOptions();
00081     long opt_width = hugin_utils::roundi(HuginBase::CalculateOptimalScale::calcOptimalScale(m_pano) * m_newOpt.getWidth());
00082 
00083     double sizeFactor = HUGIN_ASS_PANO_DOWNSIZE_FACTOR;
00084     wxConfigBase* config = wxConfigBase::Get();
00085     config->Read(wxT("/Assistant/panoDownsizeFactor"), &sizeFactor, HUGIN_ASS_PANO_DOWNSIZE_FACTOR);
00086     m_newOpt.setWidth(hugin_utils::floori(sizeFactor*opt_width), true);
00087     m_initalWidth=m_newOpt.getWidth();
00088     m_initalROIWidth=m_newOpt.getROI().width();
00089     m_aspect=(double)m_newOpt.getROI().height()/m_newOpt.getROI().width();
00090     m_edit_width=XRCCTRL(*this, "output_width", wxSpinCtrl);
00091     m_edit_height=XRCCTRL(*this, "output_height", wxSpinCtrl);
00092     m_edit_width->SetValue(m_newOpt.getROI().width());
00093     m_edit_height->SetValue(m_newOpt.getROI().height());
00094 
00095     //LDR output format, as in preferences set
00096     int i = config->Read(wxT("/output/jpeg_quality"),HUGIN_JPEG_QUALITY);
00097     XRCCTRL(*this, "output_jpeg_quality", wxSpinCtrl)->SetValue(i);
00098     i=config->Read(wxT("/output/tiff_compression"), HUGIN_TIFF_COMPRESSION);
00099     XRCCTRL(*this, "output_tiff_compression", wxChoice)->SetSelection(i);
00100     i=config->Read(wxT("/output/ldr_format"), HUGIN_LDR_OUTPUT_FORMAT);
00101     XRCCTRL(*this, "output_ldr_format", wxChoice)->SetSelection(i);
00102     //HDR output format, as in project given
00103     if (m_newOpt.outputImageTypeHDR == "exr")
00104     {
00105         XRCCTRL(*this, "output_hdr_format", wxChoice)->SetSelection(0);
00106         XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->SetSelection(2);
00107     }
00108     else
00109     {
00110         XRCCTRL(*this, "output_hdr_format", wxChoice)->SetSelection(1);
00111         if (m_newOpt.outputImageTypeHDRCompression  == "PACKBITS")
00112         {
00113             XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->SetSelection(1);
00114         }
00115         else
00116         {
00117             if (m_newOpt.outputImageTypeHDRCompression == "LZW")
00118             {
00119                 XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->SetSelection(2);
00120             }
00121             else
00122             {
00123                 if (m_newOpt.outputImageTypeHDRCompression  == "DEFLATE")
00124                 {
00125                     XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->SetSelection(3);
00126                 }
00127                 else
00128                 {
00129                     XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->SetSelection(0);
00130                 };
00131             };
00132         };
00133     };
00134     EnableOutputOptions();
00135     wxCommandEvent dummy;
00136     OnOutputChanged(dummy);
00137     OnLDRFormatChanged(dummy);
00138     OnHDRFormatChanged(dummy);
00139 };
00140 
00141 PanoOutputDialog::~PanoOutputDialog()
00142 {
00143     wxConfigBase * cfg = wxConfigBase::Get();
00144     wxPoint ps = this->GetPosition();
00145     cfg->Write(wxT("/PanoOutputDialog/positionX"), ps.x);
00146     cfg->Write(wxT("/PanoOutputDialog/positionY"), ps.y);
00147     cfg->Flush();
00148 };
00149 
00150 void PanoOutputDialog::EnableOutputOptions()
00151 {
00152     // check, if hdr images
00153     wxFileName file1(wxString(m_pano.getImage(0).getFilename().c_str(), HUGIN_CONV_FILENAME));
00154     wxString ext1=file1.GetExt().Lower();
00155     if(ext1==wxT(".hdr") || ext1==wxT(".exr"))
00156     {
00157         XRCCTRL(*this, "output_hdr", wxCheckBox)->SetValue(true);
00158         XRCCTRL(*this, "output_hdr", wxCheckBox)->Enable(true);
00159         XRCCTRL(*this, "output_hdr_bitmap", wxStaticBitmap)->Enable(true);
00160         return;
00161     }
00162     //hide hdr controls for simple interface
00163     if(m_guiLevel==GUI_SIMPLE)
00164     {
00165         XRCCTRL(*this, "output_hdr", wxCheckBox)->Hide();
00166         XRCCTRL(*this, "output_hdr_bitmap", wxStaticBitmap)->Hide();
00167         XRCCTRL(*this, "output_hdr_format_label", wxStaticText)->Hide();
00168         XRCCTRL(*this, "output_hdr_format", wxChoice)->Hide();
00169         XRCCTRL(*this, "output_hdr_compression_label", wxStaticText)->Hide();
00170         XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->Hide();
00171         Layout();
00172         GetSizer()->Fit(this);
00173     };
00174     //single image or normal panorama, enable only normal output
00175     if(m_pano.getNrOfImages()==1 || m_stacks.size() >= 0.8 * m_pano.getNrOfImages())
00176     {
00177         XRCCTRL(*this, "output_normal", wxCheckBox)->SetValue(true);
00178         XRCCTRL(*this, "output_normal", wxCheckBox)->Enable(true);
00179         XRCCTRL(*this, "output_normal_bitmap", wxStaticBitmap)->Enable(true);
00180         if(m_pano.getNrOfImages()==1 || m_stacks.size()==m_pano.getNrOfImages())
00181         {
00182             return;
00183         };
00184     };
00185     XRCCTRL(*this, "output_fused_blended", wxCheckBox)->Enable(true);
00186     XRCCTRL(*this, "output_fused_blended_bitmap", wxStaticBitmap)->Enable(true);
00187     XRCCTRL(*this, "output_blended_fused", wxCheckBox)->Enable(true);
00188     XRCCTRL(*this, "output_blended_fused_bitmap", wxStaticBitmap)->Enable(true);
00189     if(m_guiLevel!=GUI_SIMPLE)
00190     {
00191         XRCCTRL(*this, "output_hdr", wxCheckBox)->Enable(true);
00192         XRCCTRL(*this, "output_hdr_bitmap", wxStaticBitmap)->Enable(true);
00193     };
00194     if(m_pano.getNrOfImages() % m_stacks.size() == 0)
00195     {
00196         XRCCTRL(*this, "output_fused_blended", wxCheckBox)->SetValue(true);
00197     }
00198     else
00199     {
00200         if(m_exposureLayers.size()==1)
00201         {
00202             XRCCTRL(*this, "output_normal", wxCheckBox)->SetValue(true);
00203         }
00204         else
00205         {
00206             XRCCTRL(*this, "output_blended_fused", wxCheckBox)->SetValue(true);
00207         };
00208     };
00209 };
00210 
00211 void PanoOutputDialog::OnOk(wxCommandEvent & e)
00212 {
00213     bool output_normal=XRCCTRL(*this, "output_normal", wxCheckBox)->GetValue();
00214     bool output_fused_blended=XRCCTRL(*this, "output_fused_blended", wxCheckBox)->GetValue();
00215     bool output_blended_fused=XRCCTRL(*this, "output_blended_fused", wxCheckBox)->GetValue();
00216     bool output_hdr=XRCCTRL(*this, "output_hdr", wxCheckBox)->GetValue();
00217     bool keep_intermediate=XRCCTRL(*this, "output_keep_intermediate", wxCheckBox)->GetValue();
00218     //normal output
00219     m_newOpt.outputLDRBlended=output_normal;
00220     m_newOpt.outputLDRLayers=output_normal && keep_intermediate;
00221     //fused stacks, then blended
00222     m_newOpt.outputLDRExposureBlended=output_fused_blended;
00223     m_newOpt.outputLDRExposureRemapped=(output_fused_blended || output_blended_fused) && keep_intermediate;
00224     m_newOpt.outputLDRStacks=output_fused_blended && keep_intermediate;
00225     // blended exposure layers, then fused
00226     m_newOpt.outputLDRExposureLayersFused=output_blended_fused;
00227     m_newOpt.outputLDRExposureLayers=output_blended_fused && keep_intermediate;
00228     // HDR output
00229     m_newOpt.outputHDRBlended=output_hdr;
00230     m_newOpt.outputHDRLayers=output_hdr && keep_intermediate;
00231     m_newOpt.outputHDRStacks=output_hdr && keep_intermediate;
00232     // read compression
00233     if(output_normal || output_fused_blended || output_blended_fused)
00234     {
00235         if(m_newOpt.outputImageType=="jpg")
00236         {
00237             m_newOpt.quality=XRCCTRL(*this, "output_jpeg_quality", wxSpinCtrl)->GetValue();
00238         }
00239         else
00240         {
00241             if(m_newOpt.outputImageType=="tif")
00242             {
00243                 switch(XRCCTRL(*this, "output_tiff_compression", wxChoice)->GetSelection())
00244                 {
00245                     case 0:
00246                     default:
00247                         m_newOpt.outputImageTypeCompression = "NONE";
00248                         m_newOpt.tiffCompression = "NONE";
00249                         break;
00250                     case 1:
00251                         m_newOpt.outputImageTypeCompression = "PACKBITS";
00252                         m_newOpt.tiffCompression = "PACKBITS";
00253                         break;
00254                     case 2:
00255                         m_newOpt.outputImageTypeCompression = "LZW";
00256                         m_newOpt.tiffCompression = "LZW";
00257                         break;
00258                     case 3:
00259                         m_newOpt.outputImageTypeCompression = "DEFLATE";
00260                         m_newOpt.tiffCompression = "DEFLATE";
00261                         break;
00262                 };
00263             };
00264         };
00265     };
00266     //HDR compression
00267     if(output_hdr)
00268     {
00269         if(m_newOpt.outputImageTypeHDR=="tif")
00270         {
00271             switch(XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->GetSelection())
00272             {
00273                 case 0:
00274                 default:
00275                     m_newOpt.outputImageTypeHDRCompression = "NONE";
00276                     break;
00277                 case 1:
00278                     m_newOpt.outputImageTypeHDRCompression = "PACKBITS";
00279                     break;
00280                 case 2:
00281                     m_newOpt.outputImageTypeHDRCompression = "LZW";
00282                     break;
00283                 case 3:
00284                     m_newOpt.outputImageTypeHDRCompression = "DEFLATE";
00285                     break;
00286             };
00287         };
00288     }
00289     // canvas size
00290     double scale=m_edit_width->GetValue()/m_initalROIWidth;
00291     m_newOpt.setWidth(hugin_utils::roundi(m_initalWidth*scale), true);
00292     //some checks to prevent some rounding errors, only for cropped outputs
00293     if(m_initalROIWidth < m_initalWidth)
00294     {
00295         if(m_newOpt.getROI().width()<m_edit_width->GetValue() || m_newOpt.getROI().height()<m_edit_height->GetValue())
00296         {
00297             m_newOpt.setWidth(m_newOpt.getWidth()+1, true);
00298         };
00299         vigra::Rect2D roi=m_newOpt.getROI();
00300         if(roi.width()>m_edit_width->GetValue() || roi.height()>m_edit_height->GetValue())
00301         {
00302             roi.setSize(m_edit_width->GetValue(), m_edit_height->GetValue());
00303             m_newOpt.setROI(roi);
00304         };
00305     };
00306     //send Ok
00307     EndModal(wxID_OK);
00308 };
00309 
00310 void PanoOutputDialog::OnOutputChanged(wxCommandEvent & e)
00311 {
00312     bool output_normal=XRCCTRL(*this, "output_normal", wxCheckBox)->GetValue();
00313     bool output_fused_blended=XRCCTRL(*this, "output_fused_blended", wxCheckBox)->GetValue();
00314     bool output_blended_fused=XRCCTRL(*this, "output_blended_fused", wxCheckBox)->GetValue();
00315     bool output_hdr=XRCCTRL(*this, "output_hdr", wxCheckBox)->GetValue();
00316     //enable Ok only if at least one option is enabled
00317     XRCCTRL(*this, "wxID_OK", wxButton)->Enable(output_normal || output_fused_blended || output_blended_fused || output_hdr);
00318     XRCCTRL(*this, "output_ldr_format_label", wxStaticText)->Enable(output_normal || output_fused_blended || output_blended_fused);
00319     XRCCTRL(*this, "output_ldr_format", wxChoice)->Enable(output_normal || output_fused_blended || output_blended_fused);
00320     XRCCTRL(*this, "output_ldr_compression_label", wxStaticText)->Enable(output_normal || output_fused_blended || output_blended_fused);
00321     XRCCTRL(*this, "output_jpeg_quality", wxSpinCtrl)->Enable(output_normal || output_fused_blended || output_blended_fused);
00322     XRCCTRL(*this, "output_tiff_compression", wxChoice)->Enable(output_normal || output_fused_blended || output_blended_fused);
00323     XRCCTRL(*this, "output_hdr_format_label", wxStaticText)->Enable(output_hdr);
00324     XRCCTRL(*this, "output_hdr_format", wxChoice)->Enable(output_hdr);
00325     XRCCTRL(*this, "output_hdr_compression_label", wxStaticText)->Enable(output_hdr);
00326     XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->Enable(output_hdr);
00327     GetSizer()->Layout();
00328 };
00329 
00330 void PanoOutputDialog::OnLDRFormatChanged(wxCommandEvent & e)
00331 {
00332     int sel = XRCCTRL(*this, "output_ldr_format", wxChoice)->GetSelection();
00333     switch (sel)
00334     {
00335         case 1:
00336             m_newOpt.outputImageType ="jpg";
00337             XRCCTRL(*this, "output_ldr_compression_label", wxStaticText)->Show();
00338             XRCCTRL(*this, "output_ldr_compression_label", wxStaticText)->SetLabel(_("Quality:"));
00339             XRCCTRL(*this, "output_jpeg_quality", wxSpinCtrl)->Show();
00340             XRCCTRL(*this, "output_tiff_compression", wxChoice)->Hide();
00341             break;
00342         case 2:
00343             m_newOpt.outputImageType ="png";
00344             XRCCTRL(*this, "output_ldr_compression_label", wxStaticText)->Hide();
00345             XRCCTRL(*this, "output_jpeg_quality", wxSpinCtrl)->Hide();
00346             XRCCTRL(*this, "output_tiff_compression", wxChoice)->Hide();
00347             break;
00348         default:
00349         case 0:
00350             m_newOpt.outputImageType ="tif";
00351             XRCCTRL(*this, "output_ldr_compression_label", wxStaticText)->Show();
00352             XRCCTRL(*this, "output_ldr_compression_label", wxStaticText)->SetLabel(_("Compression:"));
00353             XRCCTRL(*this, "output_jpeg_quality", wxSpinCtrl)->Hide();
00354             XRCCTRL(*this, "output_tiff_compression", wxChoice)->Show();
00355             break;
00356     };
00357     GetSizer()->Layout();
00358 };
00359 
00360 
00361 void PanoOutputDialog::OnHDRFormatChanged(wxCommandEvent & e)
00362 {
00363     int sel = XRCCTRL(*this, "output_hdr_format", wxChoice)->GetSelection();
00364     switch (sel)
00365     {
00366         case 1:
00367             m_newOpt.outputImageTypeHDR="tif";
00368             XRCCTRL(*this, "output_hdr_compression_label", wxStaticText)->Show();
00369             XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->Show();
00370             break;
00371         case 0:
00372         default:
00373             m_newOpt.outputImageTypeHDR="exr";
00374             XRCCTRL(*this, "output_hdr_compression_label", wxStaticText)->Hide();
00375             XRCCTRL(*this, "output_hdr_tiff_compression", wxChoice)->Hide();
00376             break;
00377     };
00378     GetSizer()->Layout();
00379 };
00380 
00381 void PanoOutputDialog::OnWidthChanged(wxSpinEvent & e)
00382 {
00383     if(m_aspect>0)
00384     {
00385         m_edit_height->SetValue(m_edit_width->GetValue()*m_aspect);
00386     };
00387 };
00388 
00389 void PanoOutputDialog::OnHeightChanged(wxSpinEvent & e)
00390 {
00391     if(m_aspect>0)
00392     {
00393         m_edit_width->SetValue(m_edit_height->GetValue()/m_aspect);
00394     };
00395 };

Generated on 30 Jul 2015 for Hugintrunk by  doxygen 1.4.7