OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimProjection.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Garrett Potts
6 //
7 // Description:
8 //
9 // Base class for all projections.
10 //*******************************************************************
11 // $Id: ossimProjection.cpp 17206 2010-04-25 23:20:40Z dburken $
12 
13 #include <iostream>
14 #include <iomanip>
15 
18 #include <ossim/base/ossimDatum.h>
22 //***
23 // Define Trace flags for use within this file:
24 //***
25 #include <ossim/base/ossimTrace.h>
26 static ossimTrace traceExec ("ossimProjection:exec");
27 static ossimTrace traceDebug ("ossimProjection:debug");
28 
29 using namespace std;
30 
31 RTTI_DEF1(ossimProjection, "ossimProjection", ossimObject);
32 
33 //*******************************************************************
34 // Public constructor:
35 //*******************************************************************
37 {
38 }
39 
40 //*****************************************************************************
41 // METHOD: ossimProjection::saveState()
42 //*****************************************************************************
44  const char* prefix)const
45 {
46  kwl.add(prefix,
48  TYPE_NAME(this),
49  true);
50 
51  return true;
52 }
53 
54 //*****************************************************************************
55 // METHOD: ossimProjection::loadState()
56 //*****************************************************************************
58  const char* /* prefix */)
59 {
60  return true;
61 }
62 
63 //*****************************************************************************
64 // METHOD: ossimProjection::worldToLineSample()
65 //
66 // Performs forward projection of ground point to image space via iterative
67 // calls to lineSampleHeightToWorld
68 //
69 //*****************************************************************************
71  ossimDpt& ip) const
72 {
73  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimProjection::worldToLineSample: entering..." << std::endl;
74 
75  static const double PIXEL_THRESHOLD = 0.1; // acceptable pixel error
76  static const int MAX_NUM_ITERATIONS = 20;
77 
78  //***
79  // First check if the world point is inside bounding rectangle:
80  //***
81  int iters = 0;
82  double height = worldPoint.hgt;
83  if ( ossim::isnan(height) )
84  {
85  height = 0.0;
86  }
87 
88  //***
89  // Utilize iterative scheme for arriving at image point. Begin with guess
90  // at image center:
91  //***
92  ip.u = 0;
93  ip.v = 0;
94 
95  ossimDpt ip_du;
96  ossimDpt ip_dv;
97 
98  ossimGpt gp, gp_du, gp_dv;
99  double dlat_du, dlat_dv, dlon_du, dlon_dv;
100  double delta_lat, delta_lon, delta_u, delta_v;
101  double inverse_norm;
102 
103  //***
104  // Begin iterations:
105  //***
106  do
107  {
108  //***
109  // establish perturbed image points about the guessed point:
110  //***
111  ip_du.u = ip.u + 1.0;
112  ip_du.v = ip.v;
113  ip_dv.u = ip.u;
114  ip_dv.v = ip.v + 1.0;
115 
116  //***
117  // Compute numerical partials at current guessed point:
118  //***
119  lineSampleHeightToWorld(ip, height, gp);
120  lineSampleHeightToWorld(ip_du, height, gp_du);
121  lineSampleHeightToWorld(ip_dv, height, gp_dv);
122 
123  dlat_du = gp_du.lat - gp.lat; //e
124  dlon_du = gp_du.lon - gp.lon; //g
125  dlat_dv = gp_dv.lat - gp.lat; //f
126  dlon_dv = gp_dv.lon - gp.lon; //h
127 
128  //***
129  // Test for convergence:
130  //***
131  delta_lat = worldPoint.lat - gp.lat;
132  delta_lon = worldPoint.lon - gp.lon;
133 
134  //***
135  // Compute linearized estimate of image point given gp delta:
136  //***
137  inverse_norm = dlat_dv*dlon_du - dlat_du*dlon_dv; // fg-eh
138  if (inverse_norm != 0)
139  {
140  delta_u = (-dlon_dv*delta_lat + dlat_dv*delta_lon)/inverse_norm;
141  delta_v = ( dlon_du*delta_lat - dlat_du*delta_lon)/inverse_norm;
142  ip.u += delta_u;
143  ip.v += delta_v;
144  }
145  else
146  {
147  delta_u = 0;
148  delta_v = 0;
149  }
150 
151  iters++;
152 
153  } while (((fabs(delta_u) > PIXEL_THRESHOLD) ||
154  (fabs(delta_v) > PIXEL_THRESHOLD)) &&
155  (iters < MAX_NUM_ITERATIONS));
156 
157  //***
158  // Note that this error mesage appears only if max count was reached while
159  // iterating. A linear (no iteration) solution would finish with iters =
160  // MAX_NUM_ITERATIONS + 1:
161  //***
162  if (iters == MAX_NUM_ITERATIONS)
163  {
164 // ossimNotify(ossimNotifyLevel_WARN) << "WARNING ossimProjection::worldToLineSample: Exceeded max number of iterations computing image \n"
165 // << "point for ground point: " << worldPoint
166 // << "\nCheck the geometry file for valid quantities." << endl;
167  }
168 
169 }
170 
172  ossimDpt& errorResult)const
173 {
174  ossimGpt world;
175  ossimDpt testPt;
176 
177  lineSampleToWorld(imagePoint, world);
178  worldToLineSample(world, testPt);
179 
180  errorResult = imagePoint - testPt;
181 }
182 
184  ossimDpt& errorResult)const
185 {
186  ossimDpt tempPt;
187  ossimGpt tempGround;
188 
189  worldToLineSample(groundPoint, tempPt);
190  lineSampleToWorld(tempPt, tempGround);
191 
192  errorResult = ossimDpt(groundPoint) - ossimDpt(tempGround);
193 }
194 
196 {
197 }
198 
200 {
202 }
#define TYPE_NAME(p)
Definition: ossimRtti.h:326
Represents serializable keyword/value map.
double u
Definition: ossimDpt.h:164
virtual std::ostream & print(std::ostream &out) const
Outputs theErrorStatus as an ossimErrorCode and an ossimString.
virtual std::ostream & print(std::ostream &out) const
Outputs theErrorStatus as an ossimErrorCode and an ossimString.
ossim_float64 hgt
Height in meters above the ellipsiod.
Definition: ossimGpt.h:274
static const char * TYPE_KW
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual void getGroundClipPoints(ossimGeoPolygon &gpts) const
ossim_float64 lon
Definition: ossimGpt.h:266
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
RTTI_DEF1(ossimProjection, "ossimProjection", ossimObject)
ossim_float64 lat
Definition: ossimGpt.h:265
virtual void getRoundTripError(const ossimDpt &imagePoint, ossimDpt &errorResult) const
virtual void worldToLineSample(const ossimGpt &worldPoint, ossimDpt &lineSampPt) const =0
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
double v
Definition: ossimDpt.h:165
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.
Definition: ossimCommon.h:91