Isis 3 Programmer Reference
SurfaceModel.cpp
1 #include "SurfaceModel.h"
2 
3 namespace Isis {
6  p_poly2d = new PolynomialBivariate(2);
7  p_lsq = new LeastSquares(*p_poly2d);
8  }
9 
12  delete p_lsq;
13  delete p_poly2d;
14  }
15 
18  void SurfaceModel::AddTriplet(const double x, const double y, const double z) {
19  std::vector<double> vec;
20  vec.push_back(x);
21  vec.push_back(y);
22  p_lsq->AddKnown(vec, z);
23  }
24 
27  void SurfaceModel::AddTriplets(const double *x, const double *y,
28  const double *z, const int n) {
29  for(int i = 0; i < n; i++) {
30  AddTriplet(x[i], y[i], z[i]);
31  }
32  }
33 
36  void SurfaceModel::AddTriplets(const std::vector<double> &x,
37  const std::vector<double> &y,
38  const std::vector<double> &z) {
39  for(int i = 0; i < (int)x.size(); i++) {
40  AddTriplet(x[i], y[i], z[i]);
41  }
42  }
43 
46  p_lsq->Solve();
47  }
48 
51  double SurfaceModel::Evaluate(const double x, const double y) {
52  std::vector<double> vec;
53  vec.push_back(x);
54  vec.push_back(y);
55  return p_lsq->Evaluate(vec);
56  }
57 
64  int SurfaceModel::MinMax(double &x, double &y) {
65  /* For a PolynomialBivariate of 2nd degree, the partial derivatives are two lines:
66  *
67  * dz/dx = b + 2dx + ey
68  * dz/dy = c + ex + 2fy
69  *
70  * We will have a local min/max where dz/dx and dz/dy = 0.
71  * Solve using that condition using linear algebra yields:
72  *
73  * xlocal = (ce - 2bf) / (4df - ee)
74  * ylocal = (be - 2cd) / (4df - ee)
75  */
76 
77  // Get coefficients
78  double b = p_poly2d->Coefficient(1);
79  double c = p_poly2d->Coefficient(2);
80  double d = p_poly2d->Coefficient(3);
81  double e = p_poly2d->Coefficient(4);
82  double f = p_poly2d->Coefficient(5);
83 
84  // Compute the determinant
85  double det = 4.0 * d * f - e * e;
86  if(det == 0.0) return 1;
87 
88  // Compute local min/max
89  x = (c * e - 2.0 * b * f) / det;
90  y = (b * e - 2.0 * c * d) / det;
91  return 0;
92  }
93 }
int MinMax(double &x, double &y)
After invoking Solve, a coordinate (x,y) at a local minimum (or maximum) of the surface model can be ...
Nth degree Polynomial with two variables.
void Solve()
Fit a surface to the input triplets.
void AddTriplets(const double *x, const double *y, const double *z, const int n)
Add an array of (x,y,z) triplet to the list of knowns After all knowns are added invoke the Solve met...
double Evaluate(const std::vector< double > &input)
Invokes the BasisFunction Evaluate method.
void AddTriplet(const double x, const double y, const double z)
Add a single (x,y,z) triplet to the list of knowns. After all knowns are added invoke the Solve metho...
Generic least square fitting class.
Definition: LeastSquares.h:115
void AddKnown(const std::vector< double > &input, double expected, double weight=1.0)
Invoke this method for each set of knowns.
double Coefficient(int i) const
Returns the ith coefficient.
double Evaluate(const double x, const double y)
Evaluate at x,y to compute z. This is available after the Solve method is invoked.
SurfaceModel()
Constructor.
Definition: SurfaceModel.cpp:5
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
~SurfaceModel()
Destructor.
int Solve(Isis::LeastSquares::SolveMethod method=SVD)
After all the data has been registered through AddKnown, invoke this method to solve the system of eq...