~ubuntu-branches/ubuntu/trusty/hugin/trusty-proposed

« back to all changes in this revision

Viewing changes to src/hugin1/hugin/PanoPanel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Metzler
  • Date: 2011-01-06 14:28:24 UTC
  • mfrom: (1.1.9 upstream) (0.1.21 experimental)
  • Revision ID: james.westby@ubuntu.com-20110106142824-zn9lxylg5z44dynn
* Drop Cyril Brulebois from Uploaders. Thank you very much for your work.
* Bump package version. (rc3 was re-released as 2010.4.0).

Show diffs side-by-side

added added

removed removed

Lines of Context:
226
226
 
227
227
    m_FileFormatChoice = XRCCTRL(*this, "pano_choice_file_format", wxChoice);
228
228
    DEBUG_ASSERT(m_FileFormatChoice);
229
 
    m_FileFormatPanelJPEG = XRCCTRL(*this, "pano_output_normal_opts_jpeg", wxPanel);
230
 
    DEBUG_ASSERT(m_FileFormatPanelJPEG);
 
229
    m_FileFormatOptionsLabel = XRCCTRL(*this, "pano_output_ldr_format_options_label", wxStaticText);
 
230
    
231
231
    m_FileFormatJPEGQualityText = XRCCTRL(*this, "pano_output_normal_opts_jpeg_quality", wxTextCtrl);
232
232
    DEBUG_ASSERT(m_FileFormatJPEGQualityText);
233
233
    m_FileFormatJPEGQualityText->PushEventHandler(new TextKillFocusHandler(this));
234
234
 
235
 
    m_FileFormatPanelTIFF = XRCCTRL(*this, "pano_output_normal_opts_tiff", wxPanel);
236
 
    DEBUG_ASSERT(m_FileFormatPanelTIFF);
237
235
    m_FileFormatTIFFCompChoice = XRCCTRL(*this, "pano_output_normal_opts_tiff_compression", wxChoice);
238
236
    DEBUG_ASSERT(m_FileFormatTIFFCompChoice);
239
237
 
240
238
    m_HDRFileFormatChoice = XRCCTRL(*this, "pano_choice_hdr_file_format", wxChoice);
241
239
    DEBUG_ASSERT(m_HDRFileFormatChoice);
242
 
    m_HDRFileFormatPanelTIFF = XRCCTRL(*this, "pano_output_hdr_opts_tiff", wxPanel);
243
 
    DEBUG_ASSERT(m_HDRFileFormatPanelTIFF);
 
240
    m_HDRFileFormatLabelTIFFCompression = XRCCTRL(*this, "pano_output_hdr_opts_tiff_compression_label", wxStaticText);
 
241
    DEBUG_ASSERT(m_HDRFileFormatLabelTIFFCompression);
244
242
    m_FileFormatHDRTIFFCompChoice = XRCCTRL(*this, "pano_output_hdr_opts_tiff_compression", wxChoice);
245
243
    DEBUG_ASSERT(m_FileFormatHDRTIFFCompChoice);
246
244
 
279
277
    m_HFOVText->PopEventHandler(true);
280
278
    m_VFOVText->PopEventHandler(true);
281
279
    m_WidthTxt->PopEventHandler(true);
 
280
    m_HeightTxt->PopEventHandler(true);
282
281
    m_ROILeftTxt->PopEventHandler(true);
283
282
    m_ROIRightTxt->PopEventHandler(true);
284
283
    m_ROITopTxt->PopEventHandler(true);
292
291
void PanoPanel::panoramaChanged (PT::Panorama &pano)
293
292
{
294
293
    DEBUG_TRACE("");
295
 
        bool hasImages = pano.getActiveImages().size() > 0;
296
 
    m_StitchButton->Enable(hasImages);
297
 
        m_BatchButton->Enable(hasImages);
298
294
 
299
295
#ifdef STACK_CHECK //Disabled for 0.7.0 release
300
296
    const bool hasStacks = StackCheck(pano);
391
387
    m_ROITopTxt->SetValue(wxString::Format(wxT("%d"), opt.getROI().top() ));
392
388
    m_ROIBottomTxt->SetValue(wxString::Format(wxT("%d"), opt.getROI().bottom() ));
393
389
 
394
 
    //do not stitch unless there are active images
395
 
    m_StitchButton->Enable(hasImages);
396
 
 
397
390
    // output types
398
391
    XRCCTRL(*this, "pano_cb_ldr_output_blended",
399
392
            wxCheckBox)->SetValue(opt.outputLDRBlended);
424
417
                              opt.outputHDRStacks || 
425
418
                              opt.outputHDRLayers);
426
419
    
427
 
    if (m_StitchButton->IsEnabled()) {
428
 
        if(!anyOutputSelected)
429
 
            m_StitchButton->Disable();
430
 
    } else {
431
 
        if(anyOutputSelected)
432
 
            m_StitchButton->Enable();
433
 
    }
 
420
    //do not let the user stitch unless there are active images and an output selected.
 
421
    bool any_output_possible = hasImages && anyOutputSelected;
 
422
    m_StitchButton->Enable(any_output_possible);
 
423
    m_BatchButton->Enable(any_output_possible);
434
424
 
435
425
#ifdef STACK_CHECK //Disabled for 0.7.0 release
436
426
    if (hasStacks) {
464
454
                          opt.outputLDRExposureLayers || 
465
455
                          opt.outputHDRBlended;
466
456
 
467
 
    m_BlenderChoice->Show(blenderEnabled);
468
 
    XRCCTRL(*this, "pano_button_blender_opts", wxButton)->Show(blenderEnabled);
469
 
    XRCCTRL(*this, "pano_text_blender", wxStaticText)->Show(blenderEnabled);
 
457
    m_BlenderChoice->Enable(blenderEnabled);
 
458
    XRCCTRL(*this, "pano_button_blender_opts", wxButton)->Enable(blenderEnabled);
 
459
    XRCCTRL(*this, "pano_text_blender", wxStaticText)->Enable(blenderEnabled);
470
460
 
471
461
    bool fusionEnabled = (opt.outputLDRExposureBlended || opt.outputLDRExposureLayersFused);
472
 
    m_FusionChoice->Show(fusionEnabled);
473
 
    XRCCTRL(*this, "pano_button_fusion_opts", wxButton)->Show(fusionEnabled);
474
 
    XRCCTRL(*this, "pano_text_fusion", wxStaticText)->Show(fusionEnabled);
 
462
    m_FusionChoice->Enable(fusionEnabled);
 
463
    XRCCTRL(*this, "pano_button_fusion_opts", wxButton)->Enable(fusionEnabled);
 
464
    XRCCTRL(*this, "pano_text_fusion", wxStaticText)->Enable(fusionEnabled);
475
465
 
476
466
    bool hdrMergeEnabled = opt.outputHDRBlended || opt.outputHDRStacks;
477
 
    m_HDRMergeChoice->Show(hdrMergeEnabled);
478
 
    XRCCTRL(*this, "pano_button_hdrmerge_opts", wxButton)->Show(hdrMergeEnabled);
479
 
    XRCCTRL(*this, "pano_text_hdrmerge", wxStaticText)->Show(hdrMergeEnabled);
 
467
    m_HDRMergeChoice->Enable(hdrMergeEnabled);
 
468
    XRCCTRL(*this, "pano_button_hdrmerge_opts", wxButton)->Enable(hdrMergeEnabled);
 
469
    XRCCTRL(*this, "pano_text_hdrmerge", wxStaticText)->Enable(hdrMergeEnabled);
480
470
 
481
471
    // output file mode
 
472
    bool ldr_pano_enabled = opt.outputLDRBlended ||
 
473
                            opt.outputLDRExposureBlended ||
 
474
                            opt.outputLDRExposureLayersFused;
 
475
    
 
476
    XRCCTRL(*this, "pano_output_ldr_format_label", wxStaticText)->Enable(ldr_pano_enabled);
 
477
    m_FileFormatOptionsLabel->Enable(ldr_pano_enabled);
 
478
    m_FileFormatChoice->Enable(ldr_pano_enabled);
 
479
    m_FileFormatJPEGQualityText->Enable(ldr_pano_enabled);
 
480
    m_FileFormatTIFFCompChoice->Enable(ldr_pano_enabled);
 
481
    
482
482
    long i=0;
483
483
    if (opt.outputImageType == "tif") {
484
484
        i = 0;
485
 
        m_FileFormatPanelJPEG->Hide();
486
 
        m_FileFormatPanelTIFF->Show();
 
485
        m_FileFormatOptionsLabel->Show();
 
486
        m_FileFormatOptionsLabel->SetLabel(_("Compression:"));
 
487
        m_FileFormatJPEGQualityText->Hide();
 
488
        m_FileFormatTIFFCompChoice->Show();
487
489
        if (opt.outputImageTypeCompression  == "PACKBITS") {
488
490
            m_FileFormatTIFFCompChoice->SetSelection(1);
489
491
        } else if (opt.outputImageTypeCompression == "LZW") {
490
492
            m_FileFormatTIFFCompChoice->SetSelection(2);
491
 
        } else if (opt.outputImageTypeCompression  == "DEFLATE") {
 
493
        } else if (opt.outputImageTypeCompression  == "DEFLATE") {
492
494
            m_FileFormatTIFFCompChoice->SetSelection(3);
493
495
        } else {
494
496
            m_FileFormatTIFFCompChoice->SetSelection(0);
495
497
        }
496
498
    } else if (opt.outputImageType == "jpg") {
497
499
        i = 1;
498
 
        m_FileFormatPanelJPEG->Show();
499
 
        m_FileFormatPanelTIFF->Hide();
 
500
        m_FileFormatOptionsLabel->Show();
 
501
        m_FileFormatOptionsLabel->SetLabel(_("Quality:"));
 
502
        m_FileFormatJPEGQualityText->Show();
 
503
        m_FileFormatTIFFCompChoice->Hide();
500
504
        m_FileFormatJPEGQualityText->SetValue(wxString::Format(wxT("%d"), opt.quality));
501
505
    } else if (opt.outputImageType == "png") {
502
 
        m_FileFormatPanelJPEG->Hide();
503
 
        m_FileFormatPanelTIFF->Hide();
 
506
        m_FileFormatOptionsLabel->Hide();
 
507
        m_FileFormatJPEGQualityText->Hide();
 
508
        m_FileFormatTIFFCompChoice->Hide();
504
509
        i = 2;
505
510
    } else if (opt.outputImageType == "exr") {
506
 
        m_FileFormatPanelJPEG->Hide();
507
 
        m_FileFormatPanelTIFF->Hide();
 
511
        /// @todo Is this right? I don't see a 4th item in the combo box, and exr is a confusing LDR format.
 
512
        m_FileFormatOptionsLabel->Hide();
 
513
        m_FileFormatJPEGQualityText->Hide();
 
514
        m_FileFormatTIFFCompChoice->Hide();
508
515
        i = 3;
509
516
    } else
510
517
        wxLogError(wxT("INTERNAL error: unknown output image type"));
511
518
 
512
519
    m_FileFormatChoice->SetSelection(i);
513
520
 
 
521
    bool hdr_pano_enabled = opt.outputHDRBlended;
 
522
    
 
523
    XRCCTRL(*this, "pano_output_hdr_format_label", wxStaticText)->Enable(hdr_pano_enabled);
 
524
    m_HDRFileFormatChoice->Enable(hdr_pano_enabled);
 
525
    m_HDRFileFormatLabelTIFFCompression->Enable(hdr_pano_enabled);
 
526
    m_FileFormatHDRTIFFCompChoice->Enable(hdr_pano_enabled);
 
527
    
514
528
    i=0;
515
529
    if (opt.outputImageTypeHDR == "exr") {
516
530
        i = 0;
517
 
        m_HDRFileFormatPanelTIFF->Hide();
 
531
        m_HDRFileFormatLabelTIFFCompression->Hide();
 
532
        m_FileFormatHDRTIFFCompChoice->Hide();
518
533
    } else if (opt.outputImageTypeHDR == "tif") {
519
534
        i = 1;
520
 
        m_HDRFileFormatPanelTIFF->Show();
 
535
        m_HDRFileFormatLabelTIFFCompression->Show();
 
536
        m_FileFormatHDRTIFFCompChoice->Show();
521
537
        if (opt.outputImageTypeHDRCompression  == "PACKBITS") {
522
538
            m_FileFormatHDRTIFFCompChoice->SetSelection(1);
523
539
        } else if (opt.outputImageTypeHDRCompression == "LZW") {
524
540
            m_FileFormatHDRTIFFCompChoice->SetSelection(2);
525
 
        } else if (opt.outputImageTypeHDRCompression  == "DEFLATE") {
 
541
        } else if (opt.outputImageTypeHDRCompression  == "DEFLATE") {
526
542
            m_FileFormatHDRTIFFCompChoice->SetSelection(3);
527
543
        } else {
528
544
            m_FileFormatHDRTIFFCompChoice->SetSelection(0);
962
978
    if (pano->getNrOfImages() == 0) {
963
979
        return;
964
980
    }
 
981
    
 
982
    if (!CheckGoodSize()) {
 
983
        // oversized pano and the user no longer wants to stitch.
 
984
        return;
 
985
    }
965
986
 
966
987
    // save project
967
988
    // copy pto file to temporary file
1004
1025
    wxString hugin_stitch_project = wxT("hugin_stitch_project");
1005
1026
#endif
1006
1027
 
1007
 
/*
1008
 
    wxFileName prefixFN(ptofile);
 
1028
    // Derive a default output prefix from the project filename if set, otherwise default project filename
 
1029
    wxString ptofile = MainFrame::Get()->getProjectName();
1009
1030
    wxString outputPrefix;
1010
 
    if (prefixFN.GetExt() == wxT("pto")) {
1011
 
        outputPrefix = prefixFN.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR, wxPATH_NATIVE) + prefixFN.GetName();
 
1031
    if (ptofile  == wxT("")) {
 
1032
         outputPrefix = getDefaultProjectName(*pano);
1012
1033
    } else {
1013
 
        outputPrefix = ptofile;
1014
 
    }
1015
 
*/
1016
 
 
1017
 
    //TODO: don't overwrite files without warning!
1018
 
    // wxString command = hugin_stitch_project + wxT(" -o ") + wxQuoteFilename(outputPrefix) + wxT(" ") + wxQuoteFilename(ptofile);
1019
 
    wxString command = hugin_stitch_project + wxT(" -d ") + wxQuoteFilename(currentPTOfn);
 
1034
        wxFileName prefixFN(ptofile);
 
1035
        if (prefixFN.GetExt() == wxT("pto")) {
 
1036
            outputPrefix = prefixFN.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR, wxPATH_NATIVE) + prefixFN.GetName();
 
1037
        } else {
 
1038
            outputPrefix = ptofile;
 
1039
        }
 
1040
    }
 
1041
 
 
1042
    // Show a file save dialog so user can confirm/change the prefix.
 
1043
    // (We don't have to worry about overwriting existing files, since hugin_switch_project checks this.)
 
1044
    // TODO: The following code is similar to stitchApp::OnInit in hugin_switch_project.cpp. Should be refactored.
 
1045
    // TODO: We should save the output prefix somewhere, so we can recall it as the default if the user stitches this project again.
 
1046
    {
 
1047
        wxFileDialog dlg(this,_("Specify output prefix"),
 
1048
                         wxConfigBase::Get()->Read(wxT("/actualPath"),wxT("")),
 
1049
                         outputPrefix, wxT(""),
 
1050
                         wxFD_SAVE, wxDefaultPosition);
 
1051
        dlg.SetDirectory(wxConfigBase::Get()->Read(wxT("/actualPath"),wxT("")));
 
1052
        while (true) {
 
1053
            if (dlg.ShowModal() != wxID_OK)
 
1054
                 return; // bail
 
1055
            if (containsInvalidCharacters(dlg.GetPath())) {
 
1056
                wxMessageBox(wxString::Format(_("The given filename contains one of the following invalid characters: %s\nHugin can not work with this filename. Please enter a valid filename."),getInvalidCharacters().c_str()),
 
1057
                    _("Error"),wxOK | wxICON_EXCLAMATION);
 
1058
            } else { // successful
 
1059
                wxConfig::Get()->Write(wxT("/actualPath"), dlg.GetDirectory());  // remember for later
 
1060
                outputPrefix = dlg.GetPath();
 
1061
                break;
 
1062
            }
 
1063
        }
 
1064
    }
 
1065
 
 
1066
    wxString command = hugin_stitch_project + wxT(" -o ") + wxQuoteFilename(outputPrefix) + wxT(" ") + wxQuoteFilename(currentPTOfn);
1020
1067
    
1021
1068
    wxConfigBase::Get()->Flush();
1022
1069
#ifdef __WXGTK__
1088
1135
 
1089
1136
void PanoPanel::OnSendToBatch ( wxCommandEvent & e )
1090
1137
{
 
1138
    if (!CheckGoodSize()) {
 
1139
        return;
 
1140
    }
1091
1141
        wxCommandEvent dummy;
1092
1142
        MainFrame::Get()->OnSaveProject(dummy);
1093
1143
        wxString projectFile = MainFrame::Get()->getProjectName();
1128
1178
    PanoramaOptions opt = pano->getOptions();
1129
1179
    switch (fmt) {
1130
1180
        case 1:
1131
 
            m_FileFormatPanelJPEG->Show();
1132
 
            m_FileFormatPanelTIFF->Hide();
1133
1181
            opt.outputImageType ="jpg";
1134
1182
            break;
1135
1183
        case 2:
1136
 
            m_FileFormatPanelJPEG->Hide();
1137
 
            m_FileFormatPanelTIFF->Hide();
1138
1184
            opt.outputImageType ="png";
1139
1185
            break;
1140
1186
        case 3:
1141
 
            m_FileFormatPanelJPEG->Hide();
1142
 
            m_FileFormatPanelTIFF->Hide();
1143
1187
            opt.outputImageType ="exr";
1144
1188
            break;
1145
1189
        default:
1146
1190
        case 0:
1147
 
            m_FileFormatPanelJPEG->Hide();
1148
 
            m_FileFormatPanelTIFF->Show();
1149
1191
            opt.outputImageType ="tif";
1150
1192
            break;
1151
1193
    }
1152
1194
 
1153
 
    m_pano_ctrls->FitInside();
1154
 
    Layout();
1155
 
 
1156
1195
    GlobalCmdHist::getInstance().addCommand(
1157
1196
            new PT::SetPanoOptionsCmd( *pano, opt )
1158
1197
            );
1167
1206
    PanoramaOptions opt = pano->getOptions();
1168
1207
    switch (fmt) {
1169
1208
        case 1:
1170
 
            m_HDRFileFormatPanelTIFF->Show();
1171
1209
            opt.outputImageTypeHDR ="tif";
1172
1210
            break;
1173
1211
        default:
1174
1212
        case 0:
1175
 
            m_HDRFileFormatPanelTIFF->Hide();
1176
1213
            opt.outputImageTypeHDR ="exr";
1177
1214
            break;
1178
1215
    }
1179
1216
 
1180
 
    m_pano_ctrls->FitInside();
1181
 
    Layout();
1182
 
 
1183
1217
    GlobalCmdHist::getInstance().addCommand(
1184
1218
            new PT::SetPanoOptionsCmd( *pano, opt )
1185
1219
            );
1279
1313
        );
1280
1314
}
1281
1315
 
 
1316
bool PanoPanel::CheckGoodSize()
 
1317
{
 
1318
    vigra::Rect2D cropped_region = pano->getOptions().getROI();
 
1319
    unsigned long long int area = ((unsigned long int) cropped_region.width()) * ((unsigned long int) cropped_region.height());
 
1320
    // Argh, more than half a gigapixel!
 
1321
    if (area > 500000000)
 
1322
    {
 
1323
        // Tell the user the stitch will be really big, and give them a
 
1324
        // chance to reduce the size.
 
1325
#if wxCHECK_VERSION(2,9,0)
 
1326
        wxMessageDialog dialog(this,
 
1327
                _("Are you sure you want to stitch such a large panorama?"),
 
1328
#ifdef _WINDOWS
 
1329
                _("Hugin"),
 
1330
#else
 
1331
                wxT(""),
 
1332
#endif
 
1333
                wxICON_EXCLAMATION | wxYES_NO);
 
1334
        dialog.SetExtendedMessage(
 
1335
                wxString::Format(_("The panorama you are trying to stitch is %.1f gigapixels.\nIf this is too big, reduce the panorama Canvas Size and the cropped region and stitch from the Stitcher tab. Stitching a panorama this size could take a long time and a large amount of memory."),
 
1336
                        area / 1000000000.0));
 
1337
        dialog.SetYesNoLabels(_("Stitch anyway"), _("Let me fix that"));
 
1338
#else // replacement for old wxWidgets versions.
 
1339
        // wxMessageDialog derives from wxDialog, but I don't understand
 
1340
        // why because on most platforms wxMessageDialog uses the native
 
1341
        // message box, and trying to make descriptive buttons through
 
1342
        // wxDialog::CreateStdButtonSizer causes a crash on wxGTK.
 
1343
        // Descriptive buttons are recommended by the Windows, Gnome, KDE,
 
1344
        // and Apple user interface guidelines.
 
1345
        // Due to this wxWidgets WTF, the buttons will are labeled Yes and
 
1346
        // No on wxWidgets 2.8 and earlier. This makes it a little
 
1347
        // confusing, and it is more likely someone will just click yes
 
1348
        // without reading the message and then wonder why their computer
 
1349
        // has ground to a halt.
 
1350
        /** @todo (Possibly) make a dialog manually with properly labelled
 
1351
         * buttons.
 
1352
         */
 
1353
        wxMessageDialog dialog(this,
 
1354
                wxString::Format(_("Are you sure you want to stitch such a large panorama?\n\nThe panorama you are trying to stitch is %.1f gigapixels.\nIf this is too big, reduce the panorama Canvas Size and the cropped region and stitch from the Stitcher tab. Stitching a panorama this size could take a long time and a large amount of memory."),
 
1355
                        area / 1000000000.0),
 
1356
#ifdef _WINDOWS
 
1357
                _("Hugin"),
 
1358
#else
 
1359
                wxT(""),
 
1360
#endif
 
1361
                wxICON_EXCLAMATION | wxYES_NO);
 
1362
#endif
 
1363
        bool result;
 
1364
        switch (dialog.ShowModal())
 
1365
        {
 
1366
            case wxID_OK:
 
1367
            case wxID_YES:
 
1368
                // Continue stitch.
 
1369
                return true;
 
1370
                break;
 
1371
            default:
 
1372
                // bring the user towards the approptiate controls.
 
1373
                MainFrame::Get()->ShowStitcherTab();
 
1374
                return false;
 
1375
        }
 
1376
    }
 
1377
    // I see nothing wrong with this...
 
1378
    return true;
 
1379
}
 
1380
 
1282
1381
 
1283
1382
IMPLEMENT_DYNAMIC_CLASS(PanoPanel, wxPanel)
1284
1383