OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Functions
atp-residuals.cpp File Reference
#include <cmath>
#include <memory>
#include <sstream>
#include <iostream>
#include <ossim/base/ossimApplicationUsage.h>
#include <ossim/base/ossimArgumentParser.h>
#include <ossim/init/ossimInit.h>
#include <ossim/reg/PhotoBlock.h>
#include <ossim/projection/ossimSensorModelTuple.h>
#include <ossim/projection/ossimProjectionFactoryRegistry.h>
#include <ossim/imaging/ossimImageHandlerRegistry.h>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 35 of file atp-residuals.cpp.

References ossimInit::addOptions(), distance(), ossimGpt::distanceTo(), ossimImageHandler::getImageGeometry(), ossim::PhotoBlock::getImageList(), ossim::PhotoBlock::getTiePointList(), ossimInit::initialize(), ossimInit::instance(), ossimImageHandlerRegistry::instance(), ossimImageGeometry::localToWorld(), ossimFilename::noExtension(), ossimImageHandler::open(), and ossimString::string().

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 }
virtual bool open()=0
Pure virtual open.
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
Class for representing MSP PhotoBlock.
Definition: PhotoBlock.h:25
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.
static ossimInit * instance()
Definition: ossimInit.cpp:89
static ossimImageHandlerRegistry * instance()
float distance(double lat1, double lon1, double lat2, double lon2, int units)