1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Garrett Potts (gpotts@imagelinks.com
6 //
7 // Description: Source code produced by Dave Knopp
8 //
9 //*******************************************************************
10 // $Id: ossimLeastSquaresBilin.h 9968 2006-11-29 14:01:53Z gpotts $
11 #ifndef ossimLeastSquaresBilin_INCLUDE
12 #define ossimLeastSquaresBilin_INCLUDE
13 #include <ossim/base/ossimConstants.h>
14 #include <ossim/matrix/newmat.h>
15
16 /**
17 * @brief Provide 2D Least Squares Bilinear model fitting
18 * The math model is that of a bilinear surface of the form:
19 @code
20 z(x,y) = a + b*x + c*y + d*x*y
21 @endcode
22 * The getLSParms() method returns parameter values which are the least
23 * squares solution associated with the samples added via addSample(). Note
24 * that it is necessary to add at least four sample to obtain a solution.
25 */
26
27 class OSSIMDLLEXPORT ossimLeastSquaresBilin
28 {
ossimLagrangeInterpolator()29 public:
30
31 ossimLeastSquaresBilin(const ossimLeastSquaresBilin &);
32 /**
33 * Instantiate as zero surface.
34 */
35 ossimLeastSquaresBilin();
36
37 ossimLeastSquaresBilin & operator = (const ossimLeastSquaresBilin &);
38
39 /**
40 * Free internal storage.
41 */
42 virtual ~ossimLeastSquaresBilin();
43
44
45 /**
46 * Will clear everything and set it up to
47 * for another solve. Just add points
48 * and call the solve method.
49 */
50 virtual void clear();
51
52 /**
53 * add a single data sample.
54 *
55 * @param xx "x" coordinate of sample location.
56 * @param yy "y" "y" coordinate of sample location.
57 * @param zmea sample value measured at (xx,yy)
58 */
59 virtual void addSample(double x, double yy, double zmea);
60
61 /**
62 * return LS solution parameters.
63 *
64 * @param pa set to constant coefficient.
65 * @param pb_x set to linear coefficient of "x"
66 * @param pc_y set to linear coefficient of "y"
67 * @param pd_xy set to cross coefficient of "x*y"
68 */
69 virtual bool getLSParms(double& pa, double& pb_x, double& pc_y, double& pd_xy)const;
70
71 /**
72 * @param pa set to constant coefficient.
73 * @param pb_x set to linear coefficient of "x"
74 * @param pc_y set to linear coefficient of "y"
75 * @param pd_xy set to cross coefficient of "x*y"
76 */
77 virtual void setLSParams(double pa, //constant
78 double pb_x, // linear coefficient of x,
79 double pc_y, // linear coefficient of y
80 double pd_xy); // coefficient of x*y
81
82 /**
83 * interpolate LS-fit value at location (xx,yy) - returns z(xx,yy).
84 *
85 * @param xx "x" coordinate at which to interpolate.
86 * @param yy "y" "y" coordinate at which to interpolate.
87 *
88 */
89 virtual inline double lsFitValue(double xx, double yy) const
90 {
91 return (bl_a + bl_b*xx + bl_c*yy + bl_d*xx*yy);
92 }
93
94 /**
95 * compute least squares parameter solution - true if succesfull.
96 */
97 bool solveLS();
98
99 private:
100 /**
101 * constant term.
102 */
103 double bl_a;
104
105 /**
106 * linear-X term.
107 */
108 double bl_b;
109
110 /**
111 * linear-Y term.
112 */
113 double bl_c;
114
115 /**
116 * cross-XY term
117 */
118 double bl_d;
119
120 /**
121 * Normal system coefficient matrix.
122 */
123 NEWMAT::Matrix* AtA;
124
125 /**
126 * Normal system RHS vector
127 */
128 NEWMAT::Matrix* Atb;
129 };
130
131 #endif // LeastSquaresBilinilin_INCL_
132
133