OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
AutoTiePoint.cpp
Go to the documentation of this file.
1 //**************************************************************************************************
2 //
3 // OSSIM Open Source Geospatial Data Processing Library
4 // See top level LICENSE.txt file for license information
5 //
6 //**************************************************************************************************
7 #include "AutoTiePoint.h"
8 #include "AtpConfig.h"
9 #include "AtpGenerator.h"
10 #include "../AtpCommon.h"
12 
13 using namespace std;
14 using namespace ossim;
15 
16 namespace ATP
17 {
18 AutoTiePoint::AutoTiePoint()
19 : m_relativeError(0),
20  m_generator(0)
21 {
22 }
23 
25  : TiePoint (copy),
26  m_generator(copy.m_generator),
27  m_refViewPt(copy.m_refViewPt),
28  m_cmpViewPt(copy.m_cmpViewPt),
29  m_residual(copy.m_residual),
30  m_relativeError(copy.m_relativeError)
31 {
32  for (size_t i=0; i<copy.m_matchPoints.size(); ++i)
33  m_matchPoints.push_back(copy.m_matchPoints[i]);
34 }
35 
36 AutoTiePoint::AutoTiePoint(shared_ptr<AtpGenerator> generator, const std::string& id)
37 : m_generator(generator),
38  m_relativeError(0)
39 {
40  m_type = TiePoint::AUTO;
41  setTiePointId(id);
42  if (!m_generator)
43  {
44  CFATAL << "AutoTiePoint Constructor ERROR: Null overlap chain passed." << endl;
45  return;
46  }
47 
48  // Because the Image IDs are not unique, use the image filename as the ID:
49  shared_ptr<Image> ref (new Image(m_generator->getRefImageID(), m_generator->getRefFilename()));
50  shared_ptr<Image> cmp (new Image(m_generator->getCmpImageID(), m_generator->getCmpFilename()));
51  m_images.push_back(ref);
52  m_images.push_back(cmp);
53 }
54 
55 AutoTiePoint::AutoTiePoint(const Json::Value& tp_json_node)
56 : TiePoint(tp_json_node),
57  m_relativeError(0),
58  m_generator(0)
59 {
60 }
61 
63 {
64  m_matchPoints.clear();
65 }
66 
68 {
69  residual = m_residual;
70  return true;
71 }
72 
73 bool AutoTiePoint::getCmpImagePoint(ossimDpt& image_point) const
74 {
75  if ((m_imagePoints.size() < 2) || m_imagePoints[1].isNan())
76  return false;
77  image_point = m_imagePoints[1];
78  return true;
79 }
80 
81 bool AutoTiePoint::getRefImagePoint(ossimDpt& image_point) const
82 {
83  if (m_imagePoints.empty() || m_imagePoints[0].isNan())
84  return false;
85  image_point = m_imagePoints[0];
86  return true;
87 }
88 
90 {
91  if (m_imagePoints.empty())
92  m_imagePoints.push_back(imagePt);
93  else
94  m_imagePoints[0] = imagePt;
95  m_generator->getRefIVT()->imageToView(imagePt, m_refViewPt);
96 }
97 
99 {
100  m_refViewPt = viewPt;
101  ossimDpt imagePt;
102  m_generator->getRefIVT()->viewToImage(viewPt, imagePt);
103  if (m_imagePoints.empty())
104  m_imagePoints.push_back(imagePt);
105  else
106  m_imagePoints[0] = imagePt;
107 }
108 
109 void AutoTiePoint::saveJSON(Json::Value& json_node) const
110 {
111  TiePoint::saveJSON(json_node);// ID
112  if (m_matchPoints.empty())
113  return;
114  json_node["confidence"] = m_matchPoints[0].getConfidenceMeasure();
115 
116  auto geom = m_generator->getRefIVT()->getViewGeometry();
117  if (geom)
118  {
119  ossimGpt refGpt, cmpGpt;
120  geom->localToWorld(m_refViewPt, refGpt);
121  geom->localToWorld(m_cmpViewPt, cmpGpt);
122  Json::Value residual;
123  residual["range"] = refGpt.distanceTo(cmpGpt);
124  residual["azimuth"] = refGpt.azimuthTo(cmpGpt);
125  json_node["residual"] = residual;
126  }
127 }
128 
130 {
131  double azimuth = atan2(m_residual.x, - m_residual.y)*DEG_PER_RAD;
132  if (azimuth < 0.0)
133  azimuth += 360.0;
134 
135  out << "\nDump of AutoTiePoint ID = " << m_tiePointId;
136  out << "\n refImgPt = " << m_imagePoints[0];
137  out << "\n residual (p) = " << m_residual;
138  out << "\n azimuth deg = " << azimuth;
139  TiePoint::print(out);
140  if (m_matchPoints.size() == 0)
141  {
142  out<<"\n No matches.";
143  }
144  else
145  {
146  out<<"\n Matches:";
147  for (size_t i=0; i<m_matchPoints.size(); ++i)
148  out<<"\n "<<m_matchPoints[i];
149  }
150 
151  return out;
152 }
153 
154 void AutoTiePoint::addImageMatch(const ossimDpt& cmpImagePt, double confidenceValue)
155 {
156  // Check if we will be inserting in first position. If so, need to set m_cmpViewPt and
157  // m_residual data members to this (active) active peak info:
158  if (m_matchPoints.size() == 0)
159  {
160  if (m_imagePoints.empty())
161  {
162  ossimDpt nanRefPt;
163  nanRefPt.makeNan();
164  m_imagePoints.push_back(nanRefPt);
165  }
166  if (m_imagePoints.size() == 1)
167  m_imagePoints.push_back(cmpImagePt);
168  else
169  m_imagePoints[1] = cmpImagePt;
170 
172  }
173 
174  // Instantiate a new peak. Insert this peak into the map, where it is ordered by peak value:
175  m_matchPoints.emplace_back(MatchPoint(cmpImagePt, confidenceValue, m_residual));
176 }
177 
178 bool AutoTiePoint::getConfidenceMeasure(double &confidence) const
179 {
180  // Check for empty list or if we are at the end of the list (no points remaining):
181  if ((!hasValidMatch()))
182  {
183  confidence = 0;
184  return false;
185  }
186 
187  // The first peak in the list is always the best peak:
188  confidence = m_matchPoints.begin()->getConfidenceMeasure();
189  return true;
190 }
191 
193 {
194  m_matchPoints.erase(m_matchPoints.begin());
195  if (m_matchPoints.empty())
196  return false;
197 
199  return true;
200 }
201 
203 {
204  return !m_matchPoints.empty();
205 }
206 
207 void AutoTiePoint::addViewMatch(const ossimDpt& cmpViewPt, double confidenceValue)
208 {
209  // Need to compute what the CMP image point is for the peak:
210  ossimDpt cmpImagePt;
211  m_generator->getCmpIVT()->viewToImage(cmpViewPt, cmpImagePt);
212 
213  // Check if we will be inserting in first position. If so, need to set m_cmpViewPt and
214  // m_residual data members to this (active) active peak info:
215  if (m_matchPoints.size() == 0)
216  m_cmpViewPt = cmpViewPt;
217 
218  addImageMatch(cmpImagePt, confidenceValue);
219 }
220 
222 {
223  view_point = m_refViewPt;
224  if (m_refViewPt.isNan())
225  return false;
226  return true;
227 }
228 
229 bool AutoTiePoint::getCmpViewPoint(ossimDpt& view_point, unsigned int peak_idx) const
230 {
231  if (peak_idx == 0)
232  {
233  view_point = m_cmpViewPt; // last known point, may be invalid.
234  return true;
235  }
236 
237  return false;
238 }
239 
241 {
242  if (!m_generator)
244 
245  if (m_imagePoints.size() < 2)
246  return;
247 
248  // Since the REF input projection may have changed, recompute the REF view pt data member:
249  m_generator->getRefIVT()->imageToView(m_imagePoints[0], m_refViewPt);
250 
251  // Establish the view-space coordinates of the peak given the peak's image point (in REF imae)
252  // in order to compute residual:
253  m_generator->getCmpIVT()->imageToView(m_imagePoints[1], m_cmpViewPt);
254 
256 }
257 
259 {
260  gpt.makeNan();
261  if (m_refViewPt.isNan())
262  return false;
263 
264  m_generator->getRefIVT()->getViewGeometry()->localToWorld(m_refViewPt, gpt);
265  return true;
266 }
267 
268 
269 }
270 
void setRefViewPt(const ossimDpt &viewPt)
Sets the reference image&#39;s view point (in view space) for this tiepoint.
double azimuthTo(const ossimGpt &arg_gpt) const
METHOD: azimuthTo(ossimGpt) Computes the great-circle starting azimuth (i.e., at this gpt) to the arg...
Definition: ossimGpt.cpp:446
bool getRefImagePoint(ossimDpt &image_pt) const
Returns the center location of the reference patch (the feature) in image-space.
bool getVectorResidual(ossimDpt &residual) const
Returns the vector residual (CMP-REF) of current active peak (in view space) via argument.
bool getRefGroundPoint(ossimGpt &gpt) const
Returns the center location of the reference patch (the feature) in geographic.
Base class for all automatic tiepoints.
Definition: AutoTiePoint.h:30
#define DEG_PER_RAD
ossimDpt m_refViewPt
Definition: AutoTiePoint.h:131
bool getConfidenceMeasure(double &confidence) const
Returns the correlation value of current active peak via argument. Returns true if valid...
This code was derived from https://gist.github.com/mshockwave.
Definition: Barrier.h:8
double y
Definition: ossimDpt.h:165
void makeNan()
Definition: ossimGpt.h:130
std::ostream & print(H5::H5File *file, std::ostream &out)
Print method.
Definition: ossimH5Util.cpp:41
bool isNan() const
Definition: ossimDpt.h:72
bool hasValidMatch() const
Returns true if there is a valid peak in the list.
std::vector< ossimDpt > m_imagePoints
Definition: TiePoint.h:116
void setTiePointId(const std::string &id)
Definition: TiePoint.cpp:54
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
void setRefImagePt(const ossimDpt &imagePt)
Sets the reference image&#39;s image point (in image space) for this tiepoint.
bool bumpActiveMatch()
Removes the active match and sets the next peak as active.
virtual ~AutoTiePoint()
std::vector< MatchPoint > m_matchPoints
Definition: AutoTiePoint.h:130
std::string m_tiePointId
Definition: TiePoint.h:114
ossimDpt m_cmpViewPt
Definition: AutoTiePoint.h:132
Class representing an Image as used by ossim-msp services.
Definition: Image.h:27
std::shared_ptr< AtpGenerator > m_generator
Definition: AutoTiePoint.h:129
virtual void recomputeResidual()
Recomputes active peak&#39;s residual after a model adjustment or change in peak.
void addImageMatch(const ossimDpt &cmpPt, double confidenceValue=1.0)
Inserts match in image space by confidence in descending order.
THESE FUNCTIONS REQUIRE OPENCV.
virtual void saveJSON(Json::Value &json) const
std::vector< std::shared_ptr< Image > > m_images
Definition: TiePoint.h:115
void addViewMatch(const ossimDpt &cmpViewPt, double confidenceValue=1.0)
Inserts match in image space by confidence in descending order.
bool getRefViewPoint(ossimDpt &view_pt) const
Returns the center location of the reference patch (the feature) in view-space.
virtual std::ostream & print(std::ostream &out) const
Stream output dump of object.
bool getCmpViewPoint(ossimDpt &view_pt, unsigned int peak_idx=0) const
Fetches the comparison view point for current best peak, or for the peak indicated if provided...
double x
Definition: ossimDpt.h:164
#define CFATAL
bool getCmpImagePoint(ossimDpt &image_pt) const
Fetches the comparison image point for current best peak. Returns false if no valid peak...
Class for representing a single tiepoint on two or more images.
Definition: TiePoint.h:28
Maintains quantities associated with single matchpoint peak.
Definition: MatchPoint.h:26
void makeNan()
Definition: ossimDpt.h:65
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23