pto_merge.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00013 /*  This program is free software; you can redistribute it and/or
00014  *  modify it under the terms of the GNU General Public
00015  *  License as published by the Free Software Foundation; either
00016  *  version 2 of the License, or (at your option) any later version.
00017  *
00018  *  This software is distributed in the hope that it will be useful,
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  *  General Public License for more details.
00022  *
00023  *  You should have received a copy of the GNU General Public
00024  *  License along with this software. If not, see
00025  *  <http://www.gnu.org/licenses/>.
00026  *
00027  */
00028 
00029 #include <fstream>
00030 #include <sstream>
00031 #include <getopt.h>
00032 #ifndef WIN32
00033 #include <unistd.h>
00034 #endif
00035 #include <panodata/Panorama.h>
00036 
00037 using namespace std;
00038 using namespace HuginBase;
00039 using namespace AppBase;
00040 
00041 static void usage(const char* name)
00042 {
00043     cout << name << ": merges several project files" << endl
00044          << "pto_merge version " << hugin_utils::GetHuginVersion() << endl
00045          << endl
00046          << "Usage:  " << name << " [options] input.pto input2.pto ..." << endl
00047          << endl
00048          << "  Options:" << endl
00049          << "     -o, --output=file.pto  Output Hugin PTO file." << endl
00050          << "                            Default: <filename>_merge.pto" << endl
00051          << "     -h, --help             Shows this help" << endl
00052          << endl;
00053 }
00054 
00055 int main(int argc, char* argv[])
00056 {
00057     // parse arguments
00058     const char* optstring = "o:h";
00059 
00060     static struct option longOptions[] =
00061     {
00062         {"output", required_argument, NULL, 'o' },
00063         {"help", no_argument, NULL, 'h' },
00064         0
00065     };
00066 
00067     int c;
00068     int optionIndex = 0;
00069     string output;
00070     while ((c = getopt_long (argc, argv, optstring, longOptions,&optionIndex)) != -1)
00071     {
00072         switch (c)
00073         {
00074             case 'o':
00075                 output = optarg;
00076                 break;
00077             case 'h':
00078                 usage(hugin_utils::stripPath(argv[0]).c_str());
00079                 return 0;
00080             case '?':
00081                 break;
00082             default:
00083                 abort ();
00084         }
00085     }
00086 
00087     if (argc - optind < 2)
00088     {
00089         cout << "Warning: pto_merge requires at least 2 project files" << endl << endl;
00090         usage(hugin_utils::stripPath(argv[0]).c_str());
00091         return 1;
00092     };
00093 
00094     string input=argv[optind];
00095     // read panorama
00096     Panorama pano;
00097     ifstream prjfile(input.c_str());
00098     if (!prjfile.good())
00099     {
00100         cerr << "could not open script : " << input << endl;
00101         return 1;
00102     }
00103     pano.setFilePrefix(hugin_utils::getPathPrefix(input));
00104     DocumentData::ReadWriteError err = pano.readData(prjfile);
00105     if (err != DocumentData::SUCCESSFUL)
00106     {
00107         cerr << "error while parsing panos tool script: " << input << endl;
00108         cerr << "DocumentData::ReadWriteError code: " << err << endl;
00109         return 1;
00110     }
00111 
00112     optind++;
00113     while(optind<argc)
00114     {
00115         Panorama pano2;
00116         string input2=argv[optind];
00117         ifstream prjfile2(input2.c_str());
00118         if (!prjfile2.good())
00119         {
00120             cerr << "could not open script : " << input << endl;
00121             return 1;
00122         }
00123         pano2.setFilePrefix(hugin_utils::getPathPrefix(input2));
00124         DocumentData::ReadWriteError err = pano2.readData(prjfile2);
00125         if (err != DocumentData::SUCCESSFUL)
00126         {
00127             cerr << "error while parsing panos tool script: " << input << endl;
00128             cerr << "DocumentData::ReadWriteError code: " << err << endl;
00129             return 1;
00130         }
00131         pano.mergePanorama(pano2);
00132         optind++;
00133     };
00134 
00135     //write output
00136     OptimizeVector optvec = pano.getOptimizeVector();
00137     UIntSet imgs;
00138     fill_set(imgs,0, pano.getNrOfImages()-1);
00139     // Set output .pto filename if not given
00140     if (output=="")
00141     {
00142         output=input.substr(0,input.length()-4).append("_merge.pto");
00143     }
00144     ofstream of(output.c_str());
00145     pano.printPanoramaScript(of, optvec, pano.getOptions(), imgs, false, hugin_utils::getPathPrefix(input));
00146 
00147     cout << endl << "Written output to " << output << endl;
00148     return 0;
00149 }

Generated on 29 Aug 2015 for Hugintrunk by  doxygen 1.4.7