Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImageVariableDialog.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
11 /* This is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This software is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public
22  * License along with this software. If not, see
23  * <http://www.gnu.org/licenses/>.
24  *
25  */
26 
28 #include "base_wx/GraphTools.h"
29 #include "base_wx/wxPlatform.h"
30 #include "base_wx/wxutils.h"
31 #include "panoinc.h"
33 #include <map>
34 #include <string>
35 
36 #include "hugin/huginApp.h"
37 #include "base_wx/CommandHistory.h"
38 #include "base_wx/PanoCommand.h"
39 
41 {
42  // load our children. some children might need special
43  // initialization. this will be done later.
44  wxXmlResource::Get()->LoadDialog(this, parent, "image_variables_dialog");
45 
46  wxConfigBase * cfg = wxConfigBase::Get();
47  //position
48  int x = cfg->Read("/ImageVariablesDialog/positionX",-1l);
49  int y = cfg->Read("/ImageVariablesDialog/positionY",-1l);
50  if ( y >= 0 && x >= 0)
51  {
52  this->Move(x, y);
53  }
54  else
55  {
56  this->Move(0, 44);
57  };
58  m_pano=pano;
59  m_images=imgs;
60  m_popup=NULL;
61  InitValues();
62  // bind event handler
63  Bind(wxEVT_BUTTON, &ImageVariableDialog::OnOk, this, wxID_OK);
64  Bind(wxEVT_BUTTON, &ImageVariableDialog::OnHelp, this, wxID_HELP);
65  Bind(wxEVT_BUTTON, &ImageVariableDialog::OnShowDistortionGraph, this, XRCID("image_show_distortion_graph"));
66  Bind(wxEVT_BUTTON, &ImageVariableDialog::OnShowVignettingGraph, this, XRCID("image_show_vignetting_graph"));
67  Bind(wxEVT_BUTTON, &ImageVariableDialog::OnShowResponseGraph, this, XRCID("image_show_response_graph"));
68  Bind(wxEVT_CHOICE, &ImageVariableDialog::OnResponseSelected, this, XRCID("image_variable_responseType"));
69 };
70 
72 {
73  wxConfigBase * cfg = wxConfigBase::Get();
74  wxPoint ps = this->GetPosition();
75  cfg->Write("/ImageVariablesDialog/positionX", ps.x);
76  cfg->Write("/ImageVariablesDialog/positionY", ps.y);
77  cfg->Flush();
78 };
79 
81 {
82  XRCCTRL(*this, "image_variable_notebook", wxNotebook)->SetSelection(i);
83 };
84 
85 wxTextCtrl* GetImageVariableControl(const wxWindow* parent, const char* varname)
86 {
87  return wxStaticCast(
88  parent->FindWindow(
89  wxXmlResource::GetXRCID(
90  wxString("image_variable_").append(wxString(varname, wxConvLocal)).c_str()
91  )
92  ), wxTextCtrl
93  );
94 };
95 
97 {
98  if(m_images.empty())
99  {
100  return;
101  };
102  HuginBase::BaseSrcPanoImage::ResponseType responseType = m_pano->getImage(*m_images.begin()).getResponseType();
103  bool identical=true;
104 
105  for (HuginBase::UIntSet::const_iterator it = m_images.begin(); it != m_images.end() && identical; ++it)
106  {
107  identical=(responseType==m_pano->getImage(*it).getResponseType());
108  };
109  if(identical)
110  {
111  XRCCTRL(*this, "image_variable_responseType", wxChoice)->SetSelection(responseType);
112  };
113 
114  int degDigits = wxConfigBase::Get()->Read("/General/DegreeFractionalDigitsEdit",3);
115  int pixelDigits = wxConfigBase::Get()->Read("/General/PixelFractionalDigitsEdit",2);
116  int distDigitsEdit = wxConfigBase::Get()->Read("/General/DistortionFractionalDigitsEdit",5);
117 
119 
120  for (const char** varname = m_varNames; *varname != 0; ++varname)
121  {
122  // update parameters
123  int ndigits = distDigitsEdit;
124  if (strcmp(*varname, "y") == 0 || strcmp(*varname, "p") == 0 ||
125  strcmp(*varname, "r") == 0 || strcmp(*varname, "TrX") == 0 ||
126  strcmp(*varname, "TrY") == 0 || strcmp(*varname, "TrZ") == 0 )
127  {
128  ndigits=degDigits;
129  };
130  if (strcmp(*varname, "v") == 0 || strcmp(*varname, "d") == 0 ||
131  strcmp(*varname, "e") == 0 )
132  {
133  ndigits = pixelDigits;
134  }
135  double val=const_map_get(imgVarVector[*m_images.begin()],*varname).getValue();
136  bool identical=true;
137  for(HuginBase::UIntSet::const_iterator it=m_images.begin();it!=m_images.end() && identical;++it)
138  {
139  identical=(val==const_map_get(imgVarVector[*it],*varname).getValue());
140  };
141  if(identical)
142  {
143  GetImageVariableControl(this, *varname)->SetValue(hugin_utils::doubleTowxString(val,ndigits));
144  };
145  };
146  wxCommandEvent dummy;
147  OnResponseSelected(dummy);
148 };
149 
151 {
152  // translation
153  XRCCTRL(*this, "image_variable_text_translation", wxStaticText)->Show(newLevel==GUI_EXPERT);
154  XRCCTRL(*this, "image_variable_text_translation_x", wxStaticText)->Show(newLevel==GUI_EXPERT);
155  XRCCTRL(*this, "image_variable_text_translation_y", wxStaticText)->Show(newLevel==GUI_EXPERT);
156  XRCCTRL(*this, "image_variable_text_translation_z", wxStaticText)->Show(newLevel==GUI_EXPERT);
157  XRCCTRL(*this, "image_variable_text_translation_Tpy", wxStaticText)->Show(newLevel==GUI_EXPERT);
158  XRCCTRL(*this, "image_variable_text_translation_Tpp", wxStaticText)->Show(newLevel==GUI_EXPERT);
159  XRCCTRL(*this, "image_variable_TrX", wxTextCtrl)->Show(newLevel==GUI_EXPERT);
160  XRCCTRL(*this, "image_variable_TrY", wxTextCtrl)->Show(newLevel==GUI_EXPERT);
161  XRCCTRL(*this, "image_variable_TrZ", wxTextCtrl)->Show(newLevel==GUI_EXPERT);
162  XRCCTRL(*this, "image_variable_Tpy", wxTextCtrl)->Show(newLevel==GUI_EXPERT);
163  XRCCTRL(*this, "image_variable_Tpp", wxTextCtrl)->Show(newLevel==GUI_EXPERT);
164  // shear
165  XRCCTRL(*this, "image_variable_text_shear", wxStaticText)->Show(newLevel==GUI_EXPERT);
166  XRCCTRL(*this, "image_variable_text_shear_g", wxStaticText)->Show(newLevel==GUI_EXPERT);
167  XRCCTRL(*this, "image_variable_text_shear_t", wxStaticText)->Show(newLevel==GUI_EXPERT);
168  XRCCTRL(*this, "image_variable_g", wxTextCtrl)->Show(newLevel==GUI_EXPERT);
169  XRCCTRL(*this, "image_variable_t", wxTextCtrl)->Show(newLevel==GUI_EXPERT);
170 };
171 
173 {
174  std::vector<PanoCommand::PanoCommand*> commands;
175  HuginBase::VariableMap varMap;
176  for (const char** varname = m_varNames; *varname != 0; ++varname)
177  {
178  wxString s=GetImageVariableControl(this, *varname)->GetValue();
179  if(!s.empty())
180  {
181  double val;
182  if(hugin_utils::str2double(s,val))
183  {
184  if(strcmp(*varname, "v")==0)
185  {
186  if (val < 0.05)
187  {
188  hugin_utils::HuginMessageBox(_("The horizontal field of view must be positive."), _("Hugin"), wxICON_EXCLAMATION | wxOK, this);
189  return false;
190  };
191  switch(m_pano->getImage(*m_images.begin()).getProjection())
192  {
194  if(val>179)
195  {
196  val=179;
197  };
198  break;
200  if(val>190)
201  {
203  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?"), val),
204  _("Hugin"), wxICON_EXCLAMATION | wxYES_NO, this) == wxNO)
205  {
206  return false;
207  };
208  };
209  break;
210  default:
211  break;
212  };
213  };
214  varMap.insert(std::make_pair(std::string(*varname), HuginBase::Variable(std::string(*varname), val)));
215  }
216  else
217  {
218  wxLogError(_("Value must be numeric."));
219  return false;
220  };
221  };
222  };
223  int sel=XRCCTRL(*this, "image_variable_responseType", wxChoice)->GetSelection();
224  if(sel!=wxNOT_FOUND)
225  {
226  std::vector<HuginBase::SrcPanoImage> SrcImgs;
227  for (HuginBase::UIntSet::const_iterator it=m_images.begin(); it!=m_images.end(); ++it)
228  {
230  img.setResponseType((HuginBase::SrcPanoImage::ResponseType)sel);
231  SrcImgs.push_back(img);
232  }
233  commands.push_back(new PanoCommand::UpdateSrcImagesCmd( *m_pano, m_images, SrcImgs ));
234  }
235  if(!varMap.empty())
236  {
237  for(HuginBase::UIntSet::const_iterator it=m_images.begin();it!=m_images.end();++it)
238  {
239  commands.push_back(
241  );
242  };
243  };
244  if(!commands.empty())
245  {
247  return true;
248  }
249  else
250  {
251  return false;
252  };
253 };
254 
255 void ImageVariableDialog::OnOk(wxCommandEvent & e)
256 {
257  if(ApplyNewVariables())
258  {
259  e.Skip();
260  };
261 };
262 
263 void ImageVariableDialog::OnHelp(wxCommandEvent & e)
264 {
265  // open help on appropriate page
266  switch(XRCCTRL(*this, "image_variable_notebook", wxNotebook)->GetSelection())
267  {
268  //lens parameters
269  case 1:
270  MainFrame::Get()->DisplayHelp("Lens_correction_model.html");
271  break;
272  case 2:
273  MainFrame::Get()->DisplayHelp("Vignetting.html");
274  break;
275  case 3:
276  MainFrame::Get()->DisplayHelp("Camera_response_curve.html");
277  break;
278  default:
279  MainFrame::Get()->DisplayHelp("Image_positioning_model.html");
280  break;
281  };
282 };
283 
285 {
286  const bool showResponseParam = XRCCTRL(*this, "image_variable_responseType", wxChoice)->GetSelection() == 0;
287  wxTextCtrl* control = XRCCTRL(*this, "image_variable_Ra", wxTextCtrl);
288  control->Enable(showResponseParam);
289  control->Show(showResponseParam);
290  control = XRCCTRL(*this, "image_variable_Rb", wxTextCtrl);
291  control->Enable(showResponseParam);
292  control->Show(showResponseParam);
293  control = XRCCTRL(*this, "image_variable_Rc", wxTextCtrl);
294  control->Enable(showResponseParam);
295  control->Show(showResponseParam);
296  control = XRCCTRL(*this, "image_variable_Rd", wxTextCtrl);
297  control->Enable(showResponseParam);
298  control->Show(showResponseParam);
299  control = XRCCTRL(*this, "image_variable_Re", wxTextCtrl);
300  control->Enable(showResponseParam);
301  control->Show(showResponseParam);
302 };
303 
304 const char *ImageVariableDialog::m_varNames[] = { "y", "p", "r", "TrX", "TrY", "TrZ", "Tpy", "Tpp",
305  "v", "a", "b", "c", "d", "e", "g", "t",
306  "Eev", "Er", "Eb",
307  "Vb", "Vc", "Vd", "Vx", "Vy",
308  "Ra", "Rb", "Rc", "Rd", "Re", 0};
309 
311 {
312  wxString stringa=GetImageVariableControl(this, "a")->GetValue();
313  wxString stringb=GetImageVariableControl(this, "b")->GetValue();
314  wxString stringc=GetImageVariableControl(this, "c")->GetValue();
315  if(stringa.empty() || stringb.empty() || stringc.empty())
316  {
317  wxBell();
318  return;
319  };
320  std::vector<double> radialDist(4 ,0);
321  if(!hugin_utils::str2double(stringa, radialDist[0]) || !hugin_utils::str2double(stringb, radialDist[1]) || !hugin_utils::str2double(stringc, radialDist[2]))
322  {
323  wxBell();
324  return;
325  };
326  radialDist[3] = 1 - radialDist[0] - radialDist[1] - radialDist[2];
327 
328  //create transformation
330  srcImage.setSize(m_pano->getImage(*(m_images.begin())).getSize());
331  // set projection to rectilinear, just in case, it should be the default value
332  srcImage.setProjection(HuginBase::SrcPanoImage::RECTILINEAR);
333  srcImage.setRadialDistortion(radialDist);
334 
335  delete m_popup;
336  //show popup
338  wxWindow *button = (wxWindow*) e.GetEventObject();
339  wxPoint pos=button->ClientToScreen(wxPoint(0,0));
340  m_popup->Position(pos, button->GetSize());
341  m_popup->Popup();
342 };
343 
345 {
346  wxString stringVb=GetImageVariableControl(this, "Vb")->GetValue();
347  wxString stringVc=GetImageVariableControl(this, "Vc")->GetValue();
348  wxString stringVd=GetImageVariableControl(this, "Vd")->GetValue();
349  if(stringVb.empty() || stringVc.empty() || stringVd.empty())
350  {
351  wxBell();
352  return;
353  };
354  std::vector<double> vigCorr(4,0);
355  vigCorr[0]=1.0;
356  if(!hugin_utils::str2double(stringVb, vigCorr[1]) || !hugin_utils::str2double(stringVc, vigCorr[2]) || !hugin_utils::str2double(stringVd, vigCorr[3]))
357  {
358  wxBell();
359  return;
360  };
361  delete m_popup;
362  wxGraphTools::Graph graph(300, 200, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
363  graph.SetChartArea(10, 10, 290, 190);
364  graph.SetChartDisplay(0, 0.8, 1, 1);
365  graph.DrawGrid(6, 6);
366 
367  //create ResponseTransform with vignetting only
369  srcImage.setRadialVigCorrCoeff(vigCorr);
370 #define NRPOINTS 100
371  srcImage.setSize(vigra::Size2D(2*NRPOINTS, 2*NRPOINTS));
373  transform.enforceMonotonicity();
374 
375  //now calc vignetting curve
376  std::vector<hugin_utils::FDiff2D> points;
377 #define NRPOINTS 100
378  for(size_t i=0; i<=NRPOINTS; i++)
379  {
380  points.push_back(hugin_utils::FDiff2D(i/double(NRPOINTS),transform(1.0, hugin_utils::FDiff2D(NRPOINTS-i, NRPOINTS-i))));
381  };
382  graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 2);
383 
384  //display popup
385  m_popup = new wxGraphTools::GraphPopupWindow(this, graph.GetGraph());
386  wxWindow *button = (wxWindow*) e.GetEventObject();
387  wxPoint pos=button->ClientToScreen(wxPoint(0,0));
388  m_popup->Position(pos, button->GetSize());
389  m_popup->Popup();
390 };
391 
393 {
394  HuginBase::SrcPanoImage::ResponseType responseType=(HuginBase::SrcPanoImage::ResponseType)XRCCTRL(*this, "image_variable_responseType", wxChoice)->GetSelection();
395  wxString stringRa=GetImageVariableControl(this, "Ra")->GetValue();
396  wxString stringRb=GetImageVariableControl(this, "Rb")->GetValue();
397  wxString stringRc=GetImageVariableControl(this, "Rc")->GetValue();
398  wxString stringRd=GetImageVariableControl(this, "Rd")->GetValue();
399  wxString stringRe=GetImageVariableControl(this, "Re")->GetValue();
400  if(stringRa.empty() || stringRb.empty() || stringRc.empty() || stringRd.empty() || stringRe.empty())
401  {
402  wxBell();
403  return;
404  };
405  double Ra, Rb, Rc, Rd, Re;
406  if(!hugin_utils::str2double(stringRa, Ra) || !hugin_utils::str2double(stringRb, Rb) || !hugin_utils::str2double(stringRc, Rc) ||
407  !hugin_utils::str2double(stringRd, Rd) || !hugin_utils::str2double(stringRe, Re))
408  {
409  wxBell();
410  return;
411  };
412  delete m_popup;
413  wxGraphTools::Graph graph(300, 200, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
414  graph.SetChartArea(10, 10, 290, 190);
415  graph.SetChartDisplay(0, 0, 1, 1);
416  graph.DrawGrid(6, 6);
417  switch(responseType)
418  {
420  {
421  //draw standard EMOR curve
422  std::vector<float> emor(5, 0.0);
423  std::vector<double> outLutStd;
424  vigra_ext::EMoR::createEMoRLUT(emor, outLutStd);
426  graph.SetChartDisplay(0, 0, outLutStd.size()-1.0, 1.0);
427  std::vector<hugin_utils::FDiff2D> points;
428  for(size_t i=0; i<outLutStd.size(); i++)
429  {
430  points.push_back(hugin_utils::FDiff2D(i, outLutStd[i]));
431  };
432  graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 1);
433  outLutStd.clear();
434  points.clear();
435  // now draw our curve
436  emor[0]=Ra;
437  emor[1]=Rb;
438  emor[2]=Rc;
439  emor[3]=Rd;
440  emor[4]=Re;
441  std::vector<double> outLut;
442  vigra_ext::EMoR::createEMoRLUT(emor, outLut);
444  graph.SetChartDisplay(0, 0, outLut.size()-1.0, 1.0);
445  for(size_t i=0; i<outLut.size(); i++)
446  {
447  points.push_back(hugin_utils::FDiff2D(i, outLut[i]));
448  };
449  graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 2);
450  };
451  break;
453  default:
454  {
455  std::vector<hugin_utils::FDiff2D> points;
456  points.push_back(hugin_utils::FDiff2D(0, 0));
457  points.push_back(hugin_utils::FDiff2D(1, 1));
458  graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 2);
459  };
460  break;
461  };
462  //show popup
463  m_popup = new wxGraphTools::GraphPopupWindow(this, graph.GetGraph());
464  wxWindow *button = (wxWindow*) e.GetEventObject();
465  wxPoint pos=button->ClientToScreen(wxPoint(0,0));
466  m_popup->Position(pos, button->GetSize());
467  m_popup->Popup();
468 };
void DisplayHelp(wxString section=wxEmptyString)
call help browser with given file
Definition: MainFrame.cpp:1459
update source images
Definition: PanoCommand.h:404
#define NRPOINTS
void OnShowDistortionGraph(wxCommandEvent &e)
shows a popup with distortion graph
bool str2double(const wxString &s, double &d)
Definition: wxPlatform.cpp:37
SrcPanoImage getSrcImage(unsigned imgNr) const
get a description of a source image
Definition: Panorama.cpp:1620
void SetGuiLevel(GuiLevel newLevel)
sets the GuiLevel
radiometric transformation, includes exposure, vignetting and white balance.
void OnShowVignettingGraph(wxCommandEvent &e)
shows a popup with vignetting graph
void enforceMonotonicity(LUT &lut)
enforce monotonicity of an array (mostly used for lookup tables)
Definition: lut.h:87
wxString doubleTowxString(double d, int digits)
Definition: wxPlatform.cpp:31
void SelectTab(size_t i)
selects the tab with index i
a variable has a value and a name.
include file for the hugin project
update variables of a single image
Definition: PanoCommand.h:160
simple popup to show graph
Definition: GraphTools.h:38
vigra::pair< typename ROIImage< Image, Mask >::image_const_traverser, typename ROIImage< Image, Mask >::ImageConstAccessor > srcImage(const ROIImage< Image, Mask > &img)
Definition: ROIImage.h:300
void DrawGrid(size_t linesX, size_t linesY)
draws the grid with linesX lines in x-direction and linexY lines in y-direction
Definition: GraphTools.cpp:144
const Map::mapped_type & const_map_get(const Map &m, const typename Map::key_type &key)
Definition: stl_utils.h:110
void OnResponseSelected(wxCommandEvent &e)
response type changed
PanoCommand to combine other PanoCommands.
Definition: PanoCommand.h:39
std::set< unsigned int > UIntSet
Definition: PanoramaData.h:51
std::vector< VariableMap > VariableMapVector
Model for a panorama.
Definition: Panorama.h:152
empirical model of response
Definition: SrcPanoImage.h:100
wxGraphTools::GraphPopupWindow * m_popup
VariableMapVector getVariables() const
get variables of this panorama
Definition: Panorama.cpp:118
Definition of dialog to edit image variables.
void OnHelp(wxCommandEvent &e)
shows the help
static MainFrame * Get()
hack.. kind of a pseudo singleton...
Definition: MainFrame.cpp:2129
wxTextCtrl * GetImageVariableControl(const wxWindow *parent, const char *varname)
void SetChartArea(int left, int top, int right, int bottom)
set where to draw the chart on the bitmap
Definition: GraphTools.cpp:124
void SetChartDisplay(double xmin, double ymin, double xmax, double ymax)
set the real dimension of the chart
Definition: GraphTools.cpp:135
bool ApplyNewVariables()
applies the changed variables to the Panorama class, using CommandHistory
static GlobalCmdHist & getInstance()
void DrawLine(std::vector< hugin_utils::FDiff2D > points, wxColour colour, int penWidth=1)
draws a line with the coordinates given in points
Definition: GraphTools.cpp:160
void OnOk(wxCommandEvent &e)
Saves current state of all checkboxes when closing dialog with Ok.
void addCommand(PanoCommand *command, bool execute=true)
Adds a command to the history.
void createEMoRLUT(const std::vector< float > &params, VECTOR &lut)
Definition: emor.h:44
std::map< std::string, Variable > VariableMap
help class to draw charts
Definition: GraphTools.h:51
~ImageVariableDialog()
destructor, saves position
void OnShowResponseGraph(wxCommandEvent &e)
shows a popup with response graph
wxBitmap GetDistortionGraph(const HuginBase::SrcPanoImage &srcImage)
return wxBitmap with graph of distortion for given SrcPanoImage
Definition: GraphTools.cpp:192
void setSize(vigra::Size2D val)
Set the image size in pixels.
platform/compiler specific stuff.
ImageVariableDialog(wxWindow *parent, HuginBase::Panorama *pano, HuginBase::UIntSet imgs)
Constructor, read from xrc ressource; restore last uses settings and position.
const SrcPanoImage & getImage(std::size_t nr) const
get a panorama image, counting starts with 0
Definition: Panorama.h:211
GuiLevel
Definition: GuiLevel.h:31
const wxBitmap GetGraph() const
Definition: GraphTools.cpp:177
static const char * m_varNames[]
All variables of a source image.
Definition: SrcPanoImage.h:194
HuginBase::UIntSet m_images
HuginBase::Panorama * m_pano
int HuginMessageBox(const wxString &message, const wxString &caption, int style, wxWindow *parent)
Definition: wxutils.cpp:176
void InitValues()
copy the variables from Panorama to dialog