1 //*******************************************************************
2 //
3 // Author:  Frederic Claudel
4 // to use after correl, with a tie points file
5 //
6 //*******************************************************************
7 
8 #include <cstdlib>
9 #include <iostream>
10 using namespace std;
11 
12 #include <ossim/init/ossimInit.h>
13 #include <ossim/base/ossimArgumentParser.h>
14 #include <ossim/base/ossimApplicationUsage.h>
15 #include <ossim/base/ossimKeywordlist.h>
16 #include <ossim/base/ossimString.h>
17 #include <ossim/base/ossimStdOutProgress.h>
18 #include <ossim/base/ossimObjectFactoryRegistry.h>
19 #include <ossim/base/ossimRefPtr.h>
20 #include <ossim/base/ossimPropertyInterface.h>
21 #include <ossim/base/ossimProcessInterface.h>
22 
23 //error header
24 static const char* PROGERR = "ERROR modopt";
25 
26 int
main(int argc,char * argv[])27 main(int argc, char *argv[])
28 {
29    //error status : initially ok
30    int result=0;
31 
32    //init OSSIM (prefs, elevation, plugins, etc)
33    std::string  tempString;
34    ossimArgumentParser::ossimParameter argString(tempString);
35    ossimArgumentParser argumentParser(&argc, argv);
36    ossimInit::instance()->addOptions(argumentParser);
37    ossimInit::instance()->initialize(argumentParser);
38 
39    //init with default parms
40    ossimRefPtr<ossimObject> moObject = ossimObjectFactoryRegistry::instance()->createObject(ossimString("ossimModelOptimizer"));
41    ossimPropertyInterface* moPropertyInterface = PTR_CAST(ossimPropertyInterface, moObject.get());
42    ossimProcessInterface* moProcessInterface = PTR_CAST(ossimProcessInterface, moObject.get());
43    if(!moObject.valid())
44    {
45       ossimNotify(ossimNotifyLevel_WARN) << "Unable to find object ossimModelOptimizer in registration plugin" << std::endl;
46       exit(1);
47    }
48 
49    ossimRefPtr<ossimProperty> modelDefinition = moPropertyInterface->getProperty("model_definition");
50    ossimRefPtr<ossimProperty> outGeomFilename = moPropertyInterface->getProperty("geom_output_filename");
51 
52    //read args : options
53    argumentParser.getApplicationUsage()->setApplicationName(argumentParser.getApplicationName());
54    argumentParser.getApplicationUsage()->setDescription(argumentParser.getApplicationName()+" optimizes a projection model using tie points");
55    argumentParser.getApplicationUsage()->setCommandLineUsage(argumentParser.getApplicationName()+" [options] <GML_tiepoints_file>");
56    argumentParser.getApplicationUsage()->addCommandLineOption("-h",
57       ossimString("display Usage/Help"));
58    argumentParser.getApplicationUsage()->addCommandLineOption("-d",
59       ossimString("<model_definition> : default=") + (modelDefinition.valid()?modelDefinition->valueToString():ossimString("")) );
60    argumentParser.getApplicationUsage()->addCommandLineOption("-g",
61       ossimString("<geom_file> : output geometry file, default=") + (outGeomFilename.valid()?outGeomFilename->valueToString():ossimString("")) );
62 
63    if (argumentParser.read("-h"))
64    {
65       //help/usage
66       argumentParser.getApplicationUsage()->write(std::cout);
67       result = 0;
68    } else {
69       if (argumentParser.read("-d", argString))
70       {
71          moPropertyInterface->setProperty("model_definition", tempString);
72       }
73       if (argumentParser.read("-g", argString))
74       {
75          moPropertyInterface->setProperty("geom_output_filename", tempString);
76       }
77 
78       //read mandatory args : master and slave images
79       //should only remain 2 args
80       int nbargs = argumentParser.argc() - 1;
81       if (nbargs == 1)
82       {
83          ossimString tiePtPath(argumentParser.argv()[1]);
84 
85          moPropertyInterface->setProperty("gml_tieset_filename", tiePtPath);
86          moProcessInterface->execute();
87          //if (result==0) result = mo.loadGMLTieSet(tiePtPath) ? 0 : 5 ;
88          //if (result==0) result = mo.execute()                ? 0 : 4 ;
89 
90       } else {
91          cerr<<PROGERR<<" bad number of non-optional args "<< nbargs << ",needs 1"<< endl;
92          result = 3;
93       }
94    }
95 
96    return result;
97 }
98