OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimLensDistortion.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2005 Garrett Potts
3 //
4 // LGPL
5 //
6 // Author: Garrett Potts
7 //
8 // Description:
9 //
10 // ossimLensDistortion
11 //*******************************************************************
12 // $Id: ossimLensDistortion.cpp 15929 2009-11-16 18:20:46Z gpotts $
13 #include <sstream>
16 #include <ossim/base/ossimString.h>
17 
18 RTTI_DEF1(ossimLensDistortion, "ossimLensDistortion", ossim2dTo2dTransform);
19 
21  const char* prefix)const
22 {
24 
25  kwl.add(prefix,
26  "center",
28  true);
29 
30  return true;
31 }
32 
34  const char* prefix)
35 {
36  const char* center = kwl.find(prefix, "center");
37  theCenter.x = 0.0;
38  theCenter.y = 0.0;
39 
40  if(center)
41  {
42  std::vector<ossimString> splitString;
43  ossimString tempString(center);
44  tempString = tempString.trim();
45  tempString.split(splitString, " ");
46  if(splitString.size() == 2)
47  {
48  theCenter.x = splitString[0].toDouble();
49  theCenter.y = splitString[1].toDouble();
50  }
51  }
52 
53  return ossim2dTo2dTransform::loadState(kwl, prefix);
54 
55 }
56 
57 void ossimLensDistortion::distort(const ossimDpt& input, ossimDpt& output)const
58 {
59  int iters = 0;
60 
61  //***
62  // Begin with guess. Forward transform is defined as trasforming left to
63  // right. We are therefore solving for left:
64  //***
65  ossimDpt left (input);
66  ossimDpt left_dx;
67  ossimDpt left_dy;
68  ossimDpt right;
69  ossimDpt right_dx;
70  ossimDpt right_dy;
71  ossimDpt dr_dx;
72  ossimDpt dr_dy;
73  ossimDpt r_diff;
74  ossimDpt l_diff;
75  double inverse_norm;
76 
77  //***
78  // Begin iterations:
79  //***
80  do
81  {
82  //***
83  // establish perturbed image points about the guessed point:
84  //***
85  left_dx.x = left.x + 1.0;
86  left_dx.y = left.y;
87  left_dy.x = left.x;
88  left_dy.y = left.y + 1.0;
89 
90  //***
91  // Compute numerical partials at current guessed point:
92  //***
93  undistort(left, right);
94  undistort(left_dx, right_dx);
95  undistort(left_dy, right_dy);
96 
97  dr_dx.x = (right_dx.x - right.x); //e
98  dr_dx.y = (right_dx.y - right.y); //g
99  dr_dy.x = (right_dy.x - right.x); //f
100  dr_dy.y = (right_dy.y - right.y); //h
101 
102  //***
103  // Test for convergence:
104  //***
105  r_diff = input - right;
106 
107  //***
108  // Compute linearized estimate of image point given gp delta:
109  //***
110  inverse_norm = dr_dy.u*dr_dx.v - dr_dx.u*dr_dy.v; // fg-eh
111  if (std::fabs(inverse_norm) > DBL_EPSILON)
112  {
113  l_diff.u = (-dr_dy.v*r_diff.u + dr_dy.u*r_diff.v)/inverse_norm;
114  l_diff.v = ( dr_dx.v*r_diff.u - dr_dx.u*r_diff.v)/inverse_norm;
115  left += l_diff;
116  }
117  else
118  {
119  l_diff.u = 0;
120  l_diff.v = 0;
121  }
122 
123  iters++;
124 
125  } while (((fabs(l_diff.u) > theConvergenceThreshold) ||
126  (fabs(l_diff.v) > theConvergenceThreshold)) &&
127  (iters < theMaxIterations));
128  output = left;
129 }
130 
RTTI_DEF1(ossimLensDistortion, "ossimLensDistortion", ossim2dTo2dTransform)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Represents serializable keyword/value map.
double u
Definition: ossimDpt.h:164
const char * find(const char *key) const
double y
Definition: ossimDpt.h:165
static ossimString toString(bool aValue)
Numeric to string methods.
void split(std::vector< ossimString > &result, const ossimString &separatorList, bool skipBlankFields=false) const
Splits this string into a vector of strings (fields) using the delimiter list specified.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
#define DBL_EPSILON
virtual void undistort(const ossimDpt &input, ossimDpt &output) const =0
double x
Definition: ossimDpt.h:164
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual void distort(const ossimDpt &input, ossimDpt &output) const
double v
Definition: ossimDpt.h:165