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