Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HFOVDialog.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
28 #include "hugin_config.h"
29 #include "panoinc_WX.h"
30 #include "panoinc.h"
31 
32 #include "wxPlatform.h"
33 #include "platform.h"
34 #include "LensTools.h"
35 #include "HFOVDialog.h"
36 
37 HFOVDialog::HFOVDialog(wxWindow * parent, HuginBase::SrcPanoImage & srcImg)
38  : m_srcImg(srcImg)
39 {
40  m_HFOV = srcImg.getHFOV();
41  m_focalLength = srcImg.getExifFocalLength();
42  m_cropFactor = srcImg.getCropFactor();
43  wxXmlResource::Get()->LoadDialog(this, parent, wxT("dlg_focallength"));
44 
45  m_cropText = XRCCTRL(*this, "lensdlg_cropfactor_text", wxTextCtrl);
47  m_cropText->Bind(wxEVT_TEXT, &HFOVDialog::OnCropFactorChanged, this);
48 
49  m_hfovText = XRCCTRL(*this, "lensdlg_hfov_text", wxTextCtrl);
51  m_hfovText->Bind(wxEVT_TEXT, &HFOVDialog::OnHFOVChanged, this);
52 
53  m_focalLengthText = XRCCTRL(*this, "lensdlg_focallength_text", wxTextCtrl);
55  m_focalLengthText->Bind(wxEVT_TEXT, &HFOVDialog::OnFocalLengthChanged, this);
56 
57  m_projChoice = XRCCTRL(*this, "lensdlg_type_choice", wxChoice);
60  m_projChoice->Bind(wxEVT_CHOICE, &HFOVDialog::OnTypeChanged, this);
61 
62  m_okButton = XRCCTRL(*this, "wxID_OK", wxButton);
64  m_okButton->Bind(wxEVT_BUTTON, &HFOVDialog::OnOk, this);
65 
66  Bind(wxEVT_BUTTON, &HFOVDialog::OnLoadLensParameters, this, XRCID("lensdlg_load_lens_button"));
67  // fill fields
68  wxString fn(srcImg.getFilename().c_str(), HUGIN_CONV_FILENAME);
69  wxString message;
70  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());
71  XRCCTRL(*this, "lensdlg_message", wxStaticText)->SetLabel(message);
72  SelectListValue(m_projChoice, m_srcImg.getProjection());
73 
74  if (m_cropFactor > 0 && m_focalLength > 0) {
75  // everything is well known.. compute HFOV
77  m_cropFactor, m_srcImg.getSize());
78 
80  m_hfovText->SetValue(m_HFOVStr);
84  m_cropText->SetValue(m_cropFactorStr);
85  } else if (m_cropFactor > 0 && m_focalLength <= 0) {
86  // focal length unknown
88  m_cropText->SetValue(m_cropFactorStr);
89  m_okButton->Disable();
90  } else if (m_cropFactor <= 0 && m_focalLength > 0) {
91  // crop factor unknown
94  m_okButton->Disable();
95  } else {
96  // everything unknown
97  // assume a crop factor of one
98  m_cropFactor = 1;
100  m_cropText->SetValue(m_cropFactorStr);
101  m_okButton->Disable();
102  }
103  // set a proper size for this dialog
104  this->GetSizer()->SetSizeHints(this);
105 }
106 
107 void HFOVDialog::OnTypeChanged(wxCommandEvent & e)
108 {
110  DEBUG_DEBUG("new type: " << new_proj);
111  m_srcImg.setProjection(new_proj);
112  if (m_cropFactor > 0 && m_focalLength > 0) {
114  m_cropFactor, m_srcImg.getSize());
116  m_hfovText->SetValue(m_HFOVStr);
117  }
118 }
119 
120 void HFOVDialog::OnHFOVChanged(wxCommandEvent & e)
121 {
122  wxString text = m_hfovText->GetValue();
123  DEBUG_DEBUG("state: " << m_HFOVStr.mb_str(wxConvLocal) << ", change:" << text.mb_str(wxConvLocal));
124  DEBUG_DEBUG("cmd str: " << e.GetString().mb_str(wxConvLocal));
125  if (text.empty()) {
126  // ignore all empty hfov changes
127  return;
128  }
129  // ignore changes caused by ourself
130  if (m_hfovText->GetValue() == m_HFOVStr) {
131  DEBUG_DEBUG("ignoring programatic HFOV change");
132  return;
133  }
134 
135  // accept change
136  m_HFOVStr = text;
137 
138  if (text.empty()) {
139  m_HFOV = 0;
140  m_okButton->Disable();
141  return;
142  }
143 
144  if (!hugin_utils::str2double(text, m_HFOV)) {
145  m_okButton->Disable();
146  return;
147  }
148 
150 
151  if (m_HFOV <= 0) {
152  wxMessageBox(_("The horizontal field of view must be positive."));
153  m_HFOV = 50;
155  m_hfovText->SetValue(m_HFOVStr);
156  return;
157  }
158 
159  if (m_srcImg.getProjection() == HuginBase::SrcPanoImage::RECTILINEAR && m_HFOV > 179) {
160  DEBUG_DEBUG("HFOV " << m_HFOV << " too big, resetting to 179");
161  m_HFOV=179;
163  m_hfovText->SetValue(m_HFOVStr);
164  }
165 
166  if (m_cropFactor > 0) {
167  // set focal length only if crop factor is known
170  m_focalLengthText->SetValue(m_focalLengthStr);
171  }
172  m_okButton->Enable();
173 }
174 
175 void HFOVDialog::OnFocalLengthChanged(wxCommandEvent & e)
176 {
177  wxString text = m_focalLengthText->GetValue();
178  DEBUG_DEBUG(m_focalLengthStr.mb_str(wxConvLocal) << " => " << text.mb_str(wxConvLocal));
179  // ignore changes caused by ourself
180  if (m_focalLengthText->GetValue() == m_focalLengthStr) {
181  DEBUG_DEBUG("ignore focal length change");
182  return;
183  }
184  // accept change
185  m_focalLengthStr = text;
186 
187  if (text.empty()) {
188  m_focalLength = 0;
189  return;
190  }
192  return;
193  }
195 
196  // ignore leading zeros..
197  if (m_focalLength == 0) {
198  return;
199  }
200  if (m_focalLength <= 0) {
201  m_focalLength=1;
204  wxMessageBox(_("The focal length must be positive."));
205  }
206 
207  if (m_cropFactor > 0) {
208  // calculate HFOV.
210  m_cropFactor, m_srcImg.getSize());
212  m_hfovText->SetValue(m_HFOVStr);
213  m_okButton->Enable();
214  }
215 }
216 
217 void HFOVDialog::OnCropFactorChanged(wxCommandEvent & e)
218 {
219  // ignore changesd cause by ourself
220  wxString text = m_cropText->GetValue();
221  DEBUG_DEBUG(m_cropFactorStr.mb_str(wxConvLocal) << " => " << text.mb_str(wxConvLocal));
222  if (text == m_cropFactorStr) {
223  DEBUG_DEBUG("ignore crop change");
224  return;
225  }
226  // accept change
227  m_cropFactorStr = text;
228 
229  if (text.empty()) {
230  m_cropFactor = 0;
231  return;
232  }
234  return;
235  }
236 
237  // ignore leading zeros..
238  if (m_cropFactor == 0) {
239  m_cropFactorStr = text;
240  return;
241  }
242 
243  if (m_cropFactor <= 0) {
244  wxMessageBox(_("The crop factor must be positive."));
245  m_cropFactor=1;
247  m_cropText->SetValue(m_cropFactorStr);
248  return;
249  }
250 
251  if (m_focalLength > 0) {
253  m_cropFactor, m_srcImg.getSize());
255  m_hfovText->SetValue(m_HFOVStr);
256  m_okButton->Enable();
257  }
258 }
259 
260 void HFOVDialog::OnLoadLensParameters(wxCommandEvent & e)
261 {
262  HuginBase::Lens lens;
263  lens.setImageSize(m_srcImg.getSize());
264 
265  bool cropped=false;
266  bool autoCenterCrop=false;
267  vigra::Rect2D cropRect;
268 
269  if (LoadLensParametersChoose(this, lens, cropped, autoCenterCrop, cropRect)) {
270  m_HFOV = lens.getHFOV();
271  m_cropFactor = lens.getCropFactor();
272 
273  m_srcImg.setCropFactor(lens.getCropFactor());
274  m_srcImg.setHFOV(const_map_get(lens.variables,"v").getValue());
276 
278 
279  // geometrical distortion correction
280  std::vector<double> radialDist(4);
281  radialDist[0] = const_map_get(lens.variables,"a").getValue();
282  radialDist[1] = const_map_get(lens.variables,"b").getValue();
283  radialDist[2] = const_map_get(lens.variables,"c").getValue();
284  radialDist[3] = 1 - radialDist[0] - radialDist[1] - radialDist[2];
285  m_srcImg.setRadialDistortion(radialDist);
287  t.x = const_map_get(lens.variables,"d").getValue();
288  t.y = const_map_get(lens.variables,"e").getValue();
289  m_srcImg.setRadialDistortionCenterShift(t);
290  t.x = const_map_get(lens.variables,"g").getValue();
291  t.y = const_map_get(lens.variables,"t").getValue();
292  m_srcImg.setShear(t);
293 
294  // vignetting
295  std::vector<double> vigCorrCoeff(4);
296  vigCorrCoeff[0] = const_map_get(lens.variables,"Va").getValue();
297  vigCorrCoeff[1] = const_map_get(lens.variables,"Vb").getValue();
298  vigCorrCoeff[2] = const_map_get(lens.variables,"Vc").getValue();
299  vigCorrCoeff[3] = const_map_get(lens.variables,"Vd").getValue();
300  m_srcImg.setRadialVigCorrCoeff(vigCorrCoeff);
301  t.x = const_map_get(lens.variables,"Vx").getValue();
302  t.y = const_map_get(lens.variables,"Vy").getValue();
303  m_srcImg.setRadialVigCorrCenterShift(t);
304 
305  std::vector<float> resp(5);
306  resp[0] = const_map_get(lens.variables,"Ra").getValue();
307  resp[1] = const_map_get(lens.variables,"Rb").getValue();
308  resp[2] = const_map_get(lens.variables,"Rc").getValue();
309  resp[3] = const_map_get(lens.variables,"Rd").getValue();
310  resp[4] = const_map_get(lens.variables,"Re").getValue();
311  m_srcImg.setEMoRParams(resp);
312 
313  if (!cropped)
314  {
316  }
317  else
318  {
319  if (m_srcImg.isCircularCrop())
320  {
322  }
323  else
324  {
326  };
327  m_srcImg.setCropRect(cropRect);
328  };
329 
330  // display in GUI
334  m_cropText->SetValue(m_cropFactorStr);
336  m_hfovText->SetValue(m_HFOVStr);
337  SelectListValue(m_projChoice, m_srcImg.getProjection());
338 
339  // update lens type
340  m_okButton->Enable();
341  }
342 }
343 
344 
346 {
347  m_srcImg.setCropFactor(m_cropFactor);
348  m_srcImg.setHFOV(m_HFOV);
349  return m_srcImg;
350 }
351 
353 {
354  return m_cropFactor;
355 }
356 
358 {
359  return m_focalLength;
360 }
361 
362 void HFOVDialog::OnOk(wxCommandEvent & e)
363 {
364  if (m_srcImg.getProjection() == HuginBase::SrcPanoImage::FISHEYE_ORTHOGRAPHIC && m_HFOV>190)
365  {
366  if(wxMessageBox(
367  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),
368 #ifdef __WXMSW__
369  _("Hugin"),
370 #else
371  wxT(""),
372 #endif
373  wxICON_EXCLAMATION | wxYES_NO)==wxNO)
374  {
375  return;
376  };
377  };
378  EndModal(wxID_OK);
379 };
LensVarMap variables
Definition: Lens.h:106
void OnFocalLengthChanged(wxCommandEvent &e)
Definition: HFOVDialog.cpp:175
implementation of huginApp Class
void setCropMode(CropMode val)
Set the crop mode.
void setImageSize(const vigra::Size2D &sz)
set image size in pixels
Definition: Lens.h:93
bool str2double(const wxString &s, double &d)
Definition: wxPlatform.cpp:37
wxString m_HFOVStr
Definition: HFOVDialog.h:71
bool isCircularCrop() const
returns true, if projection requires cicular crop
#define HUGIN_CONV_FILENAME
Definition: platform.h:40
double m_focalLength
Definition: HFOVDialog.h:68
some helper classes for graphes
double getHFOV() const
get HFOV in degrees
Definition: Lens.cpp:47
wxString doubleTowxString(double d, int digits)
Definition: wxPlatform.cpp:31
HFOVDialog(wxWindow *parent, HuginBase::SrcPanoImage &srcImg)
ctor.
Definition: HFOVDialog.cpp:37
#define DEBUG_ASSERT(cond)
Definition: utils.h:80
include file for the hugin project
wxTextCtrl * m_cropText
Definition: HFOVDialog.h:60
void OnLoadLensParameters(wxCommandEvent &e)
Definition: HFOVDialog.cpp:260
const Map::mapped_type & const_map_get(const Map &m, const typename Map::key_type &key)
Definition: stl_utils.h:110
wxString m_cropFactorStr
Definition: HFOVDialog.h:69
void OnTypeChanged(wxCommandEvent &e)
Definition: HFOVDialog.cpp:107
wxTextCtrl * m_hfovText
Definition: HFOVDialog.h:62
LensProjectionFormat getProjection() const
get projection type
Definition: Lens.h:56
size_t GetSelectedValue(wxControlWithItems *list)
Returns the client value of the selected item from list.
Definition: LensTools.cpp:102
wxTextCtrl * m_focalLengthText
Definition: HFOVDialog.h:61
void OnCropFactorChanged(wxCommandEvent &e)
Definition: HFOVDialog.cpp:217
void OnOk(wxCommandEvent &e)
Definition: HFOVDialog.cpp:362
wxString m_focalLengthStr
Definition: HFOVDialog.h:67
static double calcFocalLength(SrcPanoImage::Projection proj, double hfov, double crop, vigra::Size2D imageSize)
calcualte focal length, given crop factor and hfov
wxButton * m_okButton
Definition: HFOVDialog.h:64
double GetFocalLength()
Definition: HFOVDialog.cpp:357
include file for the hugin project
void SelectListValue(wxControlWithItems *list, size_t newValue)
Selects the given value (stored in the client data) in the given list item.
Definition: LensTools.cpp:89
HuginBase::SrcPanoImage m_srcImg
Definition: HFOVDialog.h:66
double GetCropFactor()
Definition: HFOVDialog.cpp:352
#define DEBUG_DEBUG(msg)
Definition: utils.h:68
static double calcHFOV(SrcPanoImage::Projection proj, double fl, double crop, vigra::Size2D imageSize)
calculate hfov of an image given focal length, image size and crop factor
platform/compiler specific stuff.
double getCropFactor() const
get crop factor, d35mm/dreal
Definition: Lens.h:73
HuginBase::SrcPanoImage GetSrcImage()
Definition: HFOVDialog.cpp:345
All variables of a source image.
Definition: SrcPanoImage.h:194
void FillLensProjectionList(wxControlWithItems *list)
Fills a wxControlWithItem with all input projection formats, the client data contains the associated ...
Definition: LensTools.cpp:35
bool LoadLensParametersChoose(wxWindow *parent, HuginBase::Lens &lens, bool &cropped, bool &autoCenterCrop, vigra::Rect2D &cropRect)
load lens parameters from lens ini file
Definition: LensTools.cpp:290
void OnHFOVChanged(wxCommandEvent &e)
Definition: HFOVDialog.cpp:120
wxChoice * m_projChoice
Definition: HFOVDialog.h:63
double m_cropFactor
Definition: HFOVDialog.h:70
double m_HFOV
Definition: HFOVDialog.h:72