Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
icpfind.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
11 /* This program 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  * 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 "icpfind.h"
28 
29 #include <fstream>
30 #include <sstream>
31 
32 #include "AutoCtrlPointCreator.h"
33 #include <panodata/Panorama.h>
34 #include <base_wx/platform.h>
35 #include "hugin/config_defaults.h"
36 #if defined __WXGTK__ && wxCHECK_VERSION(3,1,1)
37 #include "base_wx/wxPlatform.h"
38 #endif
39 
40 extern "C"
41 {
42  #include <pano13/filter.h> // for PT_setProgressFcn, PT_setInfoDlgFcn
43 }
44 
46 {
47 #if defined __WXGTK__ && wxCHECK_VERSION(3,1,1)
48  CheckConfigFilename();
49 #endif
50  wxConfig config(wxT("hugin"));
51  //read cp detectors settings
52  CPDetectorConfig cpdetector_config;
53  cpdetector_config.Read(&config);
54  //write current cp detectors settings
55  cpdetector_config.Write(&config);
56  config.Flush();
57 
58  if(m_setting<0 || m_setting>=cpdetector_config.settings.size())
59  {
60  m_cpsetting=cpdetector_config.settings[cpdetector_config.GetDefaultGenerator()];
61  }
62  else
63  {
64  m_cpsetting=cpdetector_config.settings[m_setting];
65  };
66 
67  if(m_matches==-1)
68  {
69  m_matches=config.Read(wxT("/Assistant/nControlPoints"), HUGIN_ASS_NCONTROLPOINTS);
70  };
71 };
72 
73 void iCPApp::OnInitCmdLine(wxCmdLineParser &parser)
74 {
75  parser.AddSwitch(wxT("h"),wxT("help"),wxT("shows this help message"));
76  parser.AddOption(wxT("s"),wxT("setting"),wxT("used setting"),wxCMD_LINE_VAL_NUMBER);
77  parser.AddOption(wxT("m"),wxT("matches"),wxT("number of matches"),wxCMD_LINE_VAL_NUMBER);
78  parser.AddOption(wxT("o"),wxT("output"),wxT("output project"),wxCMD_LINE_VAL_STRING,wxCMD_LINE_OPTION_MANDATORY);
79  parser.AddParam(wxT("input.pto"),wxCMD_LINE_VAL_STRING,wxCMD_LINE_OPTION_MANDATORY);
80 };
81 
82 bool iCPApp::OnCmdLineParsed(wxCmdLineParser &parser)
83 {
84  // we don't call the parents method of OnCmdLineParse, this will pull in other options we don't want
85  if(!parser.Found(wxT("s"),&m_setting))
86  {
87  m_setting=-1;
88  };
89  if(!parser.Found(wxT("m"),&m_matches))
90  {
91  m_matches=-1;
92  };
93  parser.Found(wxT("o"),&m_output);
94  m_input=parser.GetParam();
95  return true;
96 };
97 
98 // dummy panotools progress functions
99 static int ptProgress( int command, char* argument )
100 {
101  return 1;
102 }
103 static int ptinfoDlg( int command, char* argument )
104 {
105  return 1;
106 }
107 
109 {
111  //read input project
113  int ptoVersion = 0;
114  wxFileName file(m_input);
115  file.MakeAbsolute();
116  std::ifstream in((const char *)file.GetFullPath().mb_str(HUGIN_CONV_FILENAME));
117  if(!in.good())
118  {
119  std::cerr << "could not open script : " << file.GetFullPath().char_str() << std::endl;
120  return 1;
121  }
122  if(!newPano.loadPTScript(in, ptoVersion,(std::string)file.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR).mb_str(HUGIN_CONV_FILENAME)))
123  {
124  std::cerr << "could not parse script: " << file.GetFullPath().char_str() << std::endl;
125  return 1;
126  };
127  pano.setMemento(newPano);
128 
129  //match images
130  AutoCtrlPointCreator matcher;
131  HuginBase::UIntSet imgs;
132  fill_set(imgs,0, pano.getNrOfImages()-1);
133  //deactivate libpano messages
134  PT_setProgressFcn(ptProgress);
135  PT_setInfoDlgFcn(ptinfoDlg);
136  HuginBase::CPVector cps = matcher.automatch(m_cpsetting,pano,imgs,m_matches,NULL);
137  PT_setProgressFcn(NULL);
138  PT_setInfoDlgFcn(NULL);
139  if(cps.empty())
140  {
141  return 1;
142  };
143  for(unsigned i=0;i<cps.size();i++)
144  {
145  pano.addCtrlPoint(cps[i]);
146  };
147 
148  //write output
149  wxFileName outputFile(m_output);
150  outputFile.MakeAbsolute();
151  const std::string output(outputFile.GetFullPath().mb_str(HUGIN_CONV_FILENAME));
152  if (pano.WritePTOFile(output, hugin_utils::getPathPrefix(output)))
153  {
154  std::cout << std::endl << "Written output to " << output << std::endl;
155  };
156 
157  return 0;
158 };
159 
160 IMPLEMENT_APP_CONSOLE(iCPApp)
implementation of huginApp Class
void ReadDetectorConfig()
read the CPDetectorConfig from file/registry
Definition: icpfind.cpp:45
void setMemento(const PanoramaMemento &memento)
set the internal state
Definition: Panorama.cpp:1507
void Read(wxConfigBase *config=wxConfigBase::Get(), wxString loadFromFile=wxEmptyString)
read the settings of different cp generators from config
virtual HuginBase::CPVector automatch(CPDetectorSetting &setting, HuginBase::Panorama &pano, const HuginBase::UIntSet &imgs, int nFeatures, int &ret_value, wxWindow *parent=NULL)
Do cp matching, calles the right routines, based on the matcher selected.
#define HUGIN_CONV_FILENAME
Definition: platform.h:40
static int ptinfoDlg(int command, char *argument)
Definition: icpfind.cpp:103
static int ptProgress(int command, char *argument)
Definition: icpfind.cpp:99
long m_matches
Definition: icpfind.h:33
CPDetectorSetting m_cpsetting
Definition: icpfind.h:36
Base class for control point creators.
std::set< unsigned int > UIntSet
Definition: PanoramaData.h:51
ArraySettings settings
array which stores the different autopano settings
unsigned int addCtrlPoint(const ControlPoint &point)
add a new control point.
Definition: Panorama.cpp:381
std::string getPathPrefix(const std::string &filename)
Get the path to a filename.
Definition: utils.cpp:184
bool loadPTScript(std::istream &i, int &ptoVersion, const std::string &prefix="")
load a Hugin file
std::size_t getNrOfImages() const
number of images.
Definition: Panorama.h:205
virtual int OnRun()
the main procedure of iCPApp
Definition: icpfind.cpp:108
wxString m_input
Definition: icpfind.h:34
wxString m_output
Definition: icpfind.h:35
virtual void OnInitCmdLine(wxCmdLineParser &parser)
set the parameters for the command line parser
Definition: icpfind.cpp:73
Definition: icpfind.h:19
HuginBase::Panorama pano
Definition: icpfind.h:37
Memento class for a Panorama object.
Definition: Panorama.h:49
long m_setting
Definition: icpfind.h:32
unsigned int GetDefaultGenerator()
return index of default generator (this one is used for assistent)
std::vector< ControlPoint > CPVector
Definition: ControlPoint.h:99
platform/compiler specific stuff.
bool WritePTOFile(const std::string &filename, const std::string &prefix="")
write data to given pto file
Definition: Panorama.cpp:2059
void fill_set(_Container &c, typename _Container::key_type begin, typename _Container::key_type end)
Definition: stl_utils.h:81
void Write(wxConfigBase *config=wxConfigBase::Get())
writes the settings of different cp generators to config
#define HUGIN_ASS_NCONTROLPOINTS
class for storing settings of different control point generators
virtual bool OnCmdLineParsed(wxCmdLineParser &parser)
processes the command line parameters
Definition: icpfind.cpp:82