Hugin trunk 0.1
Loading...
Searching...
No Matches
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
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);
49
50 m_hfovText = XRCCTRL(*this, "lensdlg_hfov_text", wxTextCtrl);
53
54 m_focalLengthText = XRCCTRL(*this, "lensdlg_focallength_text", wxTextCtrl);
57
58 m_projChoice = XRCCTRL(*this, "lensdlg_type_choice", wxChoice);
62
63 m_okButton = XRCCTRL(*this, "wxID_OK", wxButton);
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);
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();
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
120
121void 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
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
172 }
173 m_okButton->Enable();
174}
175
176void 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
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) {
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
218void 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
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) {
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
261void 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();
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 {
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
363void HFOVDialog::OnOk(wxCommandEvent & e)
364{
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 };
375};
void FillLensProjectionList(wxControlWithItems *list)
Fills a wxControlWithItem with all input projection formats, the client data contains the associated ...
Definition LensTools.cpp:36
size_t GetSelectedValue(wxControlWithItems *list)
Returns the client value of the selected item from list.
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
bool LoadLensParametersChoose(wxWindow *parent, HuginBase::Lens &lens, bool &cropped, bool &autoCenterCrop, vigra::Rect2D &cropRect)
load lens parameters from lens ini file
some helper classes for graphes
wxString m_HFOVStr
Definition HFOVDialog.h:71
double m_focalLength
Definition HFOVDialog.h:68
HuginBase::SrcPanoImage m_srcImg
Definition HFOVDialog.h:66
wxButton * m_okButton
Definition HFOVDialog.h:64
double m_cropFactor
Definition HFOVDialog.h:70
void OnTypeChanged(wxCommandEvent &e)
wxTextCtrl * m_focalLengthText
Definition HFOVDialog.h:61
HuginBase::SrcPanoImage GetSrcImage()
double m_HFOV
Definition HFOVDialog.h:72
wxTextCtrl * m_cropText
Definition HFOVDialog.h:60
void OnFocalLengthChanged(wxCommandEvent &e)
wxString m_cropFactorStr
Definition HFOVDialog.h:69
wxChoice * m_projChoice
Definition HFOVDialog.h:63
wxTextCtrl * m_hfovText
Definition HFOVDialog.h:62
HFOVDialog(wxWindow *parent, HuginBase::SrcPanoImage &srcImg)
ctor.
void OnLoadLensParameters(wxCommandEvent &e)
double GetCropFactor()
void OnHFOVChanged(wxCommandEvent &e)
void OnOk(wxCommandEvent &e)
double GetFocalLength()
void OnCropFactorChanged(wxCommandEvent &e)
wxString m_focalLengthStr
Definition HFOVDialog.h:67
double getHFOV() const
get HFOV in degrees
Definition Lens.cpp:47
void setImageSize(const vigra::Size2D &sz)
set image size in pixels
Definition Lens.h:93
double getCropFactor() const
get crop factor, d35mm/dreal
Definition Lens.h:73
LensVarMap variables
Definition Lens.h:106
LensProjectionFormat getProjection() const
get projection type
Definition Lens.h:56
All variables of a source image.
static double calcFocalLength(SrcPanoImage::Projection proj, double hfov, double crop, vigra::Size2D imageSize)
calcualte focal length, given crop factor and hfov
bool isCircularCrop() const
returns true, if projection requires cicular crop
void setCropMode(CropMode val)
Set the crop mode.
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
#define HUGIN_CONV_FILENAME
Definition platform.h:40
platform/compiler specific stuff.
#define DEBUG_ASSERT(cond)
Definition utils.h:80
#define DEBUG_DEBUG(msg)
Definition utils.h:68
bool str2double(const wxString &s, double &d)
wxString doubleTowxString(double d, int digits)
int HuginMessageBox(const wxString &message, const wxString &caption, int style, wxWindow *parent)
Definition wxutils.cpp:176
include file for the hugin project
include file for the hugin project
const Map::mapped_type & const_map_get(const Map &m, const typename Map::key_type &key)
Definition stl_utils.h:110
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.
Definition threshold.h:41
platform/compiler specific stuff.