icpfind.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00011 /*  This program is free software; you can redistribute it and/or
00012  *  modify it under the terms of the GNU General Public
00013  *  License as published by the Free Software Foundation; either
00014  *  version 2 of the License, or (at your option) any later version.
00015  *
00016  *  This software is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  *  General Public License for more details.
00020  *
00021  *  You should have received a copy of the GNU General Public
00022  *  License along with this software. If not, see
00023  *  <http://www.gnu.org/licenses/>.
00024  *
00025  */
00026 
00027 #include "icpfind.h"
00028 
00029 #include <fstream>
00030 #include <sstream>
00031 
00032 #include "AutoCtrlPointCreator.h"
00033 #include <panodata/Panorama.h>
00034 #include <base_wx/platform.h>
00035 #include "hugin/config_defaults.h"
00036 
00037 extern "C"
00038 {
00039     #include <pano13/filter.h>  // for PT_setProgressFcn, PT_setInfoDlgFcn
00040 }
00041 
00042 using namespace std;
00043  
00044 void iCPApp::ReadDetectorConfig()
00045 {
00046     wxConfig config(wxT("hugin"));
00047     //read cp detectors settings
00048     CPDetectorConfig cpdetector_config;
00049     cpdetector_config.Read(&config);
00050     //write current cp detectors settings
00051     cpdetector_config.Write(&config);
00052     config.Flush();
00053 
00054     if(m_setting<0 || m_setting>=cpdetector_config.settings.size())
00055     {
00056         m_cpsetting=cpdetector_config.settings[cpdetector_config.GetDefaultGenerator()];
00057     }
00058     else
00059     {
00060         m_cpsetting=cpdetector_config.settings[m_setting];
00061     };
00062 
00063     if(m_matches==-1)
00064     {
00065         m_matches=config.Read(wxT("/Assistant/nControlPoints"), HUGIN_ASS_NCONTROLPOINTS);
00066     };
00067 };
00068 
00069 void iCPApp::OnInitCmdLine(wxCmdLineParser &parser)
00070 {
00071     parser.AddSwitch(wxT("h"),wxT("help"),wxT("shows this help message"));
00072     parser.AddOption(wxT("s"),wxT("setting"),wxT("used setting"),wxCMD_LINE_VAL_NUMBER);
00073     parser.AddOption(wxT("m"),wxT("matches"),wxT("number of matches"),wxCMD_LINE_VAL_NUMBER);
00074     parser.AddOption(wxT("o"),wxT("output"),wxT("output project"),wxCMD_LINE_VAL_STRING,wxCMD_LINE_OPTION_MANDATORY);
00075     parser.AddParam(wxT("input.pto"),wxCMD_LINE_VAL_STRING,wxCMD_LINE_OPTION_MANDATORY);
00076 };
00077 
00078 bool iCPApp::OnCmdLineParsed(wxCmdLineParser &parser)
00079 {
00080     // we don't call the parents method of OnCmdLineParse, this will pull in other options we don't want
00081     if(!parser.Found(wxT("s"),&m_setting))
00082     {
00083         m_setting=-1;
00084     };
00085     if(!parser.Found(wxT("m"),&m_matches))
00086     {
00087         m_matches=-1;
00088     };
00089     parser.Found(wxT("o"),&m_output);
00090     m_input=parser.GetParam();
00091     return true;
00092 };
00093 
00094 // dummy panotools progress functions
00095 static int ptProgress( int command, char* argument )
00096 {
00097         return 1;
00098 }
00099 static int ptinfoDlg( int command, char* argument )
00100 {
00101         return 1;
00102 }
00103 
00104 int iCPApp::OnRun()
00105 {
00106     ReadDetectorConfig();
00107     //read input project
00108     HuginBase::PanoramaMemento newPano;
00109     int ptoVersion = 0;
00110     wxFileName file(m_input);
00111     file.MakeAbsolute();
00112     std::ifstream in((const char *)file.GetFullPath().mb_str(HUGIN_CONV_FILENAME));
00113     if(!in.good())
00114     {
00115         cerr << "could not open script : " << file.GetFullPath().char_str() << endl;
00116         return 1;
00117     }
00118     if(!newPano.loadPTScript(in, ptoVersion,(std::string)file.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR).mb_str(HUGIN_CONV_FILENAME)))
00119     {
00120         cerr << "could not parse script: " << file.GetFullPath().char_str() << endl;
00121         return 1;
00122     };
00123     pano.setMemento(newPano);
00124  
00125     //match images
00126     AutoCtrlPointCreator matcher;
00127     HuginBase::UIntSet imgs;
00128     fill_set(imgs,0, pano.getNrOfImages()-1);
00129     //deactivate libpano messages
00130     PT_setProgressFcn(ptProgress);
00131     PT_setInfoDlgFcn(ptinfoDlg);
00132     HuginBase::CPVector cps = matcher.automatch(m_cpsetting,pano,imgs,m_matches,NULL);
00133     PT_setProgressFcn(NULL);
00134     PT_setInfoDlgFcn(NULL);
00135     if(cps.size()==0)
00136     {
00137         return 1;
00138     };
00139     for(unsigned i=0;i<cps.size();i++)
00140     {
00141         pano.addCtrlPoint(cps[i]);
00142     };
00143 
00144     //write output
00145     HuginBase::OptimizeVector optvec = pano.getOptimizeVector();
00146     ofstream of((const char *)m_output.mb_str(HUGIN_CONV_FILENAME));
00147     wxFileName outputFile(m_output);
00148     outputFile.MakeAbsolute();
00149     string prefix(outputFile.GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME).char_str());
00150     pano.printPanoramaScript(of, optvec, pano.getOptions(), imgs, false, prefix);
00151     
00152     cout << endl << "Written output to " << m_output.char_str() << endl;
00153 
00154     return 0;
00155 };
00156 
00157 IMPLEMENT_APP_CONSOLE(iCPApp)

Generated on 29 Jul 2015 for Hugintrunk by  doxygen 1.4.7