Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[d5c5e9]: src / hugin1 / hugin / PanoPanel.cpp Maximize Restore History

Download this file

PanoPanel.cpp    801 lines (681 with data), 26.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
// -*- c-basic-offset: 4 -*-
/** @file PanoPanel.cpp
*
* @brief implementation of PanoPanel Class
*
* @author Kai-Uwe Behrmann <web@tiscali.de> and
* Pablo d'Angelo <pablo.dangelo@web.de>
*
* $Id$
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <config.h>
#include "panoinc_WX.h"
#include "panoinc.h"
#include "base_wx/platform.h"
#include <hugin/config_defaults.h>
#include "PT/Stitcher.h"
#include "common/wxPlatform.h"
extern "C" {
#ifdef HasPANO13
#include <pano13/queryfeature.h>
#else
#include <pano12/queryfeature.h>
#endif
}
#include "hugin/RunStitcherFrame.h"
#include "hugin/CommandHistory.h"
//#include "hugin/ImageCache.h"
//#include "hugin/CPEditorPanel.h"
//#include "hugin/List.h"
//#include "hugin/LensPanel.h"
//#include "hugin/ImagesPanel.h"
#include "hugin/CPImageCtrl.h"
#include "hugin/PanoPanel.h"
#include "hugin/MainFrame.h"
#include "hugin/huginApp.h"
#include "hugin/TextKillFocusHandler.h"
#include "base_wx/MyProgressDialog.h"
#include "hugin/PTStitcherPanel.h"
#include "hugin/NonaStitcherPanel.h"
#include "hugin/config_defaults.h"
#include "base_wx/platform.h"
#define WX_BROKEN_SIZER_UNKNOWN
using namespace PT;
using namespace std;
using namespace utils;
BEGIN_EVENT_TABLE(PanoPanel, wxWindow)
EVT_SIZE ( PanoPanel::OnSize )
EVT_CHOICE ( XRCID("pano_choice_pano_type"),PanoPanel::ProjectionChanged )
EVT_TEXT_ENTER( XRCID("pano_text_hfov"),PanoPanel::HFOVChanged )
EVT_TEXT_ENTER( XRCID("pano_text_vfov"),PanoPanel::VFOVChanged )
EVT_BUTTON ( XRCID("pano_button_calc_fov"), PanoPanel::DoCalcFOV)
EVT_TEXT_ENTER ( XRCID("pano_val_width"),PanoPanel::WidthChanged )
EVT_TEXT_ENTER ( XRCID("pano_val_height"),PanoPanel::HeightChanged )
EVT_TEXT_ENTER ( XRCID("pano_val_roi_top"),PanoPanel::ROIChanged )
EVT_TEXT_ENTER ( XRCID("pano_val_roi_bottom"),PanoPanel::ROIChanged )
EVT_TEXT_ENTER ( XRCID("pano_val_roi_left"),PanoPanel::ROIChanged )
EVT_TEXT_ENTER ( XRCID("pano_val_roi_right"),PanoPanel::ROIChanged )
EVT_BUTTON ( XRCID("pano_button_opt_width"), PanoPanel::DoCalcOptimalWidth)
EVT_BUTTON ( XRCID("pano_button_stitch"),PanoPanel::OnDoStitch )
EVT_CHECKBOX ( XRCID("pano_cb_ldr_output_blended"), PanoPanel::OnOutputFilesChanged)
EVT_CHECKBOX ( XRCID("pano_cb_ldr_output_layers"), PanoPanel::OnOutputFilesChanged)
EVT_CHECKBOX ( XRCID("pano_cb_ldr_output_exposure_layers"), PanoPanel::OnOutputFilesChanged)
EVT_CHECKBOX ( XRCID("pano_cb_ldr_output_exposure_blended"), PanoPanel::OnOutputFilesChanged)
EVT_CHECKBOX ( XRCID("pano_cb_ldr_output_exposure_remapped"), PanoPanel::OnOutputFilesChanged)
EVT_CHECKBOX ( XRCID("pano_cb_hdr_output_blended"), PanoPanel::OnOutputFilesChanged)
EVT_CHECKBOX ( XRCID("pano_cb_hdr_output_stacks"), PanoPanel::OnOutputFilesChanged)
EVT_CHECKBOX ( XRCID("pano_cb_hdr_output_layers"), PanoPanel::OnOutputFilesChanged)
EVT_CHOICE ( XRCID("pano_choice_remapper"),PanoPanel::RemapperChanged )
EVT_BUTTON ( XRCID("pano_button_remapper_opts"),PanoPanel::OnRemapperOptions )
EVT_CHOICE ( XRCID("pano_choice_blender"),PanoPanel::BlenderChanged )
EVT_BUTTON ( XRCID("pano_button_blender_opts"),PanoPanel::OnBlenderOptions )
EVT_CHOICE ( XRCID("pano_choice_file_format"),PanoPanel::FileFormatChanged )
EVT_CHOICE ( XRCID("pano_choice_hdr_file_format"),PanoPanel::HDRFileFormatChanged )
EVT_BUTTON ( XRCID("pano_button_file_format_opts"),PanoPanel::OnFileFormatOpts )
EVT_BUTTON ( XRCID("pano_button_hdr_file_format_opts"),PanoPanel::OnHDRFileFormatOpts )
END_EVENT_TABLE()
// Define a constructor for the Pano Panel
PanoPanel::PanoPanel(wxWindow *parent, Panorama* pano)
: wxPanel (parent, -1, wxDefaultPosition, wxDefaultSize, wxEXPAND|wxGROW),
pano(*pano),
updatesDisabled(false)
{
// opt = new PanoramaOptions();
// loading xrc resources in selfcreated this panel
wxXmlResource::Get()->LoadPanel ( this, wxT("panorama_panel")); //);
// converts KILL_FOCUS events to usable TEXT_ENTER events
// get gui controls
m_ProjectionChoice = XRCCTRL(*this, "pano_choice_pano_type" ,wxChoice);
DEBUG_ASSERT(m_ProjectionChoice);
m_keepViewOnResize = true;
/* populate with all available projection types */
#ifdef HasPANO13
int nP = panoProjectionFormatCount();
for(int n=0; n < nP; n++) {
pano_projection_features proj;
if (panoProjectionFeaturesQuery(n, &proj)) {
wxString str2(proj.name, wxConvLocal);
m_ProjectionChoice->Append(wxGetTranslation(str2));
}
}
#else
bool ok = true;
int n=0;
while(ok) {
char name[20];
char str[255];
sprintf(name,"PanoType%d",n);
n++;
int len = queryFeatureString(name,str,255);
if (len > 0) {
wxString str2(str, wxConvLocal);
m_ProjectionChoice->Append(wxGetTranslation(str2));
} else {
ok = false;
}
}
#endif
m_HFOVText = XRCCTRL(*this, "pano_text_hfov" ,wxTextCtrl);
DEBUG_ASSERT(m_HFOVText);
m_CalcHFOVButton = XRCCTRL(*this, "pano_button_calc_fov" ,wxButton);
DEBUG_ASSERT(m_CalcHFOVButton);
m_HFOVText->PushEventHandler(new TextKillFocusHandler(this));
m_VFOVText = XRCCTRL(*this, "pano_text_vfov" ,wxTextCtrl);
DEBUG_ASSERT(m_VFOVText);
m_VFOVText->PushEventHandler(new TextKillFocusHandler(this));
m_WidthTxt = XRCCTRL(*this, "pano_val_width", wxTextCtrl);
DEBUG_ASSERT(m_WidthTxt);
m_WidthTxt->PushEventHandler(new TextKillFocusHandler(this));
m_CalcOptWidthButton = XRCCTRL(*this, "pano_button_opt_width" ,wxButton);
DEBUG_ASSERT(m_CalcOptWidthButton);
m_HeightTxt = XRCCTRL(*this, "pano_val_height", wxTextCtrl);
DEBUG_ASSERT(m_HeightTxt);
m_HeightTxt->PushEventHandler(new TextKillFocusHandler(this));
m_ROILeftTxt = XRCCTRL(*this, "pano_val_roi_left", wxTextCtrl);
DEBUG_ASSERT(m_ROILeftTxt);
m_ROILeftTxt->PushEventHandler(new TextKillFocusHandler(this));
m_ROIRightTxt = XRCCTRL(*this, "pano_val_roi_right", wxTextCtrl);
DEBUG_ASSERT(m_ROIRightTxt);
m_ROIRightTxt->PushEventHandler(new TextKillFocusHandler(this));
m_ROITopTxt = XRCCTRL(*this, "pano_val_roi_top", wxTextCtrl);
DEBUG_ASSERT(m_ROITopTxt);
m_ROITopTxt->PushEventHandler(new TextKillFocusHandler(this));
m_ROIBottomTxt = XRCCTRL(*this, "pano_val_roi_bottom", wxTextCtrl);
DEBUG_ASSERT(m_ROIBottomTxt);
m_ROIBottomTxt->PushEventHandler(new TextKillFocusHandler(this));
m_RemapperChoice = XRCCTRL(*this, "pano_choice_remapper", wxChoice);
DEBUG_ASSERT(m_RemapperChoice);
m_BlenderChoice = XRCCTRL(*this, "pano_choice_blender", wxChoice);
DEBUG_ASSERT(m_BlenderChoice);
m_StitchButton = XRCCTRL(*this, "pano_button_stitch", wxButton);
DEBUG_ASSERT(m_StitchButton);
m_FileFormatChoice = XRCCTRL(*this, "pano_choice_file_format", wxChoice);
DEBUG_ASSERT(m_FileFormatChoice);
m_HDRFileFormatChoice = XRCCTRL(*this, "pano_choice_hdr_file_format", wxChoice);
DEBUG_ASSERT(m_HDRFileFormatChoice);
#ifdef USE_WX253
m_pano_ctrls = XRCCTRL(*this, "pano_controls_panel", wxScrolledWindow);
DEBUG_ASSERT(m_pano_ctrls);
m_pano_ctrls->SetSizeHints(20, 20);
m_pano_ctrls->FitInside();
m_pano_ctrls->SetScrollRate(10, 10);
#endif
// observe the panorama
pano->addObserver (this);
/*
// trigger creation of apropriate stitcher control, if
// not already happend.
if (! m_Stitcher) {
wxCommandEvent dummy;
StitcherChanged(dummy);
}
*/
DEBUG_TRACE("")
}
PanoPanel::~PanoPanel(void)
{
DEBUG_TRACE("dtor");
wxConfigBase::Get()->Write(wxT("Stitcher/DefaultRemapper"),m_RemapperChoice->GetSelection());
m_HFOVText->PopEventHandler(true);
m_VFOVText->PopEventHandler(true);
m_WidthTxt->PopEventHandler(true);
m_ROILeftTxt->PopEventHandler(true);
m_ROIRightTxt->PopEventHandler(true);
m_ROITopTxt->PopEventHandler(true);
m_ROIBottomTxt->PopEventHandler(true);
pano.removeObserver(this);
DEBUG_TRACE("dtor end");
}
void PanoPanel::panoramaChanged (PT::Panorama &pano)
{
DEBUG_TRACE("");
if (pano.getNrOfImages() == 0) {
//m_ProjectionChoice->Disable();
//m_HFOVSpin->Disable();
m_CalcHFOVButton->Disable();
//m_VFOVSpin->Disable();
//m_WidthTxt->Disable();
m_CalcOptWidthButton->Disable();
//m_HeightStaticText->Disable();
//m_StitcherChoice->Disable();
m_StitchButton->Disable();
} else {
//m_ProjectionChoice->Enable();
//m_HFOVSpin->Enable();
m_CalcHFOVButton->Enable();
//m_VFOVSpin->Enable();
//m_WidthTxt->Enable();
m_CalcOptWidthButton->Enable();
//m_HeightStaticText->Enable();
m_StitchButton->Enable();
}
PanoramaOptions opt = pano.getOptions();
// update all options for dialog and notebook tab
UpdateDisplay(opt);
m_oldOpt = opt;
}
void PanoPanel::UpdateDisplay(const PanoramaOptions & opt)
{
// m_HFOVSpin->SetRange(1,opt.getMaxHFOV());
// m_VFOVSpin->SetRange(1,opt.getMaxVFOV());
m_ProjectionChoice->SetSelection(opt.getProjection());
m_keepViewOnResize = opt.fovCalcSupported(opt.getProjection());
std::string val;
val = doubleToString(opt.getHFOV(),1);
m_HFOVText->SetValue(wxString(val.c_str(), *wxConvCurrent));
val = doubleToString(opt.getVFOV(),1);
m_VFOVText->SetValue(wxString(val.c_str(), *wxConvCurrent));
// disable VFOV edit field, due to bugs in setHeight(), setWidth()
m_VFOVText->Enable(m_keepViewOnResize);
m_CalcOptWidthButton->Enable(m_keepViewOnResize);
m_CalcHFOVButton->Enable(m_keepViewOnResize);
m_WidthTxt->SetValue(wxString::Format(wxT("%d"), opt.getWidth()));
m_HeightTxt->SetValue(wxString::Format(wxT("%d"), opt.getHeight()));
m_ROILeftTxt->SetValue(wxString::Format(wxT("%d"), opt.getROI().left() ));
m_ROIRightTxt->SetValue(wxString::Format(wxT("%d"), opt.getROI().right() ));
m_ROITopTxt->SetValue(wxString::Format(wxT("%d"), opt.getROI().top() ));
m_ROIBottomTxt->SetValue(wxString::Format(wxT("%d"), opt.getROI().bottom() ));
// output types
XRCCTRL(*this, "pano_cb_ldr_output_blended", wxCheckBox)->SetValue(opt.outputLDRBlended);
XRCCTRL(*this, "pano_cb_ldr_output_layers", wxCheckBox)->SetValue(opt.outputLDRLayers);
XRCCTRL(*this, "pano_cb_ldr_output_exposure_blended", wxCheckBox)->SetValue(opt.outputLDRExposureBlended);
XRCCTRL(*this, "pano_cb_ldr_output_exposure_layers", wxCheckBox)->SetValue(opt.outputLDRExposureLayers);
XRCCTRL(*this, "pano_cb_ldr_output_exposure_remapped", wxCheckBox)->SetValue(opt.outputLDRExposureRemapped);
XRCCTRL(*this, "pano_cb_hdr_output_blended", wxCheckBox)->SetValue(opt.outputHDRBlended);
XRCCTRL(*this, "pano_cb_hdr_output_stacks", wxCheckBox)->SetValue(opt.outputHDRStacks);
XRCCTRL(*this, "pano_cb_hdr_output_layers", wxCheckBox)->SetValue(opt.outputHDRLayers);
// output file mode
long i=0;
if (opt.outputImageType == "tif")
i = 0;
else if (opt.outputImageType == "jpg")
i = 1;
else if (opt.outputImageType == "png")
i = 2;
else if (opt.outputImageType == "exr")
i = 3;
else
wxLogError(wxT("INTERNAL error: unknown output image type"));
m_FileFormatChoice->SetSelection(i);
i=0;
if (opt.outputImageTypeHDR == "exr")
i = 0;
else if (opt.outputImageTypeHDR == "tif")
i = 1;
else
wxLogError(wxT("INTERNAL error: unknown hdr output image type"));
m_HDRFileFormatChoice->SetSelection(i);
}
void PanoPanel::ProjectionChanged ( wxCommandEvent & e )
{
if (updatesDisabled) return;
PanoramaOptions opt = pano.getOptions();
// PanoramaOptions::ProjectionFormat oldP = opt.getProjection();
PanoramaOptions::ProjectionFormat newP = (PanoramaOptions::ProjectionFormat) m_ProjectionChoice->GetSelection();
// int w = opt.getWidth();
// int h = opt.getHeight();
opt.setProjection(newP);
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( pano, opt )
);
DEBUG_DEBUG ("Projection changed: " << newP)
}
void PanoPanel::HFOVChanged ( wxCommandEvent & e )
{
if (updatesDisabled) return;
PanoramaOptions opt = pano.getOptions();
wxString text = m_HFOVText->GetValue();
DEBUG_INFO ("HFOV = " << text.mb_str() );
if (text == wxT("")) {
return;
}
double hfov;
if (!str2double(text, hfov)) {
wxLogError(_("Value must be numeric."));
return;
}
if ( hfov <=0 || hfov > opt.getMaxHFOV()) {
wxLogError(wxString::Format(
_("Invalid HFOV value. Maximum HFOV for this projection is %lf."),
opt.getMaxHFOV()));
}
opt.setHFOV(hfov);
// recalculate panorama height...
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( pano, opt )
);
DEBUG_INFO ( "new hfov: " << hfov )
}
void PanoPanel::VFOVChanged ( wxCommandEvent & e )
{
if (updatesDisabled) return;
PanoramaOptions opt = pano.getOptions();
wxString text = m_VFOVText->GetValue();
DEBUG_INFO ("VFOV = " << text.mb_str() );
if (text == wxT("")) {
return;
}
double vfov;
if (!str2double(text, vfov)) {
wxLogError(_("Value must be numeric."));
return;
}
if ( vfov <=0 || vfov > opt.getMaxVFOV()) {
wxLogError(wxString::Format(
_("Invalid VFOV value. Maximum VFOV for this projection is %lf."),
opt.getMaxVFOV()));
vfov = opt.getMaxVFOV();
}
opt.setVFOV(vfov);
// recalculate panorama height...
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( pano, opt )
);
DEBUG_INFO ( "new vfov: " << vfov )
}
/*
void PanoPanel::VFOVChanged ( wxCommandEvent & e )
{
DEBUG_TRACE("")
if (updatesDisabled) return;
PanoramaOptions opt = pano.getOptions();
int vfov = m_VFOVSpin->GetValue() ;
if (vfov != opt.getVFOV()) {
opt.setVFOV(vfov);
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( pano, opt )
);
DEBUG_INFO ( "new vfov: " << vfov << " => height: " << opt.getHeight() );
} else {
DEBUG_DEBUG("not setting same fov");
}
}
*/
void PanoPanel::WidthChanged ( wxCommandEvent & e )
{
if (updatesDisabled) return;
PanoramaOptions opt = pano.getOptions();
long nWidth;
if (m_WidthTxt->GetValue().ToLong(&nWidth)) {
if (nWidth <= 0) return;
opt.setWidth((unsigned int) nWidth, m_keepViewOnResize);
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( pano, opt )
);
DEBUG_INFO(nWidth );
} else {
wxLogError(_("width needs to be an integer bigger than 0"));
}
}
void PanoPanel::HeightChanged ( wxCommandEvent & e )
{
if (updatesDisabled) return;
PanoramaOptions opt = pano.getOptions();
long nHeight;
if (m_HeightTxt->GetValue().ToLong(&nHeight)) {
if(nHeight <= 0) return;
opt.setHeight((unsigned int) nHeight);
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( pano, opt )
);
DEBUG_INFO(nHeight);
} else {
wxLogError(_("height needs to be an integer bigger than 0"));
}
}
void PanoPanel::ROIChanged ( wxCommandEvent & e )
{
if (updatesDisabled) return;
PanoramaOptions opt = pano.getOptions();
long left, right, top, bottom;
if (!m_ROITopTxt->GetValue().ToLong(&top)) {
wxLogError(_("Top needs to be an integer bigger than 0"));
return;
}
if (!m_ROILeftTxt->GetValue().ToLong(&left)) {
wxLogError(_("left needs to be an integer bigger than 0"));
return;
}
if (!m_ROIRightTxt->GetValue().ToLong(&right)) {
wxLogError(_("right needs to be an integer bigger than 0"));
return;
}
if (!m_ROIBottomTxt->GetValue().ToLong(&bottom)) {
wxLogError(_("bottom needs to be an integer bigger than 0"));
return;
}
opt.setROI(vigra::Rect2D(left, top, right, bottom));
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( pano, opt )
);
}
void PanoPanel::EnableControls(bool enable)
{
// m_HFOVSpin->Enable(enable);
// m_VFOVSpin->Enable(enable);
m_WidthTxt->Enable(enable);
m_RemapperChoice->Enable(enable);
m_BlenderChoice->Enable(enable);
// m_CalcHFOVButton->Enable(enable);
m_CalcOptWidthButton->Enable(enable);
}
void PanoPanel::RemapperChanged(wxCommandEvent & e)
{
int remapper = m_RemapperChoice->GetSelection();
DEBUG_DEBUG("changing remapper to " << remapper);
PanoramaOptions opt = pano.getOptions();
if (remapper == 1) {
opt.remapper = PanoramaOptions::PTMENDER;
} else {
opt.remapper = PanoramaOptions::NONA;
}
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( pano, opt )
);
}
void PanoPanel::OnRemapperOptions(wxCommandEvent & e)
{
wxLogError(_("Not yet implemented"));
}
void PanoPanel::BlenderChanged(wxCommandEvent & e)
{
int blender = m_BlenderChoice->GetSelection();
DEBUG_DEBUG("changing stitcher to " << blender);
// TODO: change panorama options.
PanoramaOptions opt = pano.getOptions();
switch (blender) {
case 1:
opt.blendMode = PanoramaOptions::NO_BLEND;
break;
case 2:
opt.blendMode = PanoramaOptions::PTMASKER_BLEND;
break;
case 3:
opt.blendMode = PanoramaOptions::PTBLENDER_BLEND;
break;
default:
case 0:
opt.blendMode = PanoramaOptions::ENBLEND_BLEND;
break;
}
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( pano, opt )
);
}
void PanoPanel::OnBlenderOptions(wxCommandEvent & e)
{
wxLogError(_("Not yet implemented"));
}
void PanoPanel::DoCalcFOV(wxCommandEvent & e)
{
DEBUG_TRACE("");
double hfov, height;
pano.fitPano(hfov, height);
PanoramaOptions opt = pano.getOptions();
opt.setHFOV(hfov);
opt.setHeight(roundi(height));
DEBUG_INFO ( "hfov: " << opt.getHFOV() << " w: " << opt.getWidth() << " h: " << opt.getHeight() << " => vfov: " << opt.getVFOV() << " before update");
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( pano, opt )
);
PanoramaOptions opt2 = pano.getOptions();
DEBUG_INFO ( "hfov: " << opt2.getHFOV() << " w: " << opt2.getWidth() << " h: " << opt2.getHeight() << " => vfov: " << opt2.getVFOV() << " after update");
}
void PanoPanel::DoCalcOptimalWidth(wxCommandEvent & e)
{
PanoramaOptions opt = pano.getOptions();
unsigned width = pano.calcOptimalWidth();
if (width > 0) {
opt.setWidth( width );
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( pano, opt )
);
}
DEBUG_INFO ( "new optimal width: " << opt.getWidth() );
}
void PanoPanel::DoStitch()
{
if (pano.getNrOfImages() == 0) {
return;
}
// save project
wxCommandEvent dummy;
MainFrame::Get()->OnSaveProject(dummy);
// run stitching in a separate process
wxString ptofile = MainFrame::Get()->getProjectName();
#if defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
wxString hugin_stitch_project = MacGetPathTOBundledAppMainExecutableFile(CFSTR("HuginStitchProject.app"));
if(hugin_stitch_project == wxT(""))
{
DEBUG_ERROR("hugin_stitch_project could not be found in the bundle.");
return;
}
#elif defined __WXMAC__
wxString hugin_stitch_project = wxT("HuginStitchProject.app");
#else
wxString hugin_stitch_project = wxT("hugin_stitch_project");
#endif
wxFileName prefixFN(ptofile);
wxString outputPrefix;
if (prefixFN.GetExt() == wxT("pto")) {
outputPrefix = prefixFN.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR, wxPATH_NATIVE) + prefixFN.GetName();
} else {
outputPrefix = ptofile;
}
wxString command = hugin_stitch_project + wxT(" -o ") + wxQuoteFilename(outputPrefix) + wxT(" ") + wxQuoteFilename(ptofile);
#ifdef __WXGTK__
// work around a wxExecute bug/problem
// (endless polling of fd 0 and 1 in hugin_stitch_project)
wxProcess *my_process = new wxProcess(this);
my_process->Redirect();
// Delete itself once processes terminated.
my_process->Detach();
wxExecute(command,wxEXEC_ASYNC, my_process);
#else
wxExecute(command);
#endif
// hmm, what to do with opening the result????
#if 0
if (m_Stitcher->Stitch(pano, opt)) {
int runViewer = wxConfig::Get()->Read(wxT("/Stitcher/RunEditor"), HUGIN_STITCHER_RUN_EDITOR);
if (runViewer) {
// TODO: show image after it has been created
wxString editor = wxConfig::Get()->Read(wxT("/Stitcher/Editor"), wxT(HUGIN_STITCHER_EDITOR));
wxString args = wxConfig::Get()->Read(wxT("/Stitcher/EditorArgs"), wxT(HUGIN_STITCHER_EDITOR_ARGS));
if (opt.outputFormat == PanoramaOptions::TIFF_m || opt.outputFormat == PanoramaOptions::TIFF_mask)
{
// TODO: tiff_m case? Open all files?
} else {
wxString quoted = utils::wxQuoteFilename(wxfn);
args.Replace(wxT("%f"), quoted);
quoted = utils::wxQuoteFilename(wxString(pano.getImage(0).getFilename().c_str(), *wxConvCurrent));
args.Replace(wxT("%i"), quoted);
wxString cmdline = utils::wxQuoteFilename(editor) + wxT(" ") + args;
DEBUG_DEBUG("editor command: " << cmdline.c_str());
if (editor != wxT("")) {
wxExecute(cmdline, wxEXEC_ASYNC);
} else {
#ifdef __WXMSW__
// use default viewer on windows
SHELLEXECUTEINFO seinfo;
memset(&seinfo, 0, sizeof(SHELLEXECUTEINFO));
seinfo.cbSize = sizeof(SHELLEXECUTEINFO);
seinfo.fMask = SEE_MASK_NOCLOSEPROCESS;
seinfo.lpFile = args.c_str();
seinfo.lpParameters = args.c_str();
if (!ShellExecuteEx(&seinfo)) {
wxMessageBox(_("Could not execute command: ") + args, _("ShellExecuteEx failed"), wxCANCEL | wxICON_ERROR);
}
#endif
}
}
}
}
#endif
}
void PanoPanel::OnDoStitch ( wxCommandEvent & e )
{
DoStitch();
}
void PanoPanel::FileFormatChanged(wxCommandEvent & e)
{
int fmt = m_FileFormatChoice->GetSelection();
DEBUG_DEBUG("changing file format to " << fmt);
PanoramaOptions opt = pano.getOptions();
switch (fmt) {
case 1:
opt.outputImageType ="jpg";
break;
case 2:
opt.outputImageType ="png";
break;
case 3:
opt.outputImageType ="exr";
break;
default:
case 0:
opt.outputImageType ="tif";
break;
}
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( pano, opt )
);
}
void PanoPanel::OnFileFormatOpts(wxCommandEvent & e)
{
wxMessageBox(_("Not yet implemented"));
}
void PanoPanel::HDRFileFormatChanged(wxCommandEvent & e)
{
int fmt = m_HDRFileFormatChoice->GetSelection();
DEBUG_DEBUG("changing file format to " << fmt);
PanoramaOptions opt = pano.getOptions();
switch (fmt) {
case 1:
opt.outputImageTypeHDR ="tif";
break;
default:
case 0:
opt.outputImageTypeHDR ="exr";
break;
}
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( pano, opt )
);
}
void PanoPanel::OnHDRFileFormatOpts(wxCommandEvent & e)
{
wxMessageBox(_("Not yet implemented"));
}
void PanoPanel::OnOutputFilesChanged(wxCommandEvent & e)
{
int id = e.GetId();
PanoramaOptions opts = pano.getOptions();
if (id == XRCID("pano_cb_ldr_output_blended") ) {
opts.outputLDRBlended = e.IsChecked();
} else if (id == XRCID("pano_cb_ldr_output_layers") ) {
opts.outputLDRLayers = e.IsChecked();
} else if (id == XRCID("pano_cb_ldr_output_exposure_layers") ) {
opts.outputLDRExposureLayers = e.IsChecked();
} else if (id == XRCID("pano_cb_ldr_output_exposure_blended") ) {
opts.outputLDRExposureBlended = e.IsChecked();
} else if (id == XRCID("pano_cb_ldr_output_exposure_remapped") ) {
opts.outputLDRExposureRemapped = e.IsChecked();
} else if (id == XRCID("pano_cb_hdr_output_blended") ) {
opts.outputHDRBlended = e.IsChecked();
} else if (id == XRCID("pano_cb_hdr_output_stacks") ) {
opts.outputHDRStacks = e.IsChecked();
} else if (id == XRCID("pano_cb_hdr_output_layers") ) {
opts.outputHDRLayers = e.IsChecked();
}
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( pano, opts )
);
}
// We need to override the default handling of size events because the
// sizers set the virtual size but not the actual size. We reverse
// the standard handling and fit the child to the parent rather than
// fitting the parent around the child
void PanoPanel::OnSize( wxSizeEvent & e )
{
DEBUG_TRACE("");
wxSize new_size = e.GetSize();
XRCCTRL(*this, "panorama_panel", wxPanel)->SetSize ( new_size );
DEBUG_INFO( "" << new_size.GetWidth() <<"x"<< new_size.GetHeight() );
e.Skip();
}