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 static void usage(const char* name)
00038 {
00039     std::cout << name << ": merges several project files" << std::endl
00040          << "pto_merge version " << hugin_utils::GetHuginVersion() << std::endl
00041          << std::endl
00042          << "Usage:  " << name << " [options] input.pto input2.pto ..." << std::endl
00043          << std::endl
00044          << "  Options:" << std::endl
00045          << "     -o, --output=file.pto  Output Hugin PTO file." << std::endl
00046          << "                            Default: <filename>_merge.pto" << std::endl
00047          << "     -h, --help             Shows this help" << std::endl
00048          << std::endl;
00049 }
00050 
00051 int main(int argc, char* argv[])
00052 {
00053     // parse arguments
00054     const char* optstring = "o:h";
00055 
00056     static struct option longOptions[] =
00057     {
00058         {"output", required_argument, NULL, 'o' },
00059         {"help", no_argument, NULL, 'h' },
00060         0
00061     };
00062 
00063     int c;
00064     int optionIndex = 0;
00065     std::string output;
00066     while ((c = getopt_long (argc, argv, optstring, longOptions,&optionIndex)) != -1)
00067     {
00068         switch (c)
00069         {
00070             case 'o':
00071                 output = optarg;
00072                 break;
00073             case 'h':
00074                 usage(hugin_utils::stripPath(argv[0]).c_str());
00075                 return 0;
00076             case '?':
00077                 break;
00078             default:
00079                 abort ();
00080         }
00081     }
00082 
00083     if (argc - optind < 2)
00084     {
00085         std::cout << "Warning: pto_merge requires at least 2 project files" << std::endl << std::endl;
00086         usage(hugin_utils::stripPath(argv[0]).c_str());
00087         return 1;
00088     };
00089 
00090     std::string input=argv[optind];
00091     // read panorama
00092     HuginBase::Panorama pano;
00093     std::ifstream prjfile(input.c_str());
00094     if (!prjfile.good())
00095     {
00096         std::cerr << "could not open script : " << input << std::endl;
00097         return 1;
00098     }
00099     pano.setFilePrefix(hugin_utils::getPathPrefix(input));
00100     AppBase::DocumentData::ReadWriteError err = pano.readData(prjfile);
00101     if (err != AppBase::DocumentData::SUCCESSFUL)
00102     {
00103         std::cerr << "error while parsing panos tool script: " << input << std::endl;
00104         std::cerr << "AppBase::DocumentData::ReadWriteError code: " << err << std::endl;
00105         return 1;
00106     }
00107 
00108     optind++;
00109     while(optind<argc)
00110     {
00111         HuginBase::Panorama pano2;
00112         std::string input2=argv[optind];
00113         std::ifstream prjfile2(input2.c_str());
00114         if (!prjfile2.good())
00115         {
00116             std::cerr << "could not open script : " << input << std::endl;
00117             return 1;
00118         }
00119         pano2.setFilePrefix(hugin_utils::getPathPrefix(input2));
00120         AppBase::DocumentData::ReadWriteError err = pano2.readData(prjfile2);
00121         if (err != AppBase::DocumentData::SUCCESSFUL)
00122         {
00123             std::cerr << "error while parsing panos tool script: " << input << std::endl;
00124             std::cerr << "AppBase::DocumentData::ReadWriteError code: " << err << std::endl;
00125             return 1;
00126         }
00127         pano.mergePanorama(pano2);
00128         optind++;
00129     };
00130 
00131     //write output
00132     HuginBase::OptimizeVector optvec = pano.getOptimizeVector();
00133     HuginBase::UIntSet imgs;
00134     fill_set(imgs,0, pano.getNrOfImages()-1);
00135     // Set output .pto filename if not given
00136     if (output=="")
00137     {
00138         output=input.substr(0,input.length()-4).append("_merge.pto");
00139     }
00140     std::ofstream of(output.c_str());
00141     pano.printPanoramaScript(of, optvec, pano.getOptions(), imgs, false, hugin_utils::getPathPrefix(input));
00142 
00143     std::cout << std::endl << "Written output to " << output << std::endl;
00144     return 0;
00145 }

Generated on 23 Jul 2016 for Hugintrunk by  doxygen 1.4.7