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 void iCPApp::ReadDetectorConfig()
00043 {
00044     wxConfig config(wxT("hugin"));
00045     //read cp detectors settings
00046     CPDetectorConfig cpdetector_config;
00047     cpdetector_config.Read(&config);
00048     //write current cp detectors settings
00049     cpdetector_config.Write(&config);
00050     config.Flush();
00051 
00052     if(m_setting<0 || m_setting>=cpdetector_config.settings.size())
00053     {
00054         m_cpsetting=cpdetector_config.settings[cpdetector_config.GetDefaultGenerator()];
00055     }
00056     else
00057     {
00058         m_cpsetting=cpdetector_config.settings[m_setting];
00059     };
00060 
00061     if(m_matches==-1)
00062     {
00063         m_matches=config.Read(wxT("/Assistant/nControlPoints"), HUGIN_ASS_NCONTROLPOINTS);
00064     };
00065 };
00066 
00067 void iCPApp::OnInitCmdLine(wxCmdLineParser &parser)
00068 {
00069     parser.AddSwitch(wxT("h"),wxT("help"),wxT("shows this help message"));
00070     parser.AddOption(wxT("s"),wxT("setting"),wxT("used setting"),wxCMD_LINE_VAL_NUMBER);
00071     parser.AddOption(wxT("m"),wxT("matches"),wxT("number of matches"),wxCMD_LINE_VAL_NUMBER);
00072     parser.AddOption(wxT("o"),wxT("output"),wxT("output project"),wxCMD_LINE_VAL_STRING,wxCMD_LINE_OPTION_MANDATORY);
00073     parser.AddParam(wxT("input.pto"),wxCMD_LINE_VAL_STRING,wxCMD_LINE_OPTION_MANDATORY);
00074 };
00075 
00076 bool iCPApp::OnCmdLineParsed(wxCmdLineParser &parser)
00077 {
00078     // we don't call the parents method of OnCmdLineParse, this will pull in other options we don't want
00079     if(!parser.Found(wxT("s"),&m_setting))
00080     {
00081         m_setting=-1;
00082     };
00083     if(!parser.Found(wxT("m"),&m_matches))
00084     {
00085         m_matches=-1;
00086     };
00087     parser.Found(wxT("o"),&m_output);
00088     m_input=parser.GetParam();
00089     return true;
00090 };
00091 
00092 // dummy panotools progress functions
00093 static int ptProgress( int command, char* argument )
00094 {
00095         return 1;
00096 }
00097 static int ptinfoDlg( int command, char* argument )
00098 {
00099         return 1;
00100 }
00101 
00102 int iCPApp::OnRun()
00103 {
00104     ReadDetectorConfig();
00105     //read input project
00106     HuginBase::PanoramaMemento newPano;
00107     int ptoVersion = 0;
00108     wxFileName file(m_input);
00109     file.MakeAbsolute();
00110     std::ifstream in((const char *)file.GetFullPath().mb_str(HUGIN_CONV_FILENAME));
00111     if(!in.good())
00112     {
00113         std::cerr << "could not open script : " << file.GetFullPath().char_str() << std::endl;
00114         return 1;
00115     }
00116     if(!newPano.loadPTScript(in, ptoVersion,(std::string)file.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR).mb_str(HUGIN_CONV_FILENAME)))
00117     {
00118         std::cerr << "could not parse script: " << file.GetFullPath().char_str() << std::endl;
00119         return 1;
00120     };
00121     pano.setMemento(newPano);
00122  
00123     //match images
00124     AutoCtrlPointCreator matcher;
00125     HuginBase::UIntSet imgs;
00126     fill_set(imgs,0, pano.getNrOfImages()-1);
00127     //deactivate libpano messages
00128     PT_setProgressFcn(ptProgress);
00129     PT_setInfoDlgFcn(ptinfoDlg);
00130     HuginBase::CPVector cps = matcher.automatch(m_cpsetting,pano,imgs,m_matches,NULL);
00131     PT_setProgressFcn(NULL);
00132     PT_setInfoDlgFcn(NULL);
00133     if(cps.size()==0)
00134     {
00135         return 1;
00136     };
00137     for(unsigned i=0;i<cps.size();i++)
00138     {
00139         pano.addCtrlPoint(cps[i]);
00140     };
00141 
00142     //write output
00143     HuginBase::OptimizeVector optvec = pano.getOptimizeVector();
00144     std::ofstream of((const char *)m_output.mb_str(HUGIN_CONV_FILENAME));
00145     wxFileName outputFile(m_output);
00146     outputFile.MakeAbsolute();
00147     std::string prefix(outputFile.GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME).char_str());
00148     pano.printPanoramaScript(of, optvec, pano.getOptions(), imgs, false, prefix);
00149     
00150     std::cout << std::endl << "Written output to " << m_output.char_str() << std::endl;
00151 
00152     return 0;
00153 };
00154 
00155 IMPLEMENT_APP_CONSOLE(iCPApp)

Generated on 24 Jun 2016 for Hugintrunk by  doxygen 1.4.7