OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimLeastSquaresPlane.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Description: Source code produced by Dave Knopp
6 //
7 //*******************************************************************
8 // $Id: ossimLeastSquaresPlane.cpp 23167 2015-02-24 22:07:14Z okramer $
9 
11 #include <iostream> // for debugging
13 
14 using namespace std;
15 
17 : m_a(0.0),
18  m_b(0.0),
19  m_c(0.0),
20  AtA(NULL),
21  Atb(NULL),
22  m_numSamples(0)
23 {
24  // allocate normal system accumulation matrices
25  AtA = new NEWMAT::Matrix(3,3);
26  Atb = new NEWMAT::Matrix(3,1);
27 
28  // ensure initilization to zero
29  *AtA = 0.0;
30  *Atb = 0.0;
31 
32  return;
33 }
34 
36 {
37  // allocate normal system accumulation matrices
38  AtA = new NEWMAT::Matrix(3,3);
39  Atb = new NEWMAT::Matrix(3,1);
40 
41  m_a = rhs.m_a;
42  m_b = rhs.m_b;
43  m_c = rhs.m_c;
44 
45  *AtA = *rhs.AtA;
46  *Atb = *rhs.Atb;
47 }
48 
50 {
51  if(AtA)
52  {
53  delete AtA;
54  AtA = NULL;
55  }
56  if(Atb)
57  {
58  delete Atb;
59  Atb = NULL;
60  }
61 }
63 {
64  m_a = rhs.m_a;
65  m_b = rhs.m_b;
66  m_c = rhs.m_c;
67 
68  *AtA = *rhs.AtA;
69  *Atb = *rhs.Atb;
70 
71  return *this;
72 }
73 
75 {
76  *AtA = 0.0;
77  *Atb = 0.0;
78  m_a = 0.0;
79  m_b = 0.0;
80  m_c = 0.0;
81 }
82 
83 void ossimLeastSquaresPlane::addSample(double xx, double yy, double zmea)
84 {
85  // form normal system layer
86  NEWMAT::Matrix AtA_layer(3,1);
87  AtA_layer(1,1) = xx;
88  AtA_layer(2,1) = yy;
89  AtA_layer(3,1) = 1.0;
90 
91  // accumulate layer into normal system
92  *AtA += AtA_layer * AtA_layer.t();
93  *Atb += AtA_layer * zmea;
94 
95  ++m_numSamples;
96 }
97 
99 {
100  if (m_numSamples < 3)
101  return false;
102 
103  NEWMAT::Matrix Soln(3,1);
104  Soln = AtA->i() * (*Atb);
105  m_a = Soln(1,1);
106  m_b = Soln(2,1);
107  m_c = Soln(3,1);
108 
109  return true;
110 }
111 
112 bool ossimLeastSquaresPlane::getLSParms(double& pa, double& pb, double& pc) const
113 {
114  pa = m_a;
115  pb = m_b;
116  pc = m_c;
117 
118  return true;
119 }
120 
121 void ossimLeastSquaresPlane::setLSParams(double pa, double pb, double pc)
122 {
123  m_a = pa;
124  m_b = pb;
125  m_c = pc;
126 }
127 
128 
double m_b
linear-Y term.
ossimLeastSquaresPlane()
Instantiate as zero surface.
virtual void clear()
Will clear everything and set it up to for another solve.
virtual void addSample(double x, double y, double z_mea)
add a single data sample.
double m_c
constant term.
virtual void setLSParams(double pa, double pb, double pc)
bool solveLS()
compute least squares parameter solution - true if succesfull.
double m_a
linear-X term.
ossimLeastSquaresPlane & operator=(const ossimLeastSquaresPlane &)
virtual ~ossimLeastSquaresPlane()
Free internal storage.
virtual bool getLSParms(double &pa, double &pb, double &pc) const
return LS solution parameters.
NEWMAT::Matrix * AtA
Normal system coefficient matrix.
NEWMAT::Matrix * Atb
Normal system RHS vector.
Provide 2D Least Squares Plane model fitting The math model is that of a plane of the form: ...