OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
atp-residuals.cpp
Go to the documentation of this file.
1 //---
2 //
3 // License: MIT
4 //
5 // File: ossim-foo.cpp
6 //
7 // Description: Contains application definition "ossim-foo" app.
8 //
9 // NOTE: This is supplied for simple quick test. DO NOT checkin your test to
10 // the svn repository. Simply edit ossim-foo.cpp and run your test.
11 // After completion you can do a "git checkout -- ossimfoo.cpp" if
12 // you want to keep your working repository up to snuff.
13 //
14 // $Id$
15 //---
16 
17 // System includes:
18 #include <cmath>
19 #include <memory>
20 #include <sstream>
21 #include <iostream>
22 
25 #include <ossim/init/ossimInit.h>
26 #include <ossim/reg/PhotoBlock.h>
30 
31 using namespace std;
32 using namespace ossim;
33 
34 // Summarizes results of ATP given ATP output JSON
35 int main(int argc, char *argv[])
36 {
37  int returnCode = 0;
38 
39  ossimArgumentParser ap(&argc, argv);
42 
43  if (argc < 2)
44  {
45  cout<<"\nUsage: "<<argv[0]<<" <atp-results.json>\n"<<endl;
46  exit(0);
47  }
48 
49  ossimFilename root_name (argv[1]);
50  ifstream jsonInput (root_name.string());
51  if (jsonInput.fail())
52  {
53  cout<<"\nError opening JSON file <"<<argv[1]<<">\n"<<endl;
54  exit(1);
55  }
56 
57  Json::Value root;
58  jsonInput >> root;
59 
60  root_name = root_name.noExtension();
61 
62  const Json::Value& pbJson = root["photoblock"];
63  PhotoBlock photoblock (pbJson);
64 
65  vector<shared_ptr<Image> >& imageList = photoblock.getImageList();
66  vector<shared_ptr<TiePoint> >& tpList = photoblock.getTiePointList();
67 
68  if (tpList.empty())
69  {
70  cout << "\n " << root_name << " -- No tiepoints found." << endl;
71  return 0;
72  }
73 
75  auto factory = ossimImageHandlerRegistry::instance();
76  map<string, ossimRefPtr<ossimImageGeometry> > geomList;
77 
78  for (auto &image : imageList)
79  {
80  handler = factory->open(image->getFilename());
81  if (!handler)
82  {
83  cout<<"\nError loading image file <"<<image->getFilename()<<">\n"<<endl;
84  exit(1);
85  }
86  geomList.emplace(image->getImageId(), handler->getImageGeometry());
87  }
88 
89  ossimDpt ipA, ipB;
90  ossimGpt gpA, gpB;
91  vector<double> distances;
92  double distance = 0;
93  double accum = 0;
95  string imageID;
96  NEWMAT::SymmetricMatrix cov;
97 
98  for (auto &tp : tpList)
99  {
100  tp->getImagePoint(0, imageID, ipA, cov);
101  geomA = geomList.find(imageID)->second;
102 
103  tp->getImagePoint(1, imageID, ipB, cov);
104  geomB = geomList.find(imageID)->second;
105 
106  if (!geomA || !geomB)
107  {
108  cout<<"\nError: null image geometry encountered.\n"<<endl;
109  exit(1);
110  }
111  geomA->localToWorld(ipA, gpA);
112  geomB->localToWorld(ipB, gpB);
113 
114  distance = gpA.distanceTo(gpB);
115  distances.emplace_back(distance);
116  accum += distance;
117  }
118 
119  double mean = accum / tpList.size();
120  double e = 0;
121  for (double &distance : distances)
122  e += (distance-mean)*(distance-mean);
123  double sigma = sqrt(e/distances.size());
124 
125  cout<<"\n "<<root_name<<" mean residual: "<<mean<<" +- "<<sigma<<" m"<<endl;
126  return 0;
127 }
128 
virtual bool open()=0
Pure virtual open.
ossimFilename noExtension() const
void initialize(int &argc, char **argv)
Definition: ossimInit.cpp:119
std::basic_ifstream< char > ifstream
Class for char input file streams.
Definition: ossimIosFwd.h:44
void addOptions(ossimArgumentParser &parser)
Definition: ossimInit.cpp:100
int main(int argc, char *argv[])
This code was derived from https://gist.github.com/mshockwave.
Definition: Barrier.h:8
Class for representing MSP PhotoBlock.
Definition: PhotoBlock.h:25
ImageList & getImageList()
Definition: PhotoBlock.h:45
double distanceTo(const ossimGpt &arg_gpt) const
METHOD: distanceTo(ossimGpt) Computes straight-line distance in meters between this and arg gpt: ...
Definition: ossimGpt.cpp:431
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if non defined...
bool localToWorld(const ossimDpt &local_pt, ossimGpt &world_pt) const
Exposes the 3D projection from image to world coordinates.
TiePointList & getTiePointList()
Definition: PhotoBlock.h:46
static ossimInit * instance()
Definition: ossimInit.cpp:89
static ossimImageHandlerRegistry * instance()
float distance(double lat1, double lon1, double lat2, double lon2, int units)
const std::string & string() const
Definition: ossimString.h:414