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

Generated on 5 Dec 2016 for Hugintrunk by  doxygen 1.4.7