ossimSentinel1ModelTest.cpp 2.54 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//----------------------------------------------------------------------------
//
// "Copyright Centre National d'Etudes Spatiales"
//
// License:  LGPL-2
//
// See LICENSE.txt file in the top level directory for more details.
//
//----------------------------------------------------------------------------
// $Id$

#include "ossimSentinel1Model.h"
#include "ossimPluginProjectionFactory.h"
#include <iostream>
#include <memory>
#include <map>
#include <string>

using namespace ossimplugins;
20
enum Inverse { fwd, inv, undef};
21
22
23

int main(int argc, char * argv[])
{
24
   std::clog.precision(20);
25
26
27

   string annotationXml;
   Inverse inverse = undef;
28
   bool verbose = false;
29
30
31
32
33
34

   for (int i=1; i!=argc ; ++i) {
      std::string const a(argv[i]);
      if (a == "-v" || a == "-verbose") {
         verbose = true;
      } else if (inverse == undef)  {
35
      inverse = atoi(argv[i]) == 1 ? inv : fwd;
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
      } else if (annotationXml.empty())  {
         annotationXml = a;
      } else {
         std::cerr << "Too many arguments\n"
            << argv[0] << "[-v|--verbose] <inverse> <annotationXml>\n";
         return EXIT_FAILURE;
      }
   }

   if(annotationXml.empty())
   {
      std::cerr << "Not enough arguments\n"
         << argv[0] << "[-v|--verbose] <inverse> <annotationXml>\n";
      return EXIT_FAILURE;
   }
51
52
53
   if (!verbose) {
      std::clog.setstate(std::ios_base::badbit);
   }
54

55
   try {
56
      std::auto_ptr<ossimProjection> projection
57
         (ossimPluginProjectionFactory::instance()->createProjection(annotationXml, 42));
58
59
60
61
62
63
64
65
66
      if (!projection.get()) {
         throw std::runtime_error("Cannot read annotation file ("+annotationXml+"). Cannot create a projection from it.");
      }

      ossimSentinel1Model * sensor = dynamic_cast<ossimSentinel1Model*>(projection.get());
      if (!sensor) {
         throw std::runtime_error(
               "Unlike Expectations, the annotation file ("+annotationXml+") is not a Sentinel Annotation File");
      }
67

68
69
      if (verbose)
      {
70
         sensor->print(std::clog);
71
      }
72

73
74
75
76
      ossimKeywordlist kwl;
      sensor->saveState(kwl, "S1.");
      sensor->loadState(kwl, "S1.");
      if (verbose) {
77
         sensor->print(std::clog);
78
79
80
81
82
83
84
85
86
      }

      const bool validate = inverse == inv
         ? sensor->autovalidateInverseModelFromGCPs()
         : sensor->autovalidateForwardModelFromGCPs()
         ;

      std::cout << "Validate: " << validate << "\n";
      return validate ? EXIT_SUCCESS : EXIT_FAILURE;
87
88
89
   } catch (std::exception const& e) {
      std::cerr << "Error: " << e.what() << "\n";
   }
90
91
   return EXIT_FAILURE;
}