Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pto_merge.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
13 /* This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public
15  * License as published by the Free Software Foundation; either
16  * version 2 of the License, or (at your option) any later version.
17  *
18  * This software is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  * General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public
24  * License along with this software. If not, see
25  * <http://www.gnu.org/licenses/>.
26  *
27  */
28 
29 #include <fstream>
30 #include <sstream>
31 #include <getopt.h>
32 #include <panodata/Panorama.h>
33 
34 static void usage(const char* name)
35 {
36  std::cout << name << ": merges several project files" << std::endl
37  << "pto_merge version " << hugin_utils::GetHuginVersion() << std::endl
38  << std::endl
39  << "Usage: " << name << " [options] input.pto input2.pto ..." << std::endl
40  << std::endl
41  << " Options:" << std::endl
42  << " -o, --output=file.pto Output Hugin PTO file." << std::endl
43  << " Default: <filename>_merge.pto" << std::endl
44  << " -h, --help Shows this help" << std::endl
45  << std::endl;
46 }
47 
48 int main(int argc, char* argv[])
49 {
50  // parse arguments
51  const char* optstring = "o:h";
52 
53  static struct option longOptions[] =
54  {
55  {"output", required_argument, NULL, 'o' },
56  {"help", no_argument, NULL, 'h' },
57  0
58  };
59 
60  int c;
61  std::string output;
62  while ((c = getopt_long (argc, argv, optstring, longOptions,nullptr)) != -1)
63  {
64  switch (c)
65  {
66  case 'o':
67  output = optarg;
68  break;
69  case 'h':
70  usage(hugin_utils::stripPath(argv[0]).c_str());
71  return 0;
72  case ':':
73  case '?':
74  // missing argument or invalid switch
75  return 1;
76  break;
77  default:
78  // this should not happen
79  abort();
80  }
81  }
82 
83  if (argc - optind < 2)
84  {
85  std::cerr << hugin_utils::stripPath(argv[0]) << ": at least 2 project files needed" << std::endl << std::endl;
86  return 1;
87  };
88 
89  std::string input=argv[optind];
90  // read panorama
92  if (!pano.ReadPTOFile(input, hugin_utils::getPathPrefix(input)))
93  {
94  return 1;
95  };
96 
97  optind++;
98  while(optind<argc)
99  {
100  HuginBase::Panorama pano2;
101  const std::string input2=argv[optind];
102  if (!pano2.ReadPTOFile(input2, hugin_utils::getPathPrefix(input2)))
103  {
104  return 1;
105  };
106  // read EXIF data, needed for lens detection in merged pano
107  for (size_t i = 0; i < pano.getNrOfImages(); ++i)
108  {
109  HuginBase::SrcPanoImage srcImg(pano.getImage(i));
110  srcImg.readEXIF();
111  pano.setSrcImage(i, srcImg);
112  };
113  pano.mergePanorama(pano2);
114  optind++;
115  };
116 
117  //write output
118  // Set output .pto filename if not given
119  output = hugin_utils::GetOutputFilename(output, input, "merge");
120  if (pano.WritePTOFile(output, hugin_utils::getPathPrefix(output)))
121  {
122  std::cout << std::endl << "Written project file " << output << std::endl;
123  };
124 
125  return 0;
126 }
std::string GetOutputFilename(const std::string &out, const std::string &in, const std::string &suffix)
construct output filename, if ouput is known return this value otherwise use the input filename and a...
Definition: utils.cpp:420
Model for a panorama.
Definition: Panorama.h:152
std::string getPathPrefix(const std::string &filename)
Get the path to a filename.
Definition: utils.cpp:184
std::size_t getNrOfImages() const
number of images.
Definition: Panorama.h:205
bool ReadPTOFile(const std::string &filename, const std::string &prefix="")
read pto file from the given filename into Panorama object it does some checks on the file and issues...
Definition: Panorama.cpp:2023
static void usage()
Definition: Main.cpp:32
bool readEXIF()
try to fill out information about the image, by examining the exif data
std::string GetHuginVersion()
return a string with version numbers
Definition: utils.cpp:907
bool WritePTOFile(const std::string &filename, const std::string &prefix="")
write data to given pto file
Definition: Panorama.cpp:2059
const SrcPanoImage & getImage(std::size_t nr) const
get a panorama image, counting starts with 0
Definition: Panorama.h:211
void setSrcImage(unsigned int nr, const SrcPanoImage &img)
set input image parameters
All variables of a source image.
Definition: SrcPanoImage.h:194
void mergePanorama(const Panorama &newPano)
merges the panorama with the given pano
std::string stripPath(const std::string &filename)
remove the path of a filename (mainly useful for gui display of filenames)
Definition: utils.cpp:160
int main(int argc, char *argv[])
Definition: Main.cpp:167