Diff of /src/tools/checkpto.cpp [277c91] .. [2f6425] Maximize Restore

  Switch to side-by-side view

--- a/src/tools/checkpto.cpp
+++ b/src/tools/checkpto.cpp
@@ -42,49 +42,103 @@
 using namespace HuginBase;
 using namespace AppBase;
 
-static void usage(const char * name)
-{
-    cout << name << ": helper program for hugins makefile assistant" << endl
-         << "checkpto version " << DISPLAY_VERSION << endl
-         << endl
-         << "Not intended for stand-alone use" << endl;
-}
-
-int main(int argc, char *argv[])
-{
-    if(argc!=2)
-    {
-        usage(argv[0]);
-        return 1;
-    };
-
-    string input=argv[1];
+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;
+        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;
+        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" << std::endl << "Stopping processing." << std::endl;
-        return 1;
+        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;
     };
 }