Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[6d12f1]: src / hugin1 / hugin / HFOVDialog.cpp Maximize Restore History

Download this file

HFOVDialog.cpp    394 lines (344 with data), 13.6 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
// -*- c-basic-offset: 4 -*-
/** @file HFOVDialog.cpp
*
* @brief implementation of HFOVDialog 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
*
*/
#include <config.h>
#include "panoinc_WX.h"
#include "panoinc.h"
#include "base_wx/wxPlatform.h"
#include "base_wx/platform.h"
#include "base_wx/LensTools.h"
#include "hugin/huginApp.h"
#include "hugin/HFOVDialog.h"
#include "hugin/MainFrame.h"
using namespace PT;
using namespace std;
using namespace hugin_utils;
BEGIN_EVENT_TABLE(HFOVDialog, wxDialog)
EVT_CHOICE (XRCID("lensdlg_type_choice"),HFOVDialog::OnTypeChanged)
EVT_TEXT ( XRCID("lensdlg_cropfactor_text"), HFOVDialog::OnCropFactorChanged )
EVT_TEXT ( XRCID("lensdlg_hfov_text"), HFOVDialog::OnHFOVChanged )
EVT_TEXT ( XRCID("lensdlg_focallength_text"), HFOVDialog::OnFocalLengthChanged )
EVT_BUTTON( XRCID("lensdlg_load_lens_button"), HFOVDialog::OnLoadLensParameters )
EVT_BUTTON ( wxID_OK, HFOVDialog::OnOk)
END_EVENT_TABLE()
HFOVDialog::HFOVDialog(wxWindow * parent, SrcPanoImage & srcImg)
: m_srcImg(srcImg)
{
m_HFOV = srcImg.getHFOV();
m_focalLength = srcImg.getExifFocalLength();
m_cropFactor = srcImg.getCropFactor();
wxXmlResource::Get()->LoadDialog(this, parent, wxT("dlg_focallength"));
m_cropText = XRCCTRL(*this, "lensdlg_cropfactor_text", wxTextCtrl);
DEBUG_ASSERT(m_cropText);
m_hfovText = XRCCTRL(*this, "lensdlg_hfov_text", wxTextCtrl);
DEBUG_ASSERT(m_hfovText);
m_focalLengthText = XRCCTRL(*this, "lensdlg_focallength_text", wxTextCtrl);
DEBUG_ASSERT(m_focalLengthText);
m_projChoice = XRCCTRL(*this, "lensdlg_type_choice", wxChoice);
DEBUG_ASSERT(m_projChoice);
FillLensProjectionList(m_projChoice);
m_okButton = XRCCTRL(*this, "wxID_OK", wxButton);
DEBUG_ASSERT(m_okButton);
// fill fields
wxString fn(srcImg.getFilename().c_str(), HUGIN_CONV_FILENAME);
wxString message;
message.Printf(_("No or only partial information about field of view was found in image file\n%s\n\nPlease enter the horizontal field of view (HFOV) or the focal length and crop factor."), fn.c_str());
XRCCTRL(*this, "lensdlg_message", wxStaticText)->SetLabel(message);
SelectProjection(m_projChoice,m_srcImg.getProjection());
if (m_cropFactor > 0 && m_focalLength > 0) {
// everything is well known.. compute HFOV
m_HFOV = HuginBase::SrcPanoImage::calcHFOV(m_srcImg.getProjection(), m_focalLength,
m_cropFactor, m_srcImg.getSize());
m_HFOVStr = doubleTowxString(m_HFOV,2);
m_hfovText->SetValue(m_HFOVStr);
m_focalLengthStr = doubleTowxString(m_focalLength,2);
m_focalLengthText->SetValue(m_focalLengthStr);
m_cropFactorStr = doubleTowxString(m_cropFactor,2);
m_cropText->SetValue(m_cropFactorStr);
} else if (m_cropFactor > 0 && m_focalLength <= 0) {
// focal length unknown
m_cropFactorStr = doubleTowxString(m_cropFactor,2);
m_cropText->SetValue(m_cropFactorStr);
m_okButton->Disable();
} else if (m_cropFactor <= 0 && m_focalLength > 0) {
// crop factor unknown
m_focalLengthStr = doubleTowxString(m_focalLength,2);
m_focalLengthText->SetValue(m_focalLengthStr);
m_okButton->Disable();
} else {
// everything unknown
// assume a crop factor of one
m_cropFactor = 1;
m_cropFactorStr = doubleTowxString(m_cropFactor,2);
m_cropText->SetValue(m_cropFactorStr);
m_okButton->Disable();
}
// set a proper size for this dialog
this->GetSizer()->SetSizeHints(this);
}
void HFOVDialog::OnTypeChanged(wxCommandEvent & e)
{
SrcPanoImage::Projection new_proj=(SrcPanoImage::Projection)(GetSelectedProjection(m_projChoice));
DEBUG_DEBUG("new type: " << new_proj);
m_srcImg.setProjection(new_proj);
if (m_cropFactor > 0 && m_focalLength > 0) {
m_HFOV = HuginBase::SrcPanoImage::calcHFOV(m_srcImg.getProjection(), m_focalLength,
m_cropFactor, m_srcImg.getSize());
m_HFOVStr = doubleTowxString(m_HFOV,2);
m_hfovText->SetValue(m_HFOVStr);
}
}
void HFOVDialog::OnHFOVChanged(wxCommandEvent & e)
{
wxString text = m_hfovText->GetValue();
DEBUG_DEBUG("state: " << m_HFOVStr.mb_str(wxConvLocal) << ", change:" << text.mb_str(wxConvLocal));
DEBUG_DEBUG("cmd str: " << e.GetString().mb_str(wxConvLocal));
if (text.empty()) {
// ignore all empty hfov changes
return;
}
// ignore changes caused by ourself
if (m_hfovText->GetValue() == m_HFOVStr) {
DEBUG_DEBUG("ignoring programatic HFOV change");
return;
}
// accept change
m_HFOVStr = text;
if (text.empty()) {
m_HFOV = 0;
m_okButton->Disable();
return;
}
if (!str2double(text, m_HFOV)) {
m_okButton->Disable();
return;
}
DEBUG_DEBUG(m_HFOV);
if (m_HFOV <= 0) {
wxMessageBox(_("The horizontal field of view must be positive."));
m_HFOV = 50;
m_HFOVStr = doubleTowxString(m_HFOV,2);
m_hfovText->SetValue(m_HFOVStr);
return;
}
if (m_srcImg.getProjection() == SrcPanoImage::RECTILINEAR && m_HFOV > 179) {
DEBUG_DEBUG("HFOV " << m_HFOV << " too big, resetting to 179");
m_HFOV=179;
m_HFOVStr = doubleTowxString(m_HFOV,2);
m_hfovText->SetValue(m_HFOVStr);
}
if (m_cropFactor > 0) {
// set focal length only if crop factor is known
m_focalLength = HuginBase::SrcPanoImage::calcFocalLength(m_srcImg.getProjection(), m_HFOV, m_cropFactor, m_srcImg.getSize());
m_focalLengthStr = doubleTowxString(m_focalLength,2);
m_focalLengthText->SetValue(m_focalLengthStr);
}
m_okButton->Enable();
}
void HFOVDialog::OnFocalLengthChanged(wxCommandEvent & e)
{
wxString text = m_focalLengthText->GetValue();
DEBUG_DEBUG(m_focalLengthStr.mb_str(wxConvLocal) << " => " << text.mb_str(wxConvLocal));
// ignore changes caused by ourself
if (m_focalLengthText->GetValue() == m_focalLengthStr) {
DEBUG_DEBUG("ignore focal length change");
return;
}
// accept change
m_focalLengthStr = text;
if (text.empty()) {
m_focalLength = 0;
return;
}
if (!str2double(text, m_focalLength)) {
return;
}
DEBUG_DEBUG(m_focalLength);
// ignore leading zeros..
if (m_focalLength == 0) {
return;
}
if (m_focalLength <= 0) {
m_focalLength=1;
m_focalLengthStr = doubleTowxString(m_focalLength,2);
m_focalLengthText->SetValue(m_focalLengthStr);
wxMessageBox(_("The focal length must be positive."));
}
if (m_cropFactor > 0) {
// calculate HFOV.
m_HFOV = HuginBase::SrcPanoImage::calcHFOV(m_srcImg.getProjection(), m_focalLength,
m_cropFactor, m_srcImg.getSize());
m_HFOVStr = doubleTowxString(m_HFOV,2);
m_hfovText->SetValue(m_HFOVStr);
m_okButton->Enable();
}
}
void HFOVDialog::OnCropFactorChanged(wxCommandEvent & e)
{
// ignore changesd cause by ourself
wxString text = m_cropText->GetValue();
DEBUG_DEBUG(m_cropFactorStr.mb_str(wxConvLocal) << " => " << text.mb_str(wxConvLocal));
if (text == m_cropFactorStr) {
DEBUG_DEBUG("ignore crop change");
return;
}
// accept change
m_cropFactorStr = text;
if (text.empty()) {
m_cropFactor = 0;
return;
}
if (!str2double(text, m_cropFactor)) {
return;
}
// ignore leading zeros..
if (m_cropFactor == 0) {
m_cropFactorStr = text;
return;
}
if (m_cropFactor <= 0) {
wxMessageBox(_("The crop factor must be positive."));
m_cropFactor=1;
m_cropFactorStr = doubleTowxString(m_cropFactor,2);
m_cropText->SetValue(m_cropFactorStr);
return;
}
if (m_focalLength > 0) {
m_HFOV = HuginBase::SrcPanoImage::calcHFOV(m_srcImg.getProjection(), m_focalLength,
m_cropFactor, m_srcImg.getSize());
m_HFOVStr = doubleTowxString(m_HFOV,2);
m_hfovText->SetValue(m_HFOVStr);
m_okButton->Enable();
}
}
void HFOVDialog::OnLoadLensParameters(wxCommandEvent & e)
{
Lens lens;
lens.setImageSize(m_srcImg.getSize());
bool cropped=false;
bool autoCenterCrop=false;
vigra::Rect2D cropRect;
if (LoadLensParametersChoose(this, lens, cropped, autoCenterCrop, cropRect)) {
m_HFOV = lens.getHFOV();
m_cropFactor = lens.getCropFactor();
m_srcImg.setCropFactor(lens.getCropFactor());
m_srcImg.setExifFocalLength(lens.getFocalLength());
m_srcImg.setHFOV(const_map_get(lens.variables,"v").getValue());
m_srcImg.setProjection((SrcPanoImage::Projection) lens.getProjection());
m_focalLength = HuginBase::SrcPanoImage::calcFocalLength(m_srcImg.getProjection(), m_HFOV, m_cropFactor, m_srcImg.getSize());
// geometrical distortion correction
std::vector<double> radialDist(4);
radialDist[0] = const_map_get(lens.variables,"a").getValue();
radialDist[1] = const_map_get(lens.variables,"b").getValue();
radialDist[2] = const_map_get(lens.variables,"c").getValue();
radialDist[3] = 1 - radialDist[0] - radialDist[1] - radialDist[2];
m_srcImg.setRadialDistortion(radialDist);
FDiff2D t;
t.x = const_map_get(lens.variables,"d").getValue();
t.y = const_map_get(lens.variables,"e").getValue();
m_srcImg.setRadialDistortionCenterShift(t);
t.x = const_map_get(lens.variables,"g").getValue();
t.y = const_map_get(lens.variables,"t").getValue();
m_srcImg.setShear(t);
// vignetting
std::vector<double> vigCorrCoeff(4);
vigCorrCoeff[0] = const_map_get(lens.variables,"Va").getValue();
vigCorrCoeff[1] = const_map_get(lens.variables,"Vb").getValue();
vigCorrCoeff[2] = const_map_get(lens.variables,"Vc").getValue();
vigCorrCoeff[3] = const_map_get(lens.variables,"Vd").getValue();
m_srcImg.setRadialVigCorrCoeff(vigCorrCoeff);
t.x = const_map_get(lens.variables,"Vx").getValue();
t.y = const_map_get(lens.variables,"Vy").getValue();
m_srcImg.setRadialVigCorrCenterShift(t);
// m_srcImg.setExposureValue(const_map_get(vars,"Eev").getValue());
m_srcImg.setWhiteBalanceRed(const_map_get(lens.variables,"Er").getValue());
m_srcImg.setWhiteBalanceBlue(const_map_get(lens.variables,"Eb").getValue());
std::vector<float> resp(5);
resp[0] = const_map_get(lens.variables,"Ra").getValue();
resp[1] = const_map_get(lens.variables,"Rb").getValue();
resp[2] = const_map_get(lens.variables,"Rc").getValue();
resp[3] = const_map_get(lens.variables,"Rd").getValue();
resp[4] = const_map_get(lens.variables,"Re").getValue();
m_srcImg.setEMoRParams(resp);
if (!cropped)
{
m_srcImg.setCropMode(SrcPanoImage::NO_CROP);
}
else
{
if (m_srcImg.isCircularCrop())
{
m_srcImg.setCropMode(SrcPanoImage::CROP_CIRCLE);
}
else
{
m_srcImg.setCropMode(SrcPanoImage::CROP_RECTANGLE);
};
m_srcImg.setCropRect(cropRect);
};
// display in GUI
m_focalLengthStr = doubleTowxString(m_focalLength,2);
m_focalLengthText->SetValue(m_focalLengthStr);
m_cropFactorStr = doubleTowxString(m_cropFactor,2);
m_cropText->SetValue(m_cropFactorStr);
m_HFOVStr = doubleTowxString(m_HFOV,2);
m_hfovText->SetValue(m_HFOVStr);
SelectProjection(m_projChoice, m_srcImg.getProjection());
// update lens type
m_okButton->Enable();
}
}
SrcPanoImage HFOVDialog::GetSrcImage()
{
m_srcImg.setExifFocalLength(m_focalLength);
m_srcImg.setCropFactor(m_cropFactor);
m_srcImg.setHFOV(m_HFOV);
return m_srcImg;
}
double HFOVDialog::GetCropFactor()
{
return m_cropFactor;
}
double HFOVDialog::GetFocalLength()
{
return m_focalLength;
}
void HFOVDialog::OnOk(wxCommandEvent & e)
{
if(m_srcImg.getProjection()==SrcPanoImage::FISHEYE_ORTHOGRAPHIC && m_HFOV>190)
{
if(wxMessageBox(
wxString::Format(_("You have given a field of view of %.2f degrees.\n But the orthographic projection is limited to a field of view of 180 degress.\nDo you want still use that high value?"), m_HFOV),
#ifdef __WXMSW__
_("Hugin"),
#else
wxT(""),
#endif
wxICON_EXCLAMATION | wxYES_NO)==wxNO)
{
return;
};
};
EndModal(wxID_OK);
};