OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimRadialDecentLensDistortion.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: See top level LICENSE.txt file.
5 //
6 // Author: Garrett Potts
7 //
8 // Description:
9 //
10 // MeanRadialLens distortion.
11 //
12 //*******************************************************************
13 // $Id: ossimRadialDecentLensDistortion.cpp 15766 2009-10-20 12:37:09Z gpotts $
14 
15 #include <cstdlib>
18 #include <ossim/base/ossimString.h>
19 #include <ossim/base/ossimCommon.h>
20 
21 RTTI_DEF1(ossimRadialDecentLensDistortion, "ossimRadialDecentLensDistortion",
23 
25  = "principal_point_x";
27  = "principal_point_y";
29  = "radial_distortion_coeff_K";
31  = "decent_distortion_coeff_P";
32 
34 (const ossimKeywordlist& kwl, const char* prefix)
35  :
36  theCalibratedPrincipalPoint (0, 0),
37  theRadialDistortionParameters(5),
38  theDecentDistortionParameters(5)
39 {
40  loadState(kwl, prefix);
41 }
42 
44  const char* prefix)
45 {
46  const char* value;
47 
49 
50  value = kwl.find(prefix, PRINCIPAL_POINT_X_KW);
51  if (value)
52  {
53  theCalibratedPrincipalPoint.x = atof(value);
54  }
55 
56  value = kwl.find(prefix, PRINCIPAL_POINT_Y_KW);
57  if (value)
58  {
59  theCalibratedPrincipalPoint.y = atof(value);
60  }
61 
62  for (int i=0; i<5; ++i)
63  {
65  key += ossimString::toString(i);
66  value = kwl.find(prefix, key.c_str());
67  if (!value)
68  {
70  }
71  else
72  {
74  }
75 
77  key += ossimString::toString(i);
78  value = kwl.find(prefix, key.c_str());
79  if (!value)
80  {
82  }
83  else
84  {
86  }
87  }
88 
89  //***
90  // Pass on to base class:
91  //***
92  bool rtn_val = ossim2dTo2dTransform::loadState(kwl, prefix);
93 
94  return rtn_val;
95 }
96 
98  const char* prefix) const
99 {
100  //***
101  // Principal Point:
102  //***
105 
106  for(int i=0; i<5; ++i)
107  {
108  //---
109  // Radial distortion coefficients:
110  //---
112  key += ossimString::toString(i);
113  kwl.add(prefix,
114  key.c_str(),
116  true, // overwrite
117  15); // scientific
118 
119  //---
120  // Decentering distortion coefficients:
121  //---
123  key += ossimString::toString(i);
124  kwl.add(prefix,
125  key.c_str(),
127  true, // overwrite
128  15); // scientific
129  }
130 
131  //***
132  // Pass on to base class:
133  //***
134  bool rtn_val = ossim2dTo2dTransform::saveState(kwl, prefix);
135 
136  return rtn_val;
137 }
138 
139 //*****************************************************************************
140 // METHOD
141 //*****************************************************************************
142 double ossimRadialDecentLensDistortion::deltaR(double radius)const
143 {
144  double rSquare = radius*radius;
145 
147  rSquare*(theRadialDistortionParameters[1] +
148  rSquare*(theRadialDistortionParameters[2] +
149  rSquare*(theRadialDistortionParameters[3] +
150  rSquare*theRadialDistortionParameters[4])));
151 }
152 
153 //*****************************************************************************
154 // METHOD
155 //*****************************************************************************
157  ossimDpt& output_pt)
158  const
159 {
160  ossimDpt deltaPosition(input_pt.x - theCalibratedPrincipalPoint.x,
161  input_pt.y - theCalibratedPrincipalPoint.y);
162  double r = sqrt(ossim::square(deltaPosition.x) +
163  ossim::square(deltaPosition.y));
164  double dr = deltaR(r);
165  double deltaX1 = deltaPosition.x*dr;
166  double deltaY1 = deltaPosition.y*dr;
167 
168  double rSquare = r*r;
169  double deltaX2 = (1 + theDecentDistortionParameters[3]*rSquare +
170  theDecentDistortionParameters[4]*rSquare*rSquare)*
171  (theDecentDistortionParameters[1]*(rSquare + 2*deltaPosition.x*deltaPosition.x) +
172  2*theDecentDistortionParameters[2]*deltaPosition.x*deltaPosition.y);
173 
174  double deltaY2 = (1 + theDecentDistortionParameters[3]*rSquare + theDecentDistortionParameters[4]*rSquare*rSquare)*
175  (theDecentDistortionParameters[2]*(rSquare + 2*deltaPosition.y*deltaPosition.y) +
176  2*theDecentDistortionParameters[1]*deltaPosition.x*deltaPosition.y);
177 
178  output_pt.x = deltaPosition.x + deltaX1 + deltaX2;
179  output_pt.y = deltaPosition.y + deltaY1 + deltaY2;
180 }
181 
182 //*****************************************************************************
183 // METHOD: ossimRadialDecentLensDistortion::print()
184 //
185 //*****************************************************************************
187 {
188  os << "\nDump of ossimRadialDecentLensDistortion object" << endl;
189 
190  os << " theCalibratedPrincipalPoint: " << theCalibratedPrincipalPoint;
191 
192  for (unsigned int i=0; i<5; i++)
193  os << "\n K["<<i<<"]: " << theRadialDistortionParameters[i];
194 
195  for (unsigned int i=0; i<5; i++)
196  os << "\n P["<<i<<"]: " << theDecentDistortionParameters[i];
197 
198  os << endl;
199 
200  // call base class print???
201 
202  return os;
203 }
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Represents serializable keyword/value map.
const char * find(const char *key) const
virtual void forward(const ossimDpt &undistorted_point_in, ossimDpt &distorted_point_out) const
double y
Definition: ossimDpt.h:165
static ossimString toString(bool aValue)
Numeric to string methods.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
T square(T x)
Definition: ossimCommon.h:334
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual double deltaR(double radius) const
double toDouble() const
virtual std::ostream & print(std::ostream &out) const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
RTTI_DEF1(ossimRadialDecentLensDistortion, "ossimRadialDecentLensDistortion", ossim2dTo2dTransform)
double x
Definition: ossimDpt.h:164
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const