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, write to the Free Software
00023  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  *
00025  */
00026 
00027 #include <hugin_version.h>
00028 #include "icpfind.h"
00029 
00030 #include <fstream>
00031 #include <sstream>
00032 
00033 #include "AutoCtrlPointCreator.h"
00034 #include <panodata/Panorama.h>
00035 #include <base_wx/platform.h>
00036 #include "hugin/config_defaults.h"
00037 #include <vigra/impex.hxx>
00038 
00039 using namespace std;
00040  
00041 void iCPApp::ReadDetectorConfig()
00042 {
00043     wxConfig config(wxT("hugin"));
00044     //read cp detectors settings
00045     CPDetectorConfig cpdetector_config;
00046     cpdetector_config.Read(&config);
00047     //write current cp detectors settings
00048     cpdetector_config.Write(&config);
00049     config.Flush();
00050 
00051     if(m_setting<0 || m_setting>=cpdetector_config.settings.size())
00052     {
00053         m_cpsetting=cpdetector_config.settings[cpdetector_config.GetDefaultGenerator()];
00054     }
00055     else
00056     {
00057         m_cpsetting=cpdetector_config.settings[m_setting];
00058     };
00059 
00060     if(m_matches==-1)
00061     {
00062         m_matches=config.Read(wxT("/Assistant/nControlPoints"), HUGIN_ASS_NCONTROLPOINTS);
00063     };
00064 };
00065 
00066 void iCPApp::OnInitCmdLine(wxCmdLineParser &parser)
00067 {
00068     parser.AddSwitch(wxT("h"),wxT("help"),wxT("shows this help message"));
00069     parser.AddOption(wxT("s"),wxT("setting"),wxT("used setting"),wxCMD_LINE_VAL_NUMBER);
00070     parser.AddOption(wxT("m"),wxT("matches"),wxT("number of matches"),wxCMD_LINE_VAL_NUMBER);
00071     parser.AddOption(wxT("o"),wxT("output"),wxT("output project"),wxCMD_LINE_VAL_STRING,wxCMD_LINE_OPTION_MANDATORY);
00072     parser.AddParam(wxT("input.pto"),wxCMD_LINE_VAL_STRING,wxCMD_LINE_OPTION_MANDATORY);
00073 };
00074 
00075 bool iCPApp::OnCmdLineParsed(wxCmdLineParser &parser)
00076 {
00077     if(wxAppConsole::OnCmdLineParsed(parser))
00078     {
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     else
00092     {
00093         return false;
00094     };
00095 };
00096 
00097 // dummy panotools progress functions
00098 static int ptProgress( int command, char* argument )
00099 {
00100         return 1;
00101 }
00102 static int ptinfoDlg( int command, char* argument )
00103 {
00104         return 1;
00105 }
00106 
00107 int iCPApp::OnRun()
00108 {
00109     ReadDetectorConfig();
00110     //read input project
00111     PT::PanoramaMemento newPano;
00112     int ptoVersion = 0;
00113     wxFileName file(m_input);
00114     file.MakeAbsolute();
00115     std::ifstream in((const char *)file.GetFullPath().mb_str(HUGIN_CONV_FILENAME));
00116     if(!in.good())
00117     {
00118         cerr << "could not open script : " << file.GetFullPath().char_str() << endl;
00119         return 1;
00120     }
00121     if(!newPano.loadPTScript(in, ptoVersion,(std::string)file.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR).mb_str(HUGIN_CONV_FILENAME)))
00122     {
00123         cerr << "could not parse script: " << file.GetFullPath().char_str() << endl;
00124         return 1;
00125     };
00126     pano.setMemento(newPano);
00127  
00128     //match images
00129     AutoCtrlPointCreator matcher;
00130     HuginBase::UIntSet imgs;
00131     fill_set(imgs,0, pano.getNrOfImages()-1);
00132     //deactivate libpano messages
00133     PT_setProgressFcn(ptProgress);
00134     PT_setInfoDlgFcn(ptinfoDlg);
00135     HuginBase::CPVector cps = matcher.automatch(m_cpsetting,pano,imgs,m_matches,NULL);
00136     PT_setProgressFcn(NULL);
00137     PT_setInfoDlgFcn(NULL);
00138     if(cps.size()==0)
00139     {
00140         return 1;
00141     };
00142     for(unsigned i=0;i<cps.size();i++)
00143     {
00144         pano.addCtrlPoint(cps[i]);
00145     };
00146 
00147     //write output
00148     HuginBase::OptimizeVector optvec = pano.getOptimizeVector();
00149     ofstream of((const char *)m_output.mb_str(HUGIN_CONV_FILENAME));
00150     wxFileName outputFile(m_output);
00151     outputFile.MakeAbsolute();
00152     string prefix(outputFile.GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME).char_str());
00153     pano.printPanoramaScript(of, optvec, pano.getOptions(), imgs, false, prefix);
00154     
00155     cout << endl << "Written output to " << m_output.char_str() << endl;
00156 
00157     return 0;
00158 };
00159 
00160 IMPLEMENT_APP_CONSOLE(iCPApp)

Generated on 1 Nov 2014 for Hugintrunk by  doxygen 1.4.7