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 "wxutils.h"
35 #include "LensTools.h"
36 #include "HFOVDialog.h"
37 
38 HFOVDialog::HFOVDialog(wxWindow * parent, HuginBase::SrcPanoImage & srcImg)
39  : m_srcImg(srcImg)
40 {
41  m_HFOV = srcImg.getHFOV();
42  m_focalLength = srcImg.getExifFocalLength();
43  m_cropFactor = srcImg.getCropFactor();
44  wxXmlResource::Get()->LoadDialog(this, parent, "dlg_focallength");
45 
46  m_cropText = XRCCTRL(*this, "lensdlg_cropfactor_text", wxTextCtrl);
48  m_cropText->Bind(wxEVT_TEXT, &HFOVDialog::OnCropFactorChanged, this);
49 
50  m_hfovText = XRCCTRL(*this, "lensdlg_hfov_text", wxTextCtrl);
52  m_hfovText->Bind(wxEVT_TEXT, &HFOVDialog::OnHFOVChanged, this);
53 
54  m_focalLengthText = XRCCTRL(*this, "lensdlg_focallength_text", wxTextCtrl);
56  m_focalLengthText->Bind(wxEVT_TEXT, &HFOVDialog::OnFocalLengthChanged, this);
57 
58  m_projChoice = XRCCTRL(*this, "lensdlg_type_choice", wxChoice);
61  m_projChoice->Bind(wxEVT_CHOICE, &HFOVDialog::OnTypeChanged, this);
62 
63  m_okButton = XRCCTRL(*this, "wxID_OK", wxButton);
65  m_okButton->Bind(wxEVT_BUTTON, &HFOVDialog::OnOk, this);
66 
67  Bind(wxEVT_BUTTON, &HFOVDialog::OnLoadLensParameters, this, XRCID("lensdlg_load_lens_button"));
68  // fill fields
69  wxString fn(srcImg.getFilename().c_str(), HUGIN_CONV_FILENAME);
70  wxString message;
71  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());
72  XRCCTRL(*this, "lensdlg_message", wxStaticText)->SetLabel(message);
73  SelectListValue(m_projChoice, m_srcImg.getProjection());
74 
75  if (m_cropFactor > 0 && m_focalLength > 0) {
76  // everything is well known.. compute HFOV
78  m_cropFactor, m_srcImg.getSize());
79 
81  m_hfovText->SetValue(m_HFOVStr);
85  m_cropText->SetValue(m_cropFactorStr);
86  } else if (m_cropFactor > 0 && m_focalLength <= 0) {
87  // focal length unknown
89  m_cropText->SetValue(m_cropFactorStr);
90  m_okButton->Disable();
91  } else if (m_cropFactor <= 0 && m_focalLength > 0) {
92  // crop factor unknown
95  m_okButton->Disable();
96  } else {
97  // everything unknown
98  // assume a crop factor of one
99  m_cropFactor = 1;
101  m_cropText->SetValue(m_cropFactorStr);
102  m_okButton->Disable();
103  }
104  // set a proper size for this dialog
105  this->GetSizer()->SetSizeHints(this);
106 }
107 
108 void HFOVDialog::OnTypeChanged(wxCommandEvent & e)
109 {
111  DEBUG_DEBUG("new type: " << new_proj);
112  m_srcImg.setProjection(new_proj);
113  if (m_cropFactor > 0 && m_focalLength > 0) {
115  m_cropFactor, m_srcImg.getSize());
117  m_hfovText->SetValue(m_HFOVStr);
118  }
119 }
120 
121 void HFOVDialog::OnHFOVChanged(wxCommandEvent & e)
122 {
123  wxString text = m_hfovText->GetValue();
124  DEBUG_DEBUG("state: " << m_HFOVStr.mb_str(wxConvLocal) << ", change:" << text.mb_str(wxConvLocal));
125  DEBUG_DEBUG("cmd str: " << e.GetString().mb_str(wxConvLocal));
126  if (text.empty()) {
127  // ignore all empty hfov changes
128  return;
129  }
130  // ignore changes caused by ourself
131  if (m_hfovText->GetValue() == m_HFOVStr) {
132  DEBUG_DEBUG("ignoring programatic HFOV change");
133  return;
134  }
135 
136  // accept change
137  m_HFOVStr = text;
138 
139  if (text.empty()) {
140  m_HFOV = 0;
141  m_okButton->Disable();
142  return;
143  }
144 
145  if (!hugin_utils::str2double(text, m_HFOV)) {
146  m_okButton->Disable();
147  return;
148  }
149 
151 
152  if (m_HFOV <= 0) {
153  hugin_utils::HuginMessageBox(_("The horizontal field of view must be positive."), _("Hugin"), wxOK | wxICON_INFORMATION, wxGetActiveWindow());
154  m_HFOV = 50;
156  m_hfovText->SetValue(m_HFOVStr);
157  return;
158  }
159 
160  if (m_srcImg.getProjection() == HuginBase::SrcPanoImage::RECTILINEAR && m_HFOV > 179) {
161  DEBUG_DEBUG("HFOV " << m_HFOV << " too big, resetting to 179");
162  m_HFOV=179;
164  m_hfovText->SetValue(m_HFOVStr);
165  }
166 
167  if (m_cropFactor > 0) {
168  // set focal length only if crop factor is known
171  m_focalLengthText->SetValue(m_focalLengthStr);
172  }
173  m_okButton->Enable();
174 }
175 
176 void HFOVDialog::OnFocalLengthChanged(wxCommandEvent & e)
177 {
178  wxString text = m_focalLengthText->GetValue();
179  DEBUG_DEBUG(m_focalLengthStr.mb_str(wxConvLocal) << " => " << text.mb_str(wxConvLocal));
180  // ignore changes caused by ourself
181  if (m_focalLengthText->GetValue() == m_focalLengthStr) {
182  DEBUG_DEBUG("ignore focal length change");
183  return;
184  }
185  // accept change
186  m_focalLengthStr = text;
187 
188  if (text.empty()) {
189  m_focalLength = 0;
190  return;
191  }
193  return;
194  }
196 
197  // ignore leading zeros..
198  if (m_focalLength == 0) {
199  return;
200  }
201  if (m_focalLength <= 0) {
202  m_focalLength=1;
205  hugin_utils::HuginMessageBox(_("The focal length must be positive."), _("Hugin"), wxOK | wxICON_INFORMATION, wxGetActiveWindow());
206  }
207 
208  if (m_cropFactor > 0) {
209  // calculate HFOV.
211  m_cropFactor, m_srcImg.getSize());
213  m_hfovText->SetValue(m_HFOVStr);
214  m_okButton->Enable();
215  }
216 }
217 
218 void HFOVDialog::OnCropFactorChanged(wxCommandEvent & e)
219 {
220  // ignore changesd cause by ourself
221  wxString text = m_cropText->GetValue();
222  DEBUG_DEBUG(m_cropFactorStr.mb_str(wxConvLocal) << " => " << text.mb_str(wxConvLocal));
223  if (text == m_cropFactorStr) {
224  DEBUG_DEBUG("ignore crop change");
225  return;
226  }
227  // accept change
228  m_cropFactorStr = text;
229 
230  if (text.empty()) {
231  m_cropFactor = 0;
232  return;
233  }
235  return;
236  }
237 
238  // ignore leading zeros..
239  if (m_cropFactor == 0) {
240  m_cropFactorStr = text;
241  return;
242  }
243 
244  if (m_cropFactor <= 0) {
245  hugin_utils::HuginMessageBox(_("The crop factor must be positive."), _("Hugin"), wxOK | wxICON_INFORMATION, wxGetActiveWindow());
246  m_cropFactor=1;
248  m_cropText->SetValue(m_cropFactorStr);
249  return;
250  }
251 
252  if (m_focalLength > 0) {
254  m_cropFactor, m_srcImg.getSize());
256  m_hfovText->SetValue(m_HFOVStr);
257  m_okButton->Enable();
258  }
259 }
260 
261 void HFOVDialog::OnLoadLensParameters(wxCommandEvent & e)
262 {
263  HuginBase::Lens lens;
264  lens.setImageSize(m_srcImg.getSize());
265 
266  bool cropped=false;
267  bool autoCenterCrop=false;
268  vigra::Rect2D cropRect;
269 
270  if (LoadLensParametersChoose(this, lens, cropped, autoCenterCrop, cropRect)) {
271  m_HFOV = lens.getHFOV();
272  m_cropFactor = lens.getCropFactor();
273 
274  m_srcImg.setCropFactor(lens.getCropFactor());
275  m_srcImg.setHFOV(const_map_get(lens.variables,"v").getValue());
277 
279 
280  // geometrical distortion correction
281  std::vector<double> radialDist(4);
282  radialDist[0] = const_map_get(lens.variables,"a").getValue();
283  radialDist[1] = const_map_get(lens.variables,"b").getValue();
284  radialDist[2] = const_map_get(lens.variables,"c").getValue();
285  radialDist[3] = 1 - radialDist[0] - radialDist[1] - radialDist[2];
286  m_srcImg.setRadialDistortion(radialDist);
288  t.x = const_map_get(lens.variables,"d").getValue();
289  t.y = const_map_get(lens.variables,"e").getValue();
290  m_srcImg.setRadialDistortionCenterShift(t);
291  t.x = const_map_get(lens.variables,"g").getValue();
292  t.y = const_map_get(lens.variables,"t").getValue();
293  m_srcImg.setShear(t);
294 
295  // vignetting
296  std::vector<double> vigCorrCoeff(4);
297  vigCorrCoeff[0] = const_map_get(lens.variables,"Va").getValue();
298  vigCorrCoeff[1] = const_map_get(lens.variables,"Vb").getValue();
299  vigCorrCoeff[2] = const_map_get(lens.variables,"Vc").getValue();
300  vigCorrCoeff[3] = const_map_get(lens.variables,"Vd").getValue();
301  m_srcImg.setRadialVigCorrCoeff(vigCorrCoeff);
302  t.x = const_map_get(lens.variables,"Vx").getValue();
303  t.y = const_map_get(lens.variables,"Vy").getValue();
304  m_srcImg.setRadialVigCorrCenterShift(t);
305 
306  std::vector<float> resp(5);
307  resp[0] = const_map_get(lens.variables,"Ra").getValue();
308  resp[1] = const_map_get(lens.variables,"Rb").getValue();
309  resp[2] = const_map_get(lens.variables,"Rc").getValue();
310  resp[3] = const_map_get(lens.variables,"Rd").getValue();
311  resp[4] = const_map_get(lens.variables,"Re").getValue();
312  m_srcImg.setEMoRParams(resp);
313 
314  if (!cropped)
315  {
317  }
318  else
319  {
320  if (m_srcImg.isCircularCrop())
321  {
323  }
324  else
325  {
327  };
328  m_srcImg.setCropRect(cropRect);
329  };
330 
331  // display in GUI
335  m_cropText->SetValue(m_cropFactorStr);
337  m_hfovText->SetValue(m_HFOVStr);
338  SelectListValue(m_projChoice, m_srcImg.getProjection());
339 
340  // update lens type
341  m_okButton->Enable();
342  }
343 }
344 
345 
347 {
348  m_srcImg.setCropFactor(m_cropFactor);
349  m_srcImg.setHFOV(m_HFOV);
350  return m_srcImg;
351 }
352 
354 {
355  return m_cropFactor;
356 }
357 
359 {
360  return m_focalLength;
361 }
362 
363 void HFOVDialog::OnOk(wxCommandEvent & e)
364 {
365  if (m_srcImg.getProjection() == HuginBase::SrcPanoImage::FISHEYE_ORTHOGRAPHIC && m_HFOV>190)
366  {
368  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),
369  _("Hugin"), wxICON_EXCLAMATION | wxYES_NO, this) == wxNO)
370  {
371  return;
372  };
373  };
374  EndModal(wxID_OK);
375 };
LensVarMap variables
Definition: Lens.h:106
void OnFocalLengthChanged(wxCommandEvent &e)
Definition: HFOVDialog.cpp:176
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:38
#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:261
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:108
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:103
wxTextCtrl * m_focalLengthText
Definition: HFOVDialog.h:61
void OnCropFactorChanged(wxCommandEvent &e)
Definition: HFOVDialog.cpp:218
void OnOk(wxCommandEvent &e)
Definition: HFOVDialog.cpp:363
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:358
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:90
HuginBase::SrcPanoImage m_srcImg
Definition: HFOVDialog.h:66
double GetCropFactor()
Definition: HFOVDialog.cpp:353
#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:346
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:36
bool LoadLensParametersChoose(wxWindow *parent, HuginBase::Lens &lens, bool &cropped, bool &autoCenterCrop, vigra::Rect2D &cropRect)
load lens parameters from lens ini file
Definition: LensTools.cpp:291
int HuginMessageBox(const wxString &message, const wxString &caption, int style, wxWindow *parent)
Definition: wxutils.cpp:176
void OnHFOVChanged(wxCommandEvent &e)
Definition: HFOVDialog.cpp:121
wxChoice * m_projChoice
Definition: HFOVDialog.h:63
double m_cropFactor
Definition: HFOVDialog.h:70
double m_HFOV
Definition: HFOVDialog.h:72