[2f6425]: src / tools / checkpto.cpp Maximize Restore History

Download this file

checkpto.cpp    145 lines (130 with data), 4.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// -*- c-basic-offset: 4 -*-
/** @file checkpto.cpp
*
* @brief helper program for assistant makefile
*
*
* @author Thomas Modes
*
*/
/* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <hugin_version.h>
#include <fstream>
#include <sstream>
#ifdef WIN32
#include <getopt.h>
#else
#include <unistd.h>
#endif
#include <panodata/Panorama.h>
#include "algorithms/optimizer/ImageGraph.h"
using namespace std;
using namespace HuginBase;
using namespace AppBase;
static void usage(const char * name)
{
cout << name << ": report the number of image chains in a project" << endl
<< name << " version " << DISPLAY_VERSION << endl
<< endl
<< "Usage: " << name << " input.pto" << endl
<< endl
<< name << " examins the connections between images in a project and" << endl
<< "reports back the number of parts or image chains in that project" << endl
<< endl
<< "used by the assistant makefile" << endl
<< endl;
}
int main(int argc, char *argv[])
{
// parse arguments
const char * optstring = "h";
int c;
string output;
while ((c = getopt (argc, argv, optstring)) != -1)
{
switch (c) {
case 'h':
usage(argv[0]);
return 0;
case '?':
break;
default:
abort ();
}
}
if (argc - optind != 1)
{
usage(argv[0]);
return -1;
};
string input=argv[optind];
Panorama pano;
ifstream prjfile(input.c_str());
if (!prjfile.good()) {
cerr << "could not open script : " << input << endl;
return -1;
}
pano.setFilePrefix(hugin_utils::getPathPrefix(input));
DocumentData::ReadWriteError err = pano.readData(prjfile);
if (err != DocumentData::SUCCESSFUL) {
cerr << "error while parsing panos tool script: " << input << endl;
cerr << "DocumentData::ReadWriteError code: " << err << endl;
return -1;
}
std::cout << endl
<< "Opened project " << input << endl << endl
<< "Project contains" << endl
<< pano.getNrOfImages() << " images" << endl
<< pano.getNrOfCtrlPoints() << " control points" << endl << endl;
CPGraph graph;
createCPGraph(pano, graph);
CPComponents comps;
int n = findCPComponents(graph, comps);
if(n==1)
{
std::cout << "All images are connected." << endl;
// return value must be 0, otherwise the assistant does not continue
return 0;
}
else
{
std::cout << "Found unconnected images" << endl
<< "There are " << n << " image chains." << endl;
std::cout << "Image groups: " << endl;
for (unsigned i=0; i < comps.size(); i++)
{
std::cout << "[";
CPComponents::value_type::const_iterator it;
size_t c=0;
for (it = comps[i].begin(); it != comps[i].end(); ++it)
{
std::cout << (*it);
if (c+1 != comps[i].size())
{
std::cout << ", ";
}
c++;
}
std::cout << "]";
if (i+1 != comps.size())
{
std::cout << ", ";
}
}
return n;
};
}