Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FindPanoDialog.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 
27 #include "FindPanoDialog.h"
28 #include "base_wx/wxPlatform.h"
29 #include "panoinc.h"
31 #include "PTBatcherGUI.h"
32 #include "hugin_utils/alphanum.h"
33 #include "hugin/config_defaults.h"
34 #include "wx/mstream.h"
35 #ifdef _WIN32
36 // workaround for a conflict between exiv2 and wxWidgets/CMake built
37 #define HAVE_PID_T 1
38 #endif
39 #include <exiv2/exiv2.hpp>
40 #ifdef _WIN32
41 #include <commctrl.h>
42 #endif
43 #include "base_wx/LensTools.h"
45 #include "base_wx/wxutils.h"
46 
47 enum
48 {
49  ID_REMOVE_IMAGE = wxID_HIGHEST + 300,
50  ID_SPLIT_PANOS = wxID_HIGHEST + 301
51 };
52 
54 {
55  return doj::alphanum_comp(img1->getFilename(),img2->getFilename())<0;
56 };
57 
58 // thumbnail size currently set to 80x80
59 #define THUMBSIZE 80
60 
61 // provide some more translations for strings in wxDirPickerCtrl
62 #if 0
63 _("Browse");
64 #endif
65 
66 FindPanoDialog::FindPanoDialog(BatchFrame* batchframe, wxString xrcPrefix)
67 {
68  // load our children. some children might need special
69  // initialization. this will be done later.
70  wxXmlResource::Get()->LoadDialog(this,batchframe,"find_pano_dialog");
71 
72  m_batchframe=batchframe;
73  m_isRunning=false;
74  m_stopped=false;
75 
76  m_button_start=XRCCTRL(*this,"find_pano_start_stop",wxButton);
77  m_button_start->Bind(wxEVT_BUTTON, &FindPanoDialog::OnButtonStart, this);
78  m_button_send=XRCCTRL(*this,"find_pano_add_queue",wxButton);
79  m_button_send->Bind(wxEVT_BUTTON, &FindPanoDialog::OnButtonSend, this);
80  m_button_close=XRCCTRL(*this,"find_pano_close",wxButton);
81  m_button_close->Bind(wxEVT_BUTTON, &FindPanoDialog::OnButtonClose, this);
82  m_dirPicker=XRCCTRL(*this,"find_pano_dir",wxDirPickerCtrl);
83  m_cb_subdir=XRCCTRL(*this,"find_pano_subdir",wxCheckBox);
84  m_statustext=XRCCTRL(*this,"find_pano_label",wxStaticText);
85  m_list_pano=XRCCTRL(*this,"find_pano_list",wxCheckListBox);
86  m_list_pano->Bind(wxEVT_LISTBOX, &FindPanoDialog::OnSelectPossiblePano, this);
87  m_ch_naming=XRCCTRL(*this,"find_pano_naming",wxChoice);
88  m_cb_createLinks=XRCCTRL(*this,"find_pano_create_links",wxCheckBox);
89  m_cb_loadDistortion=XRCCTRL(*this,"find_pano_load_distortion",wxCheckBox);
90  m_cb_loadVignetting=XRCCTRL(*this,"find_pano_load_vignetting",wxCheckBox);
91  m_sc_minNumberImages=XRCCTRL(*this, "find_pano_min_number_images", wxSpinCtrl);
92  m_sc_maxTimeDiff=XRCCTRL(*this, "find_pano_max_time_diff", wxSpinCtrl);
93  m_ch_blender = XRCCTRL(*this, "find_pano_default_blender", wxChoice);
95 
96  //set parameters
97  wxConfigBase* config = wxConfigBase::Get();
98  // restore position and size
99  hugin_utils::RestoreFramePosition(this, "FindPanoDialog");
100  long splitterPos = config->Read("/FindPanoDialog/splitterPos", -1l);
101  if (splitterPos != -1)
102  {
103  XRCCTRL(*this, "find_pano_splitter", wxSplitterWindow)->SetSashPosition(splitterPos);
104  };
105  wxString path=config->Read("/FindPanoDialog/actualPath",wxEmptyString);
106  if(!path.IsEmpty())
107  {
108  m_dirPicker->SetPath(path);
109  }
110  bool val;
111  config->Read("/FindPanoDialog/includeSubDirs",&val,false);
112  m_cb_subdir->SetValue(val);
113  long i=config->Read("/FindPanoDialog/Naming",0l);
114  m_ch_naming->SetSelection(i);
115  config->Read("/FindPanoDialog/linkStacks",&val,true);
116  m_cb_createLinks->SetValue(val);
117  config->Read("/FindPanoDialog/loadDistortion",&val,false);
118  m_cb_loadDistortion->SetValue(val);
119  config->Read("/FindPanoDialog/loadVignetting",&val,false);
120  m_cb_loadVignetting->SetValue(val);
121  i=config->Read("/FindPanoDialog/MinNumberImages", 2l);
122  m_sc_minNumberImages->SetValue(i);
123  i=config->Read("/FindPanoDialog/MaxTimeDiff", 30l);
124  m_sc_maxTimeDiff->SetValue(i);
125  i = config->Read("/FindPanoDialog/DefaultBlender", static_cast<long>(HuginBase::PanoramaOptions::ENBLEND_BLEND));
127  m_button_send->Disable();
128  m_thumbs = new wxImageList(THUMBSIZE, THUMBSIZE, true, 0);
129  m_thumbsList = XRCCTRL(*this, "find_pano_selected_thumbslist", wxListCtrl);
130  m_thumbsList->SetImageList(m_thumbs, wxIMAGE_LIST_NORMAL);
131  m_thumbsList->Bind(wxEVT_MOTION, &FindPanoDialog::OnListMouseMove, this);
132  m_thumbsList->Bind(wxEVT_LIST_ITEM_RIGHT_CLICK, &FindPanoDialog::OnListItemRightClick, this);
133 #ifdef _WIN32
134  // default image spacing is too big, wxWidgets does not provide direct
135  // access to the spacing, so using the direct API function
136  ListView_SetIconSpacing(m_thumbsList->GetHandle(), THUMBSIZE + 20, THUMBSIZE + 20);
137 #endif
138  Bind(wxEVT_MENU, &FindPanoDialog::OnRemoveImage, this, ID_REMOVE_IMAGE);
139  Bind(wxEVT_MENU, &FindPanoDialog::OnSplitPanos, this, ID_SPLIT_PANOS);
140  Bind(wxEVT_CLOSE_WINDOW, &FindPanoDialog::OnClose, this);
141 };
142 
144 {
145  wxConfigBase* config=wxConfigBase::Get();
146  hugin_utils::StoreFramePosition(this, "FindPanoDialog");
147  config->Write("/FindPanoDialog/splitterPos", XRCCTRL(*this, "find_pano_splitter", wxSplitterWindow)->GetSashPosition());
148  config->Write("/FindPanoDialog/actualPath",m_dirPicker->GetPath());
149  config->Write("/FindPanoDialog/includeSubDirs",m_cb_subdir->GetValue());
150  config->Write("/FindPanoDialog/Naming",m_ch_naming->GetSelection());
151  config->Write("/FindPanoDialog/linkStacks",m_cb_createLinks->GetValue());
152  config->Write("/FindPanoDialog/loadDistortion",m_cb_loadDistortion->GetValue());
153  config->Write("/FindPanoDialog/loadVignetting",m_cb_loadDistortion->GetValue());
154  config->Write("/FindPanoDialog/MinNumberImages", m_sc_minNumberImages->GetValue());
155  config->Write("/FindPanoDialog/MaxTimeDiff", m_sc_maxTimeDiff->GetValue());
156  config->Write("/FindPanoDialog/DefaultBlender", static_cast<long>(GetSelectedValue(m_ch_blender)));
157  CleanUpPanolist();
158  delete m_thumbs;
159 };
160 
162 {
163  while(!m_panos.empty())
164  {
165  delete m_panos.back();
166  m_panos.pop_back();
167  };
168 };
169 
170 //prevent closing window when running detection
171 void FindPanoDialog::OnClose(wxCloseEvent& e)
172 {
173  if(e.CanVeto() && m_isRunning)
174  {
175  wxBell();
176  e.Veto();
177  }
178  else
179  {
180  e.Skip();
181  };
182 };
183 
184 void FindPanoDialog::OnButtonClose(wxCommandEvent& e)
185 {
186  if(!m_panos.empty())
187  {
188  if (hugin_utils::HuginMessageBox(_("The list contains possibly unprocessed panoramas.\nIf you close the dialog, you will lose them.\nContinue anyway?"),
189  _("PTBatcherGUI"), wxYES_NO | wxICON_WARNING, this) == wxNO)
190  {
191  return;
192  };
193  };
194  this->Close();
195 };
196 
197 void FindPanoDialog::OnButtonStart(wxCommandEvent& e)
198 {
199  if(m_isRunning)
200  {
201  //stop detection
202  m_stopped=true;
203  m_button_start->SetLabel(_("Accepted"));
204  }
205  else
206  {
207  //start detection
208  m_start_dir=m_dirPicker->GetPath();
209  if(wxDir::Exists(m_start_dir))
210  {
211  if(!m_panos.empty())
212  {
213  if (hugin_utils::HuginMessageBox(_("The list contains still not yet processed panoramas.\nIf you continue, they will be disregarded.\nDo you still want to continue?"),
214  _("PTBatcherGUI"), wxYES_NO | wxICON_WARNING, this) == wxNO)
215  {
216  return;
217  };
218  };
219  m_isRunning=true;
220  m_stopped=false;
221  //deactivate TIFF warning message boxes
222  m_oldtiffwarning=TIFFSetWarningHandler(NULL);
223  m_button_start->SetLabel(_("Stop"));
224  CleanUpPanolist();
225  m_list_pano->Clear();
226  wxCommandEvent dummy;
227  OnSelectPossiblePano(dummy);
228  EnableButtons(false);
229  SearchInDir(m_start_dir,m_cb_subdir->GetValue(), m_cb_loadDistortion->GetValue(), m_cb_loadVignetting->GetValue(),
230  m_sc_minNumberImages->GetValue(), m_sc_maxTimeDiff->GetValue());
231  }
232  else
233  {
234  hugin_utils::HuginMessageBox(wxString::Format(_("Directory %s does not exist.\nPlease give an existing directory."), m_start_dir),
235  _("PTBatcherGUI"), wxOK | wxICON_EXCLAMATION, this);
236  };
237  };
238 }
239 
240 void FindPanoDialog::OnButtonSend(wxCommandEvent& e)
241 {
242  if(m_panos.empty())
243  {
244  return;
245  }
246  unsigned int nr=0;
247  for(unsigned int i=0; i<m_list_pano->GetCount(); i++)
248  {
249  if(m_list_pano->IsChecked(i))
250  {
251  nr++;
252  };
253  };
254  if(nr==0)
255  {
256  hugin_utils::HuginMessageBox(_("You have not selected a panorama.\nPlease select at least one panorama and try again."), _("PTBatcherGUI"), wxOK | wxICON_EXCLAMATION, this);
257  return;
258  }
259  bool failed=false;
260  bool createLinks=m_cb_createLinks->GetValue();
261  for(unsigned int i=0; i<m_list_pano->GetCount(); i++)
262  {
263  if(m_list_pano->IsChecked(i))
264  {
265  wxString filename=m_panos[i]->GeneratePanorama((PossiblePano::NamingConvention)(m_ch_naming->GetSelection()),createLinks,
266  static_cast<HuginBase::PanoramaOptions::BlendingMechanism>(GetSelectedValue(m_ch_blender)));
267  if(!filename.IsEmpty())
268  {
270  }
271  else
272  {
273  failed=true;
274  };
275  };
276  };
277  if(failed)
278  {
279  hugin_utils::HuginMessageBox(_("Not all project files could be written successfully.\nMaybe you have no write permission for these directories or your disc is full."), _("PTBatcherGUI"), wxOK, this);
280  };
281  this->Close();
282 };
283 
284 void FindPanoDialog::EnableButtons(const bool state)
285 {
286  m_dirPicker->Enable(state);
287  m_cb_subdir->Enable(state);
288  m_ch_naming->Enable(state);
289  m_cb_createLinks->Enable(state);
290  m_button_close->Enable(state);
291  m_button_send->Enable(state);
292 };
293 
295 {
296  int selected = m_list_pano->GetSelection();
297  if (selected != wxNOT_FOUND)
298  {
299  XRCCTRL(*this, "find_pano_selected_cam", wxStaticText)->SetLabel(m_panos[selected]->GetCameraName());
300  XRCCTRL(*this, "find_pano_selected_lens", wxStaticText)->SetLabel(m_panos[selected]->GetLensName());
301  XRCCTRL(*this, "find_pano_selected_focallength", wxStaticText)->SetLabel(m_panos[selected]->GetFocalLength());
302  XRCCTRL(*this, "find_pano_selected_date_time", wxStaticText)->SetLabel(m_panos[selected]->GetStartString() + " ("+ m_panos[selected]->GetDuration() + ")");
303  m_panos[selected]->PopulateListCtrl(m_thumbsList, m_thumbs, m_tooltips);
304  }
305  else
306  {
307  XRCCTRL(*this, "find_pano_selected_cam", wxStaticText)->SetLabel(wxEmptyString);
308  XRCCTRL(*this, "find_pano_selected_lens", wxStaticText)->SetLabel(wxEmptyString);
309  XRCCTRL(*this, "find_pano_selected_focallength", wxStaticText)->SetLabel(wxEmptyString);
310  XRCCTRL(*this, "find_pano_selected_date_time", wxStaticText)->SetLabel(wxEmptyString);
311  m_thumbsList->DeleteAllItems();
312  m_thumbs->RemoveAll();
313  m_tooltips.Clear();
314  };
315 };
316 
318 {
319  // build menu
320  wxMenu contextMenu;
321  const int selectedPano = m_list_pano->GetSelection();
322  if (m_panos[selectedPano]->GetImageCount() > 2)
323  {
324  contextMenu.Append(ID_REMOVE_IMAGE, _("Remove image from project"));
325  };
326  long imageIndex = -1;
327  imageIndex = m_thumbsList->GetNextItem(imageIndex, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
328  if(imageIndex > 1 && imageIndex <= static_cast<long>(m_panos[selectedPano]->GetImageCount()) - 2)
329  {
330  contextMenu.Append(ID_SPLIT_PANOS, _("Split here into two panoramas"));
331  }
332  // show popup menu
333  if (contextMenu.GetMenuItemCount() > 0)
334  {
335  PopupMenu(&contextMenu);
336  };
337 };
338 
339 void FindPanoDialog::OnRemoveImage(wxCommandEvent &e)
340 {
341  const int selectedPano = m_list_pano->GetSelection();
342  if (selectedPano != wxNOT_FOUND)
343  {
344  if (m_panos[selectedPano]->GetImageCount() > 2)
345  {
346  long imageIndex = -1;
347  imageIndex = m_thumbsList->GetNextItem(imageIndex, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
348  if (imageIndex != wxNOT_FOUND)
349  {
350  // remove image from possible pano
351  m_panos[selectedPano]->RemoveImage(imageIndex);
352  // now remove from the wxListCtrl
353  m_thumbsList->DeleteItem(imageIndex);
354  // update the pano list
355  m_list_pano->SetString(selectedPano, m_panos[selectedPano]->GetItemString(m_start_dir));
356  // update the labels above
357  wxCommandEvent dummy;
358  OnSelectPossiblePano(dummy);
359  };
360  };
361  };
362 };
363 
364 void FindPanoDialog::OnSplitPanos(wxCommandEvent &e)
365 {
366  const int selectedPano = m_list_pano->GetSelection();
367  if (selectedPano != wxNOT_FOUND)
368  {
369  long imageIndex = -1;
370  imageIndex = m_thumbsList->GetNextItem(imageIndex, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
371  if (imageIndex != wxNOT_FOUND)
372  {
373  if (imageIndex > 1 && imageIndex <= static_cast<long>(m_panos[selectedPano]->GetImageCount()) - 2)
374  {
375  // do split
376  PossiblePano* newSubPano = m_panos[selectedPano]->SplitPano(imageIndex);
377  if (newSubPano->GetImageCount() > 0)
378  {
379  // insert new pano into internal list
380  m_panos.insert(m_panos.begin() + selectedPano + 1, newSubPano);
381  // update pano list
382  m_list_pano->SetString(selectedPano, m_panos[selectedPano]->GetItemString(m_start_dir));
383  int newItem = m_list_pano->Insert(m_panos[selectedPano + 1]->GetItemString(m_start_dir), selectedPano + 1);
384  m_list_pano->Check(newItem, true);
385  // update display
386  wxCommandEvent dummy;
387  OnSelectPossiblePano(dummy);
388  }
389  else
390  {
391  wxBell();
392  delete newSubPano;
393  };
394  };
395  };
396  };
397 }
398 
399 void FindPanoDialog::OnListMouseMove(wxMouseEvent & e)
400 {
401  if (m_tooltips.IsEmpty())
402  {
403  return;
404  }
405  int flags;
406  long item = m_thumbsList->HitTest(e.GetPosition(), flags);
407  if (item != wxNOT_FOUND && (flags&wxLIST_HITTEST_ONITEM) && item < m_tooltips.GetCount())
408  {
409  m_thumbsList->SetToolTip(m_tooltips[item]);
410  }
411  else
412  {
413  m_thumbsList->UnsetToolTip();
414  };
415 };
416 
417 int SortWxFilenames(const wxString& s1,const wxString& s2)
418 {
419  return doj::alphanum_comp(std::string(s1.mb_str(wxConvLocal)),std::string(s2.mb_str(wxConvLocal)));
420 };
421 
422 void FindPanoDialog::SearchInDir(wxString dirstring, const bool includeSubdir, const bool loadDistortion, const bool loadVignetting, const size_t minNumberImages, const size_t maxTimeDiff)
423 {
424  std::vector<PossiblePano*> newPanos;
425  wxTimeSpan max_diff(0, 0, maxTimeDiff, 0);
426  wxString filename;
427  wxArrayString fileList;
428  wxDir::GetAllFiles(dirstring,&fileList,wxEmptyString,wxDIR_FILES|wxDIR_HIDDEN);
429  fileList.Sort(SortWxFilenames);
430  //map for caching projection information to prevent reading from database for each image
431  for(size_t j=0; j<fileList.size() && !m_stopped; j++)
432  {
433  m_statustext->SetLabel(wxString::Format(_("Reading file %s"),fileList[j].c_str()));
434  wxFileName file(fileList[j]);
435  file.MakeAbsolute();
436  wxString ext=file.GetExt();
437  if(ext.CmpNoCase("jpg")==0 || ext.CmpNoCase("jpeg")==0 ||
438  ext.CmpNoCase("tif")==0 || ext.CmpNoCase("tiff")==0)
439  {
440  std::string filenamestr(file.GetFullPath().mb_str(HUGIN_CONV_FILENAME));
442  img->setFilename(filenamestr);
443  img->readEXIF();
444  // check for black/white images, if so skip
445  const HuginBase::FileMetaData& metadata = img->getFileMetadata();
446  HuginBase::FileMetaData::const_iterator it = metadata.find("pixeltype");
447  if (it != metadata.end())
448  {
449  if (it->second == "BILEVEL")
450  {
451  wxGetApp().Yield(true);
452  continue;
453  };
454  };
455  img->applyEXIFValues();
456  if(!img->getExifMake().empty() && !img->getExifModel().empty() &&
457  img->getExifFocalLength()!=0 && img->getCropFactor()!=0)
458  {
459  img->readProjectionFromDB(false);
460  if(loadDistortion)
461  {
462  img->readDistortionFromDB();
463  };
464  if(loadVignetting)
465  {
466  img->readVignettingFromDB();
467  };
468  bool found=false;
469  for(unsigned int i=0; i<newPanos.size() && !m_stopped && !found; i++)
470  {
471  //compare with all other image groups
472  if(newPanos[i]->BelongsTo(img,max_diff))
473  {
474  newPanos[i]->AddSrcPanoImage(img);
475  found=true;
476  };
477  if(i%10==0)
478  {
479  wxGetApp().Yield(true);
480  };
481  };
482  if(!found)
483  {
484  PossiblePano* newPano=new PossiblePano();
485  newPano->AddSrcPanoImage(img);
486  newPanos.push_back(newPano);
487  };
488  }
489  else
490  {
491  //could not read exif infos, disregard this image
492  delete img;
493  };
494  };
495  //allow processing events
496  wxGetApp().Yield(true);
497  };
498  if(!m_stopped && !newPanos.empty())
499  {
500  for(size_t i=0; i<newPanos.size(); i++)
501  {
502  if(newPanos[i]->GetImageCount()>=minNumberImages)
503  {
504  m_panos.push_back(newPanos[i]);
505  int newItem=m_list_pano->Append(m_panos[m_panos.size()-1]->GetItemString(m_start_dir));
506  m_list_pano->Check(newItem,true);
507  }
508  else
509  {
510  delete newPanos[i];
511  };
512  };
513  };
514 
515  if(includeSubdir && !m_stopped)
516  {
517  //now we go into all directories
518  wxDir dir(dirstring);
519  bool cont=dir.GetFirst(&filename,wxEmptyString,wxDIR_DIRS);
520  while(cont && !m_stopped)
521  {
522  SearchInDir(dir.GetName()+wxFileName::GetPathSeparator()+filename,includeSubdir, loadDistortion, loadVignetting, minNumberImages, maxTimeDiff);
523  cont=dir.GetNext(&filename);
524  }
525  };
526  if(m_start_dir.Cmp(dirstring)==0)
527  {
528  m_stopped=false;
529  m_isRunning=false;
530  m_button_start->SetLabel(_("Start"));
531  EnableButtons(true);
532  //enable send button if at least one panorama found
533  m_button_send->Enable(!m_panos.empty());
534  if(!m_panos.empty())
535  {
536  m_statustext->SetLabel(wxString::Format(_("Found %d possible panoramas"), static_cast<int>(m_panos.size())));
537  }
538  else
539  {
540  m_statustext->SetLabel(_("No possible panoramas found"));
541  };
542  TIFFSetWarningHandler(m_oldtiffwarning);
543  };
544 };
545 
547 {
548  if(!m_images.empty())
549  {
550  for(ImageSet::reverse_iterator it=m_images.rbegin(); it!=m_images.rend(); ++it)
551  {
552  delete (*it);
553  }
554  };
555 };
556 
557 bool PossiblePano::BelongsTo(HuginBase::SrcPanoImage* img, const wxTimeSpan max_time_diff)
558 {
559  if(m_make.compare(img->getExifMake())!=0)
560  {
561  return false;
562  }
563  if(m_camera.compare(img->getExifModel())!=0)
564  {
565  return false;
566  }
567  if(m_lens.compare(img->getExifLens())!=0)
568  {
569  return false;
570  }
571  if(fabs(m_focallength-img->getExifFocalLength())>0.01)
572  {
573  return false;
574  }
575  if (fabs(m_cropfactor - img->getCropFactor()) > 0.01)
576  {
577  return false;
578  }
579  if(m_size!=img->getSize())
580  {
581  return false;
582  }
583  if(!GetDateTime(img).IsBetween(m_dt_start-max_time_diff,m_dt_end+max_time_diff))
584  {
585  return false;
586  };
587  return true;
588 };
589 
591 {
592  struct tm exifdatetime;
593  if(img->getExifDateTime(&exifdatetime)==0)
594  {
595  return wxDateTime(exifdatetime);
596  }
597  else
598  {
599  wxFileName file(wxString(img->getFilename().c_str(),HUGIN_CONV_FILENAME));
600  return file.GetModificationTime();
601  };
602 };
603 
605 {
606  if(m_images.empty())
607  {
608  //fill all values from first image
609  m_make=img->getExifMake();
610  m_camera=img->getExifModel();
611  m_lens=img->getExifLens();
612  m_focallength=img->getExifFocalLength();
613  m_cropfactor = img->getCropFactor();
614  m_size=img->getSize();
615  m_dt_start=GetDateTime(img);
617  }
618  else
619  {
620  wxDateTime dt=GetDateTime(img);
621  if(dt.IsEarlierThan(m_dt_start))
622  {
623  m_dt_start=dt;
624  }
625  if(dt.IsLaterThan(m_dt_end))
626  {
627  m_dt_end=dt;
628  };
629  };
630  m_images.insert(img);
631 };
632 
633 const wxString PossiblePano::GetFilestring(const wxString BasePath, const bool stripExtension) const
634 {
635  ImageSet::const_iterator it=m_images.begin();
636  wxFileName f1(wxString((*it)->getFilename().c_str(),HUGIN_CONV_FILENAME));
637  f1.MakeRelativeTo(BasePath);
638  ImageSet::const_reverse_iterator rit=m_images.rbegin();
639  wxFileName f2(wxString((*rit)->getFilename().c_str(),HUGIN_CONV_FILENAME));
640  if(stripExtension)
641  {
642  return f1.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR)+f1.GetName()+"-"+f2.GetName();
643  }
644  else
645  {
646  return f1.GetFullPath()+" - "+f2.GetFullName();
647  };
648 };
649 
650 const wxString PossiblePano::GetItemString(const wxString BasePath) const
651 {
652  return wxString::Format(_("%d images: %s"), static_cast<int>(m_images.size()), GetFilestring(BasePath).c_str());
653 };
654 
655 bool PossiblePano::GetNewProjectFilename(NamingConvention nc,const wxString basePath, wxFileName& projectFile)
656 {
657  wxString mask;
658  unsigned int i=1;
659  projectFile.SetPath(basePath);
660  projectFile.SetName("pano");
661  projectFile.SetExt("pto");
662  if(!projectFile.IsDirWritable())
663  {
664  return false;
665  };
666  switch(nc)
667  {
668  case NAMING_PANO:
669  mask="panorama%d";
670  break;
671  case NAMING_FIRST_LAST:
672  mask=GetFilestring(basePath,true);
673  projectFile.SetName(mask);
674  if(!projectFile.FileExists())
675  {
676  return true;
677  };
678  mask=mask+"_%d";
679  break;
680  case NAMING_FOLDER:
681  {
682  wxArrayString folders=projectFile.GetDirs();
683  if(folders.GetCount()==0)
684  {
685  return false;
686  }
687  mask=folders.Last();
688  projectFile.SetName(mask);
689  if(!projectFile.FileExists())
690  {
691  return true;
692  }
693  mask=mask+"_%d";
694  }
695  break;
696  case NAMING_TEMPLATE:
697  {
698  HuginBase::Panorama tempPano;
699  tempPano.addImage(**m_images.begin());
700  tempPano.addImage(**m_images.rbegin());
701  wxFileName newProject(getDefaultProjectName(tempPano));
702  mask=newProject.GetName();
703  projectFile.SetName(mask);
704  if(!projectFile.FileExists())
705  {
706  return true;
707  }
708  mask=mask+"_%d";
709  };
710  break;
711  default:
712  mask="panorama%d";
713  };
714 
715  projectFile.SetName(wxString::Format(mask,i));
716  while(projectFile.FileExists())
717  {
718  i++;
719  projectFile.SetName(wxString::Format(mask,i));
720  //security fall through
721  if(i>1000)
722  {
723  return false;
724  };
725  }
726  return true;
727 };
728 
730 {
731  if(m_images.empty())
732  {
733  return wxEmptyString;
734  };
735  ImageSet::const_iterator it=m_images.begin();
736  wxFileName firstFile(wxString((*it)->getFilename().c_str(),HUGIN_CONV_FILENAME));
737  firstFile.MakeAbsolute();
738  wxFileName projectFile;
739  if(!GetNewProjectFilename(nc,firstFile.GetPath(),projectFile))
740  {
741  return wxEmptyString;
742  };
743  //generate panorama
744  double redBalanceAnchor = (*m_images.begin())->getExifRedBalance();
745  double blueBalanceAnchor = (*m_images.begin())->getExifBlueBalance();
746  if (fabs(redBalanceAnchor)<1e-2)
747  {
748  redBalanceAnchor = 1;
749  };
750  if (fabs(blueBalanceAnchor)<1e-2)
751  {
752  blueBalanceAnchor = 1;
753  };
754  HuginBase::Panorama pano;
755  for(ImageSet::iterator it=m_images.begin(); it!=m_images.end(); ++it)
756  {
757  (*it)->setWhiteBalanceRed((*it)->getExifRedBalance() / redBalanceAnchor);
758  (*it)->setWhiteBalanceBlue((*it)->getExifBlueBalance() / blueBalanceAnchor);
759  pano.addImage(*(*it));
760  };
761  //assign all images the same lens number
762  HuginBase::StandardImageVariableGroups variable_groups(pano);
763  HuginBase::ImageVariableGroup& lenses = variable_groups.getLenses();
764  if(pano.getNrOfImages()>1)
765  {
766  for(unsigned int i=1; i<pano.getNrOfImages(); i++)
767  {
768  lenses.switchParts(i, lenses.getPartNumber(0));
769  };
770  };
771  if (pano.hasPossibleStacks())
772  {
773  pano.linkPossibleStacks(createLinks);
774  };
775  // Setup pano with options from preferences
777  //set default exposure value
778  opts.outputExposureValue = pano.getImage(0).getExposureValue();
779  wxConfigBase* config = wxConfigBase::Get();
780  opts.quality = config->Read("/output/jpeg_quality",HUGIN_JPEG_QUALITY);
781  switch(config->Read("/output/tiff_compression", HUGIN_TIFF_COMPRESSION))
782  {
783  case 0:
784  default:
785  opts.outputImageTypeCompression = "NONE";
786  opts.tiffCompression = "NONE";
787  break;
788  case 1:
789  opts.outputImageTypeCompression = "PACKBITS";
790  opts.tiffCompression = "PACKBITS";
791  break;
792  case 2:
793  opts.outputImageTypeCompression = "LZW";
794  opts.tiffCompression = "LZW";
795  break;
796  case 3:
797  opts.outputImageTypeCompression = "DEFLATE";
798  opts.tiffCompression = "DEFLATE";
799  break;
800  }
801  switch (config->Read("/output/ldr_format", HUGIN_LDR_OUTPUT_FORMAT))
802  {
803  case 1:
804  opts.outputImageType ="jpg";
805  break;
806  case 2:
807  opts.outputImageType ="png";
808  break;
809  case 3:
810  opts.outputImageType ="exr";
811  break;
812  default:
813  case 0:
814  opts.outputImageType ="tif";
815  break;
816  }
818  opts.blendMode = defaultBlender;
819  opts.enblendOptions = config->Read("Enblend/Args",HUGIN_ENBLEND_ARGS).mb_str(wxConvLocal);
820  opts.enfuseOptions = config->Read("Enfuse/Args",HUGIN_ENFUSE_ARGS).mb_str(wxConvLocal);
821  opts.interpolator = (vigra_ext::Interpolator)config->Read("Nona/Interpolator",HUGIN_NONA_INTERPOLATOR);
822  opts.tiff_saveROI = config->Read("Nona/CroppedImages",HUGIN_NONA_CROPPEDIMAGES)!=0;
825  opts.verdandiOptions = config->Read("/VerdandiDefaultArgs", wxEmptyString).mb_str(wxConvLocal);
826  pano.setOptions(opts);
827  // set optimizer switches
830 
831  if (pano.WritePTOFile(std::string(projectFile.GetFullPath().mb_str(HUGIN_CONV_FILENAME)),
832  std::string(projectFile.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR).mb_str(HUGIN_CONV_FILENAME))))
833  {
834  return projectFile.GetFullPath();
835  }
836  else
837  {
838  return wxEmptyString;
839  };
840 };
841 
843 {
844  return wxString(m_camera.c_str(), wxConvLocal);
845 }
846 
848 {
849  return wxString(m_lens.c_str(), wxConvLocal);
850 };
851 
853 {
854  if (!m_images.empty())
855  {
856  return FormatString::GetFocalLength(*m_images.begin());
857  };
858  return wxString::Format("%0.1f mm", m_focallength);
859 };
860 
862 {
863  return m_dt_start.Format();
864 };
865 
867 {
869 };
870 
871 void PossiblePano::PopulateListCtrl(wxListCtrl* list, wxImageList* thumbs, wxArrayString& tooltips)
872 {
873  list->DeleteAllItems();
874  thumbs->RemoveAll();
875  tooltips.Clear();
876  wxBusyCursor cursor;
877  for (ImageSet::iterator it = m_images.begin(); it != m_images.end(); ++it)
878  {
879 #if defined EXIV2_VERSION && EXIV2_TEST_VERSION(0,27,99)
880  Exiv2::Image::UniquePtr image;
881 #else
882  Exiv2::Image::AutoPtr image;
883 #endif
884  bool opened = false;
885  try
886  {
887  image = Exiv2::ImageFactory::open((*it)->getFilename().c_str());
888  opened = true;
889  }
890  catch (...)
891  {
892  std::cerr << __FILE__ << " " << __LINE__ << " Error opening file" << std::endl;
893  continue;
894  }
895  int index = -1;
896  if (opened)
897  {
898  try
899  {
900  image->readMetadata();
901  }
902  catch (const Exiv2::Error& e)
903  {
904  std::cerr << __FILE__ << " " << __LINE__ << " Exiv2: Error reading metadata (" << e.what() << ")" << std::endl;
905  continue;
906  }
907  // read all thumbnails
908  Exiv2::PreviewManager previews(*image);
909  Exiv2::PreviewPropertiesList lists = previews.getPreviewProperties();
910  if (!lists.empty())
911  {
912  // select a preview with matching size
913  int previewIndex = 0;
914  while (previewIndex < lists.size() - 1 && lists[previewIndex].width_ < THUMBSIZE && lists[previewIndex].height_ < THUMBSIZE)
915  {
916  ++previewIndex;
917  };
918  // load preview image to wxImage
919  wxImage rawImage;
920  Exiv2::PreviewImage previewImage = previews.getPreviewImage(lists[previewIndex]);
921  wxMemoryInputStream stream(previewImage.pData(), previewImage.size());
922  rawImage.LoadFile(stream, wxString(previewImage.mimeType().c_str(), wxConvLocal), -1);
923  int x = 0;
924  int y = 0;
925  if (previewImage.width() > previewImage.height())
926  {
927  //landscape format
928  int newHeight = THUMBSIZE*previewImage.height() / previewImage.width();
929  rawImage.Rescale(THUMBSIZE, newHeight);
930  x = 0;
931  y = (THUMBSIZE - newHeight) / 2;
932  }
933  else
934  {
935  //portrait format
936  int newWidth = THUMBSIZE*previewImage.width() / previewImage.height();
937  rawImage.Rescale(newWidth, THUMBSIZE);
938  x = (THUMBSIZE - newWidth) / 2;
939  y = 0;
940  }
941  // rotate according to orientation tag
942  if ((*it)->getRoll() == 90)
943  {
944  rawImage = rawImage.Rotate90();
945  std::swap(x, y);
946  }
947  else
948  {
949  if ((*it)->getRoll() == 270)
950  {
951  rawImage = rawImage.Rotate90(false);
952  std::swap(x, y);
953  }
954  else
955  {
956  if ((*it)->getRoll() == 180)
957  {
958  rawImage = rawImage.Rotate180();
959  };
960  };
961  };
962  // create final bitmap with centered thumbnail
963  wxBitmap bitmap(THUMBSIZE, THUMBSIZE);
964  wxMemoryDC dc(bitmap);
965  dc.SetBackground(list->GetBackgroundColour());
966  dc.Clear();
967  dc.DrawBitmap(rawImage, x, y);
968  dc.SelectObject(wxNullBitmap);
969  // create mask bitmap
970  wxImage mask(THUMBSIZE, THUMBSIZE);
971  mask.SetRGB(wxRect(0, 0, THUMBSIZE, THUMBSIZE), 0, 0, 0);
972  mask.SetRGB(wxRect(x, y, THUMBSIZE - 2 * x, THUMBSIZE - 2 * y), 255, 255, 255);
973  // add to wxImageList
974  index = thumbs->Add(bitmap, wxBitmap(mask, 1));
975  };
976  };
977  // create item in thumb list
978  wxFileName fn(wxString((*it)->getFilename().c_str(), HUGIN_CONV_FILENAME));
979  list->InsertItem(list->GetItemCount(), fn.GetFullName(), index);
980  // build tooltip text
981  tooltips.Add(fn.GetFullName() + "\n" + FormatString::GetAperture(*it) + ", "
982  + FormatString::GetExposureTime(*it) + ", " + _("ISO") + FormatString::GetIso(*it)
983  + "\n" + FormatString::GetExifDateTime(*it));
984  };
985 };
986 
987 void PossiblePano::RemoveImage(const unsigned int index)
988 {
989  // remove image with given index
990  if (index < m_images.size())
991  {
992  ImageSet::iterator item = m_images.begin();
993  std::advance(item, index);
994  delete *item;
995  m_images.erase(item);
996  //update the internal times
997  UpdateDateTimes();
998  };
999 }
1000 
1001 PossiblePano* PossiblePano::SplitPano(const unsigned int index)
1002 {
1003  PossiblePano* newPano = new PossiblePano();
1004  if (index < m_images.size())
1005  {
1006  // now move all images to right pano
1007  ImageSet allImages = m_images;
1008  m_images.clear();
1009  ImageSet::iterator img = allImages.begin();
1010  while (m_images.size() < index && img != allImages.end())
1011  {
1012  m_images.insert(*img);
1013  ++img;
1014  };
1015  while (img != allImages.end())
1016  {
1017  newPano->AddSrcPanoImage(*img);
1018  ++img;
1019  }
1020  UpdateDateTimes();
1021  };
1022  return newPano;
1023 }
1024 
1026 {
1027  // update internal stored start and end time
1028  m_dt_start = GetDateTime(*m_images.begin());
1029  m_dt_end = m_dt_start;
1030  for (auto& img : m_images)
1031  {
1032  wxDateTime dt = GetDateTime(img);
1033  if (dt.IsEarlierThan(m_dt_start))
1034  {
1035  m_dt_start = dt;
1036  }
1037  if (dt.IsLaterThan(m_dt_end))
1038  {
1039  m_dt_end = dt;
1040  };
1041  };
1042 }
std::string m_lens
wxString GetFocalLength()
returns the focal length as string
int alphanum_comp(const std::string &l, const std::string &r)
Compare l and r with the same semantics as strcmp(), but with the &quot;Alphanum Algorithm&quot; which produces...
Definition: alphanum.cpp:119
static void swap(T &x, T &y)
Definition: svm.cpp:67
#define HUGIN_NONA_CROPPEDIMAGES
void RestoreFramePosition(wxTopLevelWindow *frame, const wxString &basename, const bool ignoreMaximize)
Definition: wxutils.cpp:67
unsigned int getPartNumber(unsigned int imageNr) const
Get a part number from an image number.
void StoreFramePosition(wxTopLevelWindow *frame, const wxString &basename, const bool ignoreMaximize)
Definition: wxutils.cpp:106
wxChoice * m_ch_naming
bool operator()(const HuginBase::SrcPanoImage *img1, const HuginBase::SrcPanoImage *img2) const
wxSpinCtrl * m_sc_maxTimeDiff
wxDateTime m_dt_start
#define HUGIN_CONV_FILENAME
Definition: platform.h:40
void AddSrcPanoImage(HuginBase::SrcPanoImage *img)
adds the given SrcPanoImage to this pano-group
#define HUGIN_JPEG_QUALITY
~PossiblePano()
destructor, cleans up used variables
void setPhotometricOptimizerSwitch(const int newSwitch)
sets the photometric optimizer master switch
Definition: Panorama.cpp:311
Somewhere to specify what variables belong to what.
void AddToList(wxString aFile, Project::Target target=Project::STITCHING, wxString userDefined=wxEmptyString)
Definition: BatchFrame.cpp:481
void RemoveImage(const unsigned int index)
removes the image at given index
some helper classes for graphes
void EnableButtons(const bool state)
wxImageList * m_thumbs
wxButton * m_button_start
include file for the hugin project
wxCheckBox * m_cb_loadDistortion
std::string outputImageTypeCompression
wxString GetCameraName()
returns the camera name
void setOptimizerSwitch(const int newSwitch)
set optimizer master switch
Definition: Panorama.cpp:303
wxCheckBox * m_cb_createLinks
WXIMPEX wxString GetFormattedTimeSpan(const wxTimeSpan &timeSpan)
Definition: wxutils.cpp:29
ImageSet m_images
double m_cropfactor
Batch processor for Hugin with GUI.
int SortWxFilenames(const wxString &s1, const wxString &s2)
void OnButtonClose(wxCommandEvent &e)
closes window
wxCheckBox * m_cb_loadVignetting
void UpdateDateTimes()
updates the internal date/time representations
void linkPossibleStacks(bool linkPosition)
create automatically stacks as indicated by metadata
Definition: Panorama.cpp:2181
Model for a panorama.
Definition: Panorama.h:152
PossiblePano * SplitPano(const unsigned int index)
split pano into 2 subpanos, index is used as first image of second pano
BatchFrame * m_batchframe
wxArrayString m_tooltips
some definitions to work with optimizer master switches
size_t GetSelectedValue(wxControlWithItems *list)
Returns the client value of the selected item from list.
Definition: LensTools.cpp:103
wxDateTime m_dt_end
const wxString GetFilestring(const wxString BasePath, const bool stripExtension=false) const
returns a string with the filename of the first and last file
wxString GetDuration()
returns the duration as string
void PopulateListCtrl(wxListCtrl *list, wxImageList *thumbs, wxArrayString &tooltips)
add all images to wxListCtrl
std::size_t getNrOfImages() const
number of images.
Definition: Panorama.h:205
void SearchInDir(wxString dirstring, const bool includeSubdir, const bool loadDistortion, const bool loadVignetting, const size_t minNumberImages, const size_t maxTimeDiff)
const int getExifDateTime(struct tm *datetime) const
try to convert Exif date time string to struct tm
void OnSplitPanos(wxCommandEvent &e)
event handler to split into 2 panos
vigra_ext::Interpolator interpolator
const unsigned int GetImageCount() const
returns number of images in this group
Definition of dialog to change user defined sequence.
wxString GetStartString()
return the start date/time as string
ImageVariableGroup & getLenses()
Get the ImageVariableGroup representing the group of lens variables.
#define HUGIN_NONA_INTERPOLATOR
#define HUGIN_TIFF_COMPRESSION
void OnListMouseMove(wxMouseEvent &e)
mouse move handler for tooltips
wxCheckBox * m_cb_subdir
std::map< std::string, std::string > FileMetaData
typedef for general map for storing metadata in files
Definition: SrcPanoImage.h:55
wxString GetLensName()
returns the lens name
std::set< HuginBase::SrcPanoImage *, SortFilename > ImageSet
std::string stripExtension(const std::string &basename2)
remove extension of a filename
Definition: utils.cpp:130
TIFFErrorHandler m_oldtiffwarning
void OnSelectPossiblePano(wxCommandEvent &e)
event to populate information on the right
wxStaticText * m_statustext
void OnListItemRightClick(wxListEvent &e)
event handler for context menu
#define HUGIN_HDRMERGE_ARGS
#define HUGIN_LDR_OUTPUT_FORMAT
bool BelongsTo(HuginBase::SrcPanoImage *img, const wxTimeSpan max_time_diff)
return true, if the image could belong to the given PossiblePano, it checks camera maker and model...
unsigned int addImage(const SrcPanoImage &img)
the the number for a specific image
Definition: Panorama.cpp:319
wxString GetExposureTime(const HuginBase::SrcPanoImage *img)
returns formatted exposure time
Definition: LensTools.cpp:550
Same as above, but use a non const panorama.
wxButton * m_button_close
NamingConvention
enumeration for different naming conventions, must be match combobox in ressource ...
const PanoramaOptions & getOptions() const
returns the options for this panorama
Definition: Panorama.h:481
wxString GeneratePanorama(NamingConvention nc, bool createLinks, HuginBase::PanoramaOptions::BlendingMechanism defaultBlender)
generates the panorama file from this set of images
wxString GetExifDateTime(const HuginBase::SrcPanoImage *img)
returns Exif DateTimeOriginal as formatted wxString
Definition: LensTools.cpp:499
#define THUMBSIZE
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
wxListCtrl * m_thumbsList
vigra::Size2D m_size
double m_focallength
wxString m_start_dir
bool GetNewProjectFilename(NamingConvention nc, const wxString basePath, wxFileName &projectFile)
returns a given filename, which does not already exists
#define HUGIN_ENFUSE_ARGS
bool readEXIF()
try to fill out information about the image, by examining the exif data
const wxDateTime GetDateTime(const HuginBase::SrcPanoImage *img)
does some reformating date/time format
PossiblePano()
constructor, init values
wxDirPickerCtrl * m_dirPicker
void OnClose(wxCloseEvent &e)
prevents closing window when running detection
platform/compiler specific stuff.
bool WritePTOFile(const std::string &filename, const std::string &prefix="")
write data to given pto file
Definition: Panorama.cpp:2059
wxSpinCtrl * m_sc_minNumberImages
~FindPanoDialog()
destructor, saves size and position
std::string m_camera
const SrcPanoImage & getImage(std::size_t nr) const
get a panorama image, counting starts with 0
Definition: Panorama.h:211
FindPanoDialog(BatchFrame *batchframe, wxString xrcPrefix)
Constructor, read from xrc ressource; restore last uses settings, size and position.
const wxString GetItemString(const wxString BasePath) const
returns a string which contains description of this pano
void OnRemoveImage(wxCommandEvent &e)
event handler to remove selected image from list
void setOptions(const PanoramaOptions &opt)
set new output settings This is not used directly for optimizing/stiching, but it can be feed into ru...
Definition: Panorama.cpp:1531
wxString GetFocalLength(const HuginBase::SrcPanoImage *img)
return focallength and focallength 35 mm as wxString
Definition: LensTools.cpp:515
Interpolator
enum with all interpolation methods
Definition: Interpolators.h:78
static uint16_t flags
All variables of a source image.
Definition: SrcPanoImage.h:194
Panorama image options.
wxString GetAperture(const HuginBase::SrcPanoImage *img)
returns formatted aperture value
Definition: LensTools.cpp:536
void switchParts(unsigned int ImageNr, unsigned int partNr)
switch a given image to a different part number.
const bool hasPossibleStacks() const
return true, if the metadata indicates that the projects is a bracketet project
Definition: Panorama.cpp:2137
#define HUGIN_ENBLEND_ARGS
wxChoice * m_ch_blender
void OnButtonSend(wxCommandEvent &e)
add selected projects to queue
int HuginMessageBox(const wxString &message, const wxString &caption, int style, wxWindow *parent)
Definition: wxutils.cpp:176
wxString getDefaultProjectName(const HuginBase::Panorama &pano, const wxString filenameTemplate)
gets the default project name, as defined in the preferences
BlendingMechanism blendMode
std::string m_make
wxCheckListBox * m_list_pano
void FillBlenderList(wxControlWithItems *list)
Fills a wxControlWithItem with all possible blender options, the client data contains the associated ...
Definition: LensTools.cpp:82
wxString GetIso(const HuginBase::SrcPanoImage *img)
returns formatted iso value
Definition: LensTools.cpp:587
wxButton * m_button_send
void OnButtonStart(wxCommandEvent &e)
start/stops detections
std::vector< PossiblePano * > m_panos