[3f9ab6]: src / hugin1 / hugin / PreviewFrame.cpp Maximize Restore History

Download this file

PreviewFrame.cpp    997 lines (863 with data), 34.8 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
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
// -*- c-basic-offset: 4 -*-
/** @file PreviewFrame.cpp
*
* @brief implementation of PreviewFrame Class
*
* @author 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
*
*/
// use toggle buttons or uncomment check boxes
//#ifndef __WXMAC__
#define USE_TOGGLE_BUTTON 1
//#endif
//wxMac now has toggle buttons.
#include <config.h>
#include "panoinc_WX.h"
#include "panoinc.h"
#include "base_wx/platform.h"
#include "hugin/config_defaults.h"
#include "hugin/PreviewFrame.h"
#include "hugin/huginApp.h"
#include "hugin/PreviewPanel.h"
#include "hugin/ImagesPanel.h"
#include "hugin/CommandHistory.h"
#include "MaskEdClientWnd.h"
#include <vigra_ext/ImageTransforms.h>
extern "C" {
#ifdef HasPANO13
#include <pano13/queryfeature.h>
#else
#include <pano12/queryfeature.h>
#endif
}
using namespace utils;
// a random id, hope this doesn't break something..
enum {
ID_PROJECTION_CHOICE = wxID_HIGHEST +1,
ID_BLEND_CHOICE,
ID_UPDATE_BUTTON,
ID_OUTPUTMODE_CHOICE,
ID_EXPOSURE_TEXT,
ID_EXPOSURE_SPIN,
ID_EXPOSURE_DEFAULT,
ID_TOGGLE_BUT = wxID_HIGHEST+100,
PROJ_PARAM_NAMES_ID = wxID_HIGHEST+1000,
PROJ_PARAM_VAL_ID = wxID_HIGHEST+1100,
PROJ_PARAM_SLIDER_ID = wxID_HIGHEST+1200
};
BEGIN_EVENT_TABLE(PreviewFrame, wxFrame)
EVT_CLOSE(PreviewFrame::OnClose)
// EVT_CHECKBOX(-1, PreviewFrame::OnAutoPreviewToggle)
EVT_TOOL(XRCID("preview_center_tool"), PreviewFrame::OnCenterHorizontally)
EVT_TOOL(XRCID("preview_fit_pano_tool"), PreviewFrame::OnFitPano)
EVT_TOOL(XRCID("preview_straighten_pano_tool"), PreviewFrame::OnStraighten)
EVT_TOOL(XRCID("preview_auto_update_tool"), PreviewFrame::OnAutoPreviewToggle)
EVT_TOOL(XRCID("preview_update_tool"), PreviewFrame::OnUpdate)
EVT_TOOL(XRCID("preview_show_all_tool"), PreviewFrame::OnShowAll)
EVT_TOOL(XRCID("preview_show_none_tool"), PreviewFrame::OnShowNone)
EVT_TOOL(XRCID("preview_num_transform"), PreviewFrame::OnNumTransform)
EVT_TOOL(XRCID("preview_mask_editor"), PreviewFrame::OnMaskEditor)
EVT_TOOL(XRCID("action_exit_maskeditor"), PreviewFrame::OnExitMaskEditor)
EVT_TEXT_ENTER( -1 , PreviewFrame::OnTextCtrlChanged)
EVT_BUTTON(ID_EXPOSURE_DEFAULT, PreviewFrame::OnDefaultExposure)
EVT_SPIN_DOWN(ID_EXPOSURE_SPIN, PreviewFrame::OnDecreaseExposure)
EVT_SPIN_UP(ID_EXPOSURE_SPIN, PreviewFrame::OnIncreaseExposure)
EVT_CHOICE(ID_BLEND_CHOICE, PreviewFrame::OnBlendChoice)
EVT_CHOICE(ID_PROJECTION_CHOICE, PreviewFrame::OnProjectionChoice)
EVT_CHOICE(ID_OUTPUTMODE_CHOICE, PreviewFrame::OnOutputChoice)
#ifdef USE_TOGGLE_BUTTON
EVT_TOGGLEBUTTON(-1, PreviewFrame::OnChangeDisplayedImgs)
#else
EVT_CHECKBOX(-1, PreviewFrame::OnChangeDisplayedImgs)
#endif
EVT_SCROLL_CHANGED(PreviewFrame::OnChangeFOV)
// EVT_SCROLL_THUMBRELEASE(PreviewFrame::OnChangeFOV)
// EVT_SCROLL_ENDSCROLL(PreviewFrame::OnChangeFOV)
// EVT_SCROLL_THUMBTRACK(PreviewFrame::OnChangeFOV)
END_EVENT_TABLE()
#define PF_STYLE (wxMAXIMIZE_BOX | wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN)
PreviewFrame::PreviewFrame(wxFrame * frame, PT::Panorama &pano)
: wxFrame(frame,-1, _("Panorama preview"), wxDefaultPosition, wxDefaultSize,
PF_STYLE),
m_pano(pano)
{
DEBUG_TRACE("");
m_oldProjFormat = -1;
m_ToolBar = wxXmlResource::Get()->LoadToolBar(this, wxT("preview_toolbar"));
DEBUG_ASSERT(m_ToolBar);
// create tool bar
SetToolBar(m_ToolBar);
m_topsizer = new wxBoxSizer( wxVERTICAL );
// create our preview panel
m_PreviewPanel = new PreviewPanel();
m_PreviewPanel->Create(this);
m_PreviewPanel->Init(this, &m_pano);
//create mask editor client window
wxSize sz = GetClientSize();
//m_MaskEdClientWnd = new MaskEdClientWnd(this, wxID_ANY, wxDefaultPosition, sz);
initPreviewMode();
}
PreviewFrame::~PreviewFrame()
{
DEBUG_TRACE("dtor writing config");
wxConfigBase * config = wxConfigBase::Get();
wxSize sz = GetClientSize();
StoreFramePosition(this, wxT("PreviewFrame"));
if ( (!this->IsIconized()) && (! this->IsMaximized()) && this->IsShown()) {
config->Write(wxT("/PreviewFrame/isShown"), 1l);
} else {
config->Write(wxT("/PreviewFrame/isShown"), 0l);
}
bool checked = m_ToolBar->GetToolState(XRCID("preview_auto_update_tool"));
config->Write(wxT("/PreviewFrame/autoUpdate"), checked ? 1l: 0l);
config->Write(wxT("/PreviewFrame/blendMode"), m_BlendModeChoice->GetSelection());
m_pano.removeObserver(this);
DEBUG_TRACE("dtor end");
}
void PreviewFrame::initPreviewMode()
{
m_ToggleButtonSizer = new wxStaticBoxSizer(
new wxStaticBox(this, -1, _("displayed images")),
wxHORIZONTAL );
m_ButtonPanel = new wxScrolledWindow(this, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
// Set min height big enough to display scrollbars as well
m_ButtonPanel->SetSizeHints(20, 42);
//Horizontal scroll bars only
m_ButtonPanel->SetScrollRate(10, 0);
m_ButtonSizer = new wxBoxSizer(wxHORIZONTAL);
m_ButtonPanel->SetAutoLayout(true);
m_ButtonPanel->SetSizer(m_ButtonSizer);
m_ToggleButtonSizer->Add(m_ButtonPanel, 1, wxEXPAND | wxADJUST_MINSIZE, 0);
m_topsizer->Add(m_ToggleButtonSizer, 0, wxEXPAND | wxADJUST_MINSIZE | wxBOTTOM, 5);
wxFlexGridSizer * flexSizer = new wxFlexGridSizer(2,0,5,5);
flexSizer->AddGrowableCol(0);
flexSizer->AddGrowableRow(0);
flexSizer->Add(m_PreviewPanel,
1, // not vertically stretchable
wxEXPAND | // horizontally stretchable
wxALL, // draw border all around
5); // border width
m_VFOVSlider = new wxSlider(this, -1, 1,
1, 180,
wxDefaultPosition, wxDefaultSize,
wxSL_VERTICAL | wxSL_AUTOTICKS,
wxDefaultValidator,
_("VFOV"));
m_VFOVSlider->SetLineSize(2);
m_VFOVSlider->SetPageSize(10);
m_VFOVSlider->SetTickFreq(5,0);
m_VFOVSlider->SetToolTip(_("drag to change the vertical field of view"));
flexSizer->Add(m_VFOVSlider, 0, wxEXPAND);
m_HFOVSlider = new wxSlider(this, -1, 1,
1, 360,
wxDefaultPosition, wxDefaultSize,
wxSL_HORIZONTAL | wxSL_AUTOTICKS,
wxDefaultValidator,
_("HFOV"));
m_HFOVSlider->SetPageSize(10);
m_HFOVSlider->SetLineSize(2);
m_HFOVSlider->SetTickFreq(5,0);
m_HFOVSlider->SetToolTip(_("drag to change the horizontal field of view"));
flexSizer->Add(m_HFOVSlider, 0, wxEXPAND);
m_topsizer->Add(flexSizer,
1, // vertically stretchable
wxEXPAND | // horizontally stretchable
wxALL, // draw border all around
5); // border width
wxStaticBoxSizer * blendModeSizer = new wxStaticBoxSizer(
new wxStaticBox(this, -1, _("Preview Options")),
wxHORIZONTAL);
blendModeSizer->Add(new wxStaticText(this, -1, _("projection (f):")),
0, // not vertically strechable
wxALL | wxALIGN_CENTER_VERTICAL, // draw border all around
5); // border width
m_ProjectionChoice = new wxChoice(this, ID_PROJECTION_CHOICE,
wxDefaultPosition, wxDefaultSize);
/* 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_ProjectionChoice->SetSelection(2);
blendModeSizer->Add(m_ProjectionChoice,
0,
wxALL | wxALIGN_CENTER_VERTICAL,
5);
//////////////////////////////////////////////////////
// Blend mode
blendModeSizer->Add(new wxStaticText(this, -1, _("Blend mode:")),
0, // not vertically strechable
wxALL | wxALIGN_CENTER_VERTICAL, // draw border all around
5); // border width
m_choices[0] = _("normal");
m_choices[1] = _("difference");
int oldMode = wxConfigBase::Get()->Read(wxT("/PreviewFrame/blendMode"), 0l);
if (oldMode > 1) oldMode = 0;
m_BlendModeChoice = new wxChoice(this, ID_BLEND_CHOICE,
wxDefaultPosition, wxDefaultSize,
2, m_choices);
m_BlendModeChoice->SetSelection((PreviewPanel::BlendMode) oldMode);
blendModeSizer->Add(m_BlendModeChoice,
0,
wxALL | wxALIGN_CENTER_VERTICAL,
5);
//////////////////////////////////////////////////////
// LDR, HDR
blendModeSizer->Add(new wxStaticText(this, -1, _("Output:")),
0, // not vertically strechable
wxALL | wxALIGN_CENTER_VERTICAL, // draw border all around
5); // border width
m_choices[0] = _("LDR");
m_choices[1] = _("HDR");
m_outputModeChoice = new wxChoice(this, ID_OUTPUTMODE_CHOICE,
wxDefaultPosition, wxDefaultSize,
2, m_choices);
m_outputModeChoice->SetSelection(0);
blendModeSizer->Add(m_outputModeChoice,
0,
wxALL | wxALIGN_CENTER_VERTICAL,
5);
/////////////////////////////////////////////////////
// exposure
blendModeSizer->Add(new wxStaticText(this, -1, _("EV:")),
0, // not vertically strechable
wxALL | wxALIGN_CENTER_VERTICAL, // draw border all around
5); // border width
m_defaultExposureBut = new wxBitmapButton(this, ID_EXPOSURE_DEFAULT,
wxArtProvider::GetBitmap(wxART_REDO));
blendModeSizer->Add(m_defaultExposureBut, 0, wxLEFT | wxRIGHT, 5);
// m_decExposureBut = new wxBitmapButton(this, ID_EXPOSURE_DECREASE,
// wxArtProvider::GetBitmap(wxART_GO_BACK));
// blendModeSizer->Add(m_decExposureBut);
m_exposureTextCtrl = new wxTextCtrl(this, ID_EXPOSURE_TEXT, _("0"),
wxDefaultPosition,wxSize(50,-1), wxTE_PROCESS_ENTER);
blendModeSizer->Add(m_exposureTextCtrl,
0, // not vertically strechable
wxLEFT | wxTOP | wxBOTTOM | wxALIGN_CENTER_VERTICAL, // draw border all around
5); // border width
// m_incExposureBut = new wxBitmapButton(this, ID_EXPOSURE_INCREASE,
// wxArtProvider::GetBitmap(wxART_GO_FORWARD));
m_exposureSpinBut = new wxSpinButton(this, ID_EXPOSURE_SPIN, wxDefaultPosition,
wxDefaultSize, wxSP_VERTICAL);
m_exposureSpinBut->SetRange(-0x8000, 0x7fff);
m_exposureSpinBut->SetValue(0);
blendModeSizer->Add(m_exposureSpinBut, 0, wxALIGN_CENTER_VERTICAL);
m_topsizer->Add(blendModeSizer, 0, wxEXPAND | wxALL, 5);
#ifdef HasPANO13
m_projParamSizer = new wxStaticBoxSizer(
new wxStaticBox(this, -1, _("Projection Parameters")),
wxHORIZONTAL);
m_projParamNamesLabel.resize(PANO_PROJECTION_MAX_PARMS);
m_projParamTextCtrl.resize(PANO_PROJECTION_MAX_PARMS);
m_projParamSlider.resize(PANO_PROJECTION_MAX_PARMS);
for (int i=0; i < PANO_PROJECTION_MAX_PARMS; i++) {
m_projParamNamesLabel[i] = new wxStaticText(this, PROJ_PARAM_NAMES_ID+i, _("param:"));
m_projParamSizer->Add(m_projParamNamesLabel[i],
0, // not vertically strechable
wxALL | wxALIGN_CENTER_VERTICAL, // draw border all around
5); // border width
m_projParamTextCtrl[i] = new wxTextCtrl(this, PROJ_PARAM_VAL_ID+i, _("0"),
wxDefaultPosition,wxDefaultSize, wxTE_PROCESS_ENTER);
m_projParamSizer->Add(m_projParamTextCtrl[i],
0, // not vertically strechable
wxALL | wxALIGN_CENTER_VERTICAL, // draw border all around
5); // border width
m_projParamSlider[i] = new wxSlider(this, PROJ_PARAM_SLIDER_ID+i, 0, -90, 90);
m_projParamSizer->Add(m_projParamSlider[i],
1, // not vertically strechable
wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, // draw border all around
5); // border width
}
m_topsizer->Add(m_projParamSizer, 0, wxEXPAND | wxALL, 5);
// do not show projection param sizer
m_topsizer->Show(m_projParamSizer, false, true);
#endif
wxConfigBase * config = wxConfigBase::Get();
// add a status bar
CreateStatusBar(3);
int widths[3] = {-3, 150, 150};
SetStatusWidths(3, widths);
SetStatusText(_("Left click to define new center point, right click to move point to horizon."),0);
SetStatusText(wxT(""),1);
SetStatusText(wxT(""),2);
// the initial size as calculated by the sizers
this->SetSizer( m_topsizer );
m_topsizer->SetSizeHints( this );
// set the minimize icon
#ifdef __WXMSW__
wxIcon myIcon(MainFrame::Get()->GetXRCPath() + wxT("data/icon.ico"),wxBITMAP_TYPE_ICO);
#else
wxIcon myIcon(MainFrame::Get()->GetXRCPath() + wxT("data/icon.png"),wxBITMAP_TYPE_PNG);
#endif
SetIcon(myIcon);
m_pano.addObserver(this);
RestoreFramePosition(this, wxT("PreviewFrame"));
m_PreviewPanel->SetBlendMode((PreviewPanel::BlendMode)oldMode );
long aup = config->Read(wxT("/PreviewFrame/autoUpdate"),0l);
m_PreviewPanel->SetAutoUpdate(aup != 0);
m_ToolBar->ToggleTool(XRCID("preview_auto_update_tool"), aup !=0);
#ifdef __WXMSW__
// wxFrame does have a strange background color on Windows..
this->SetBackgroundColour(m_PreviewPanel->GetBackgroundColour());
#endif
if (config->Read(wxT("/PreviewFrame/isShown"), 0l) != 0) {
Show();
}
SetStatusText(_("Center panorama with left mouse button, set horizon with right button"),0);
}
void PreviewFrame::setMaskEditorMode()
{
}
void PreviewFrame::OnMaskEditor(wxCommandEvent & e)
{
m_HFOVSlider->Hide();
m_VFOVSlider->Hide();
SetTitle(wxT("Mask Editor Mode"));
delete m_ToolBar;
m_ToolBar = wxXmlResource::Get()->LoadToolBar(this, wxT("masked_main_toolbar"));
DEBUG_ASSERT(m_ToolBar);
// create tool bar
SetToolBar(m_ToolBar);
/*m_topsizer->Hide(m_topsizer, true);
m_topsizer->Layout();*/
}
void PreviewFrame::OnExitMaskEditor(wxCommandEvent &e)
{
SetTitle(wxT("Preview"));
delete m_ToolBar;
m_ToolBar = wxXmlResource::Get()->LoadToolBar(this, wxT("preview_toolbar"));
DEBUG_ASSERT(m_ToolBar);
// create tool bar
SetToolBar(m_ToolBar);
m_HFOVSlider->Show();
m_VFOVSlider->Show();
}
void PreviewFrame::OnChangeDisplayedImgs(wxCommandEvent & e)
{
int id = e.GetId() - ID_TOGGLE_BUT;
int nImg = m_pano.getNrOfImages();
UIntSet activeImages = m_pano.getActiveImages();
DEBUG_DEBUG("toggle_button_id: " << id << " nImg:" << nImg << " m_ToggleButtons.size(): " << m_ToggleButtons.size());
if (id >= 0 && id < nImg) {
if (e.IsChecked()) {
activeImages.insert(id);
} else {
activeImages.erase(id);
}
// m_PreviewPanel->SetDisplayedImages(m_displayedImgs);
GlobalCmdHist::getInstance().addCommand(
new PT::SetActiveImagesCmd(m_pano, activeImages)
);
} else {
DEBUG_ERROR("invalid Togglebutton ID");
}
}
void PreviewFrame::panoramaChanged(Panorama &pano)
{
const PanoramaOptions & opts = pano.getOptions();
wxString projection;
m_ProjectionChoice->SetSelection(opts.getProjection());
m_VFOVSlider->Enable( opts.fovCalcSupported(opts.getProjection()) );
m_outputModeChoice->SetSelection(opts.outputMode);
if (opts.outputMode == PanoramaOptions::OUTPUT_HDR) {
/*
m_exposureTextCtrl->Hide();
m_defaultExposureBut->Hide();
m_decExposureBut->Hide();
m_incExposureBut->Hide();
*/
} else {
/*
m_exposureTextCtrl->Show();
m_defaultExposureBut->Show();
m_decExposureBut->Show();
m_incExposureBut->Show();
*/
}
m_exposureTextCtrl->SetValue(wxString(doubleToString(opts.outputExposureValue,2).c_str(), wxConvLocal));
bool activeImgs = pano.getActiveImages().size() > 0;
m_ToolBar->EnableTool(XRCID("preview_center_tool"), activeImgs);
m_ToolBar->EnableTool(XRCID("preview_fit_pano_tool"), activeImgs);
m_ToolBar->EnableTool(XRCID("preview_update_tool"), activeImgs);
m_ToolBar->EnableTool(XRCID("preview_num_transform"), activeImgs);
m_ToolBar->EnableTool(XRCID("preview_straighten_pano_tool"), pano.getNrOfImages() > 0);
// TODO: enable display of parameters and set their limits, if projection has some.
#ifdef HasPANO13
int nParam = opts.m_projFeatures.numberOfParameters;
bool relayout = false;
// if the projection format has changed
if (opts.getProjection() != m_oldProjFormat) {
DEBUG_DEBUG("Projection format changed");
if (nParam) {
// show parameters and update labels.
m_topsizer->Show(m_projParamSizer, true, true);
int i;
for (i=0; i < nParam; i++) {
const pano_projection_parameter * pp = & (opts.m_projFeatures.parm[i]);
wxString str2(pp->name, wxConvLocal);
str2 = wxGetTranslation(str2);
m_projParamNamesLabel[i]->SetLabel(str2);
m_projParamSlider[i]->SetRange(utils::roundi(pp->minValue), utils::roundi(pp->maxValue));
}
for(;i < PANO_PROJECTION_MAX_PARMS; i++) {
m_projParamNamesLabel[i]->Hide();
m_projParamSlider[i]->Hide();
m_projParamTextCtrl[i]->Hide();
}
relayout = true;
} else {
m_topsizer->Show(m_projParamSizer, false, true);
relayout = true;
}
}
if (nParam) {
// display new values
std::vector<double> params = opts.getProjectionParameters();
assert((int) params.size() == nParam);
for (int i=0; i < nParam; i++) {
wxString val = wxString(doubleToString(params[i],1).c_str(), wxConvLocal);
m_projParamTextCtrl[i]->SetValue(wxString(val.c_str(), wxConvLocal));
m_projParamSlider[i]->SetValue(utils::roundi(params[i]));
}
}
if (relayout) {
m_topsizer->Layout();
}
#endif
SetStatusText(_("Center panorama with left mouse button, set horizon with right button"),0);
SetStatusText(wxString::Format(wxT("%.1f x %.1f"), opts.getHFOV(), opts.getVFOV()),2);
m_HFOVSlider->SetValue(roundi(opts.getHFOV()));
m_VFOVSlider->SetValue(roundi(opts.getVFOV()));
m_oldProjFormat = opts.getProjection();
}
void PreviewFrame::panoramaImagesChanged(Panorama &pano, const UIntSet &changed)
{
DEBUG_TRACE("");
bool dirty = false;
unsigned int nrImages = pano.getNrOfImages();
unsigned int nrButtons = m_ToggleButtons.size();
// m_displayedImgs.clear();
// remove items for nonexisting images
for (int i=nrButtons-1; i>=(int)nrImages; i--)
{
m_ButtonSizer->Detach(m_ToggleButtons[i]);
delete m_ToggleButtons[i];
m_ToggleButtons.pop_back();
dirty = true;
}
// add buttons
if ( nrImages >= nrButtons ) {
for(UIntSet::const_iterator it = changed.begin(); it != changed.end(); ++it){
if (*it >= nrButtons) {
unsigned int imgNr = *it;
// create new item.
// wxImage * bmp = new wxImage(sz.GetWidth(), sz.GetHeight());
#ifdef USE_TOGGLE_BUTTON
wxToggleButton * but = new wxToggleButton(m_ButtonPanel,
ID_TOGGLE_BUT + *it,
wxString::Format(wxT("%d"),*it),
wxDefaultPosition, wxDefaultSize,
wxBU_EXACTFIT);
#else
wxCheckBox * but = new wxCheckBox(m_ButtonPanel,
ID_TOGGLE_BUT + *it,
wxString::Format(wxT("%d"),*it));
#endif
wxFileName tFilename(wxString (pano.getImage(imgNr).getFilename().c_str(), HUGIN_CONV_FILENAME));
but->SetToolTip(tFilename.GetFullName());
wxSize sz = but->GetSize();
// but->SetSize(res.GetWidth(),sz.GetHeight());
// HACK.. set fixed width. that should work
// better than all that stupid dialogunit stuff, that
// breaks on wxWin 2.5
but->SetSize(20, sz.GetHeight());
but->SetValue(true);
m_ButtonSizer->Add(but,
0,
wxLEFT | wxTOP | wxADJUST_MINSIZE,
5);
m_ToggleButtons.push_back(but);
dirty = true;
}
}
}
// update existing items
UIntSet displayedImages = m_pano.getActiveImages();
for (unsigned i=0; i < nrImages; i++) {
m_ToggleButtons[i]->SetValue(set_contains(displayedImages, i));
}
if (dirty) {
m_ButtonSizer->SetVirtualSizeHints(m_ButtonPanel);
// Layout();
DEBUG_INFO("New m_ButtonPanel width: " << (m_ButtonPanel->GetSize()).GetWidth());
DEBUG_INFO("New m_ButtonPanel Height: " << (m_ButtonPanel->GetSize()).GetHeight());
}
}
void PreviewFrame::OnClose(wxCloseEvent& event)
{
DEBUG_TRACE("OnClose")
// do not close, just hide if we're not forced
if (event.CanVeto()) {
event.Veto();
Hide();
DEBUG_DEBUG("hiding");
} else {
DEBUG_DEBUG("closing");
this->Destroy();
}
}
void PreviewFrame::OnAutoPreviewToggle(wxCommandEvent & e)
{
m_PreviewPanel->SetAutoUpdate(e.IsChecked());
if (e.IsChecked()) {
m_PreviewPanel->ForceUpdate();
}
}
#if 0
// need to add the wxChoice somewhere
void PreviewFrame::OnProjectionChanged()
{
PanoramaOptions opt = m_pano.getOptions();
int lt = m_ProjectionChoice->GetSelection();
wxString Ip;
switch ( lt ) {
case PanoramaOptions::RECTILINEAR: Ip = _("Rectilinear"); break;
case PanoramaOptions::CYLINDRICAL: Ip = _("Cylindrical"); break;
case PanoramaOptions::EQUIRECTANGULAR: Ip = _("Equirectangular"); break;
}
opt.projectionFormat = (PanoramaOptions::ProjectionFormat) lt;
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( pano, opt )
);
DEBUG_DEBUG ("Projection changed: " << lt << ":" << Ip )
}
#endif
void PreviewFrame::OnCenterHorizontally(wxCommandEvent & e)
{
if (m_pano.getActiveImages().size() == 0) return;
GlobalCmdHist::getInstance().addCommand(
new PT::CenterPanoCmd(m_pano)
);
// fit pano afterwards
OnFitPano(e);
}
void PreviewFrame::OnStraighten(wxCommandEvent & e)
{
if (m_pano.getNrOfImages() == 0) return;
GlobalCmdHist::getInstance().addCommand(
new PT::StraightenPanoCmd(m_pano)
);
if (m_pano.getOptions().getHFOV() > 359) {
// adjust canvas size for 360 deg panos
OnFitPano(e);
} else {
// also center non 360 deg panos
OnCenterHorizontally(e);
}
}
void PreviewFrame::OnUpdate(wxCommandEvent& event)
{
m_PreviewPanel->ForceUpdate();
}
void PreviewFrame::updatePano()
{
if (m_ToolBar->GetToolState(XRCID("preview_auto_update_tool"))) {
m_PreviewPanel->ForceUpdate();
}
}
void PreviewFrame::OnFitPano(wxCommandEvent & e)
{
if (m_pano.getActiveImages().size() == 0) return;
DEBUG_TRACE("");
PanoramaOptions opt = m_pano.getOptions();
double hfov, height;
m_pano.fitPano(hfov, height);
opt.setHFOV(hfov);
opt.setHeight(roundi(height));
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( m_pano, opt )
);
DEBUG_INFO ( "new fov: [" << opt.getHFOV() << " "<< opt.getVFOV() << "] => height: " << opt.getHeight() );
updatePano();
}
void PreviewFrame::OnShowAll(wxCommandEvent & e)
{
if (m_pano.getNrOfImages() == 0) return;
DEBUG_ASSERT(m_pano.getNrOfImages() == m_ToggleButtons.size());
UIntSet displayedImgs;
for (unsigned int i=0; i < m_pano.getNrOfImages(); i++) {
displayedImgs.insert(i);
}
GlobalCmdHist::getInstance().addCommand(
new PT::SetActiveImagesCmd(m_pano, displayedImgs)
);
updatePano();
}
void PreviewFrame::OnShowNone(wxCommandEvent & e)
{
if (m_pano.getNrOfImages() == 0) return;
DEBUG_ASSERT(m_pano.getNrOfImages() == m_ToggleButtons.size());
for (unsigned int i=0; i < m_pano.getNrOfImages(); i++) {
m_ToggleButtons[i]->SetValue(false);
}
UIntSet displayedImgs;
GlobalCmdHist::getInstance().addCommand(
new PT::SetActiveImagesCmd(m_pano, displayedImgs)
);
updatePano();
}
void PreviewFrame::OnNumTransform(wxCommandEvent & e)
{
if (m_pano.getNrOfImages() == 0) return;
wxDialog dlg;
wxXmlResource::Get()->LoadDialog(&dlg, this, wxT("dlg_numtrans"));
if (dlg.ShowModal() == wxID_OK ) {
wxString text = XRCCTRL(dlg, "numtrans_yaw", wxTextCtrl)->GetValue();
double y;
if (!str2double(text, y)) {
wxLogError(_("Yaw value must be numeric."));
return;
}
text = XRCCTRL(dlg, "numtrans_pitch", wxTextCtrl)->GetValue();
double p;
if (!str2double(text, p)) {
wxLogError(_("Pitch value must be numeric."));
return;
}
text = XRCCTRL(dlg, "numtrans_roll", wxTextCtrl)->GetValue();
double r;
if (!str2double(text, r)) {
wxLogError(_("Roll value must be numeric."));
return;
}
GlobalCmdHist::getInstance().addCommand(
new PT::RotatePanoCmd(m_pano, y, p, r)
);
// update preview panel
updatePano();
} else {
DEBUG_DEBUG("Numerical transform canceled");
}
}
void PreviewFrame::OnTextCtrlChanged(wxCommandEvent & e)
{
PanoramaOptions opts = m_pano.getOptions();
if (e.GetEventObject() == m_exposureTextCtrl) {
// exposure
wxString text = m_exposureTextCtrl->GetValue();
DEBUG_INFO ("target exposure = " << text.mb_str(wxConvLocal) );
double p = 0;
if (text != wxT("")) {
if (!str2double(text, p)) {
wxLogError(_("Value must be numeric."));
return;
}
}
opts.outputExposureValue = p;
#ifdef HasPANO13
} else {
int nParam = opts.m_projFeatures.numberOfParameters;
std::vector<double> para = opts.getProjectionParameters();
for (int i = 0; i < nParam; i++) {
if (e.GetEventObject() == m_projParamTextCtrl[i]) {
wxString text = m_projParamTextCtrl[i]->GetValue();
DEBUG_INFO ("param " << i << ": = " << text.mb_str(wxConvLocal) );
double p = 0;
if (text != wxT("")) {
if (!str2double(text, p)) {
wxLogError(_("Value must be numeric."));
return;
}
}
para[i] = p;
}
}
opts.setProjectionParameters(para);
#endif
}
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( m_pano, opts )
);
// update preview panel
updatePano();
}
void PreviewFrame::OnChangeFOV(wxScrollEvent & e)
{
DEBUG_TRACE("");
PanoramaOptions opt = m_pano.getOptions();
if (e.GetEventObject() == m_HFOVSlider) {
DEBUG_DEBUG("HFOV changed (slider): " << e.GetInt() << " == " << m_HFOVSlider->GetValue());
opt.setHFOV(e.GetInt());
} else if (e.GetEventObject() == m_VFOVSlider) {
DEBUG_DEBUG("VFOV changed (slider): " << e.GetInt());
opt.setVFOV(e.GetInt());
} else {
#ifdef HasPANO13
int nParam = opt.m_projFeatures.numberOfParameters;
std::vector<double> para = opt.getProjectionParameters();
for (int i = 0; i < nParam; i++) {
if (e.GetEventObject() == m_projParamSlider[i]) {
// update
para[i] = e.GetInt();
}
}
opt.setProjectionParameters(para);
#endif
}
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( m_pano, opt )
);
}
void PreviewFrame::OnBlendChoice(wxCommandEvent & e)
{
if (e.GetEventObject() == m_BlendModeChoice) {
int sel = e.GetSelection();
switch (sel) {
case 0:
m_PreviewPanel->SetBlendMode(PreviewPanel::BLEND_COPY);
break;
case 1:
m_PreviewPanel->SetBlendMode(PreviewPanel::BLEND_DIFFERENCE);
break;
default:
DEBUG_WARN("Unknown blend mode selected");
}
} else {
DEBUG_WARN("wxChoice event from unknown object received");
}
}
void PreviewFrame::OnDefaultExposure( wxCommandEvent & e )
{
if (m_pano.getNrOfImages() > 0) {
PanoramaOptions opt = m_pano.getOptions();
opt.outputExposureValue = calcMeanExposure(m_pano);
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( m_pano, opt )
);
updatePano();
}
}
void PreviewFrame::OnIncreaseExposure( wxSpinEvent & e )
{
PanoramaOptions opt = m_pano.getOptions();
opt.outputExposureValue = opt.outputExposureValue + 1.0/3;
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( m_pano, opt )
);
updatePano();
}
void PreviewFrame::OnDecreaseExposure( wxSpinEvent & e )
{
PanoramaOptions opt = m_pano.getOptions();
opt.outputExposureValue = opt.outputExposureValue - 1.0/3;
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( m_pano, opt )
);
updatePano();
}
void PreviewFrame::OnProjectionChoice( wxCommandEvent & e )
{
if (e.GetEventObject() == m_ProjectionChoice) {
PanoramaOptions opt = m_pano.getOptions();
int lt = m_ProjectionChoice->GetSelection();
wxString Ip;
opt.setProjection( (PanoramaOptions::ProjectionFormat) lt );
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( m_pano, opt )
);
DEBUG_DEBUG ("Projection changed: " << lt);
updatePano();
} else {
DEBUG_WARN("wxChoice event from unknown object received");
}
}
void PreviewFrame::OnOutputChoice( wxCommandEvent & e)
{
if (e.GetEventObject() == m_outputModeChoice) {
PanoramaOptions opt = m_pano.getOptions();
int lt = m_outputModeChoice->GetSelection();
wxString Ip;
opt.outputMode = ( (PanoramaOptions::OutputMode) lt );
GlobalCmdHist::getInstance().addCommand(
new PT::SetPanoOptionsCmd( m_pano, opt )
);
updatePano();
} else {
DEBUG_WARN("wxChoice event from unknown object received");
}
}
/** update the display */
void PreviewFrame::updateProgressDisplay()
{
wxString msg;
// build the message:
for (std::vector<ProgressTask>::iterator it = tasks.begin();
it != tasks.end(); ++it)
{
wxString cMsg;
if (it->getProgress() > 0) {
cMsg.Printf(wxT("%s [%3.0f%%]: %s "),
wxString(it->getShortMessage().c_str(), wxConvLocal).c_str(),
100 * it->getProgress(),
wxString(it->getMessage().c_str(), wxConvLocal).c_str());
} else {
cMsg.Printf(wxT("%s %s"),wxString(it->getShortMessage().c_str(), wxConvLocal).c_str(),
wxString(it->getMessage().c_str(), wxConvLocal).c_str());
}
// append to main message
if (it == tasks.begin()) {
msg = cMsg;
} else {
msg.Append(wxT(" | "));
msg.Append(cMsg);
}
}
// wxStatusBar *m_statbar = GetStatusBar();
//DEBUG_TRACE("Statusmb : " << msg.mb_str(wxConvLocal));
//m_statbar->SetStatusText(msg,0);
#ifdef __WXMSW__
UpdateWindow(NULL);
#else
// This is a bad call.. we just want to repaint the window, instead we will
// process user events as well :( Unfortunately, there is not portable workaround...
// wxYield();
#endif
}