Loading [MathJax]/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
SurfaceModel.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include "SurfaceModel.h"
8 
9 namespace Isis {
12  p_poly2d = new PolynomialBivariate(2);
13  p_lsq = new LeastSquares(*p_poly2d);
14  }
15 
18  delete p_lsq;
19  delete p_poly2d;
20  }
21 
24  void SurfaceModel::AddTriplet(const double x, const double y, const double z) {
25  std::vector<double> vec;
26  vec.push_back(x);
27  vec.push_back(y);
28  p_lsq->AddKnown(vec, z);
29  }
30 
33  void SurfaceModel::AddTriplets(const double *x, const double *y,
34  const double *z, const int n) {
35  for(int i = 0; i < n; i++) {
36  AddTriplet(x[i], y[i], z[i]);
37  }
38  }
39 
42  void SurfaceModel::AddTriplets(const std::vector<double> &x,
43  const std::vector<double> &y,
44  const std::vector<double> &z) {
45  for(int i = 0; i < (int)x.size(); i++) {
46  AddTriplet(x[i], y[i], z[i]);
47  }
48  }
49 
52  p_lsq->Solve();
53  }
54 
57  double SurfaceModel::Evaluate(const double x, const double y) {
58  std::vector<double> vec;
59  vec.push_back(x);
60  vec.push_back(y);
61  return p_lsq->Evaluate(vec);
62  }
63 
70  int SurfaceModel::MinMax(double &x, double &y) {
71  /* For a PolynomialBivariate of 2nd degree, the partial derivatives are two lines:
72  *
73  * dz/dx = b + 2dx + ey
74  * dz/dy = c + ex + 2fy
75  *
76  * We will have a local min/max where dz/dx and dz/dy = 0.
77  * Solve using that condition using linear algebra yields:
78  *
79  * xlocal = (ce - 2bf) / (4df - ee)
80  * ylocal = (be - 2cd) / (4df - ee)
81  */
82 
83  // Get coefficients
84  double b = p_poly2d->Coefficient(1);
85  double c = p_poly2d->Coefficient(2);
86  double d = p_poly2d->Coefficient(3);
87  double e = p_poly2d->Coefficient(4);
88  double f = p_poly2d->Coefficient(5);
89 
90  // Compute the determinant
91  double det = 4.0 * d * f - e * e;
92  if(det == 0.0) return 1;
93 
94  // Compute local min/max
95  x = (c * e - 2.0 * b * f) / det;
96  y = (b * e - 2.0 * c * d) / det;
97  return 0;
98  }
99 }
Isis::LeastSquares::Solve
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...
Definition: LeastSquares.cpp:205
Isis::SurfaceModel::Solve
void Solve()
Fit a surface to the input triplets.
Definition: SurfaceModel.cpp:51
Isis::LeastSquares::Evaluate
double Evaluate(const std::vector< double > &input)
Invokes the BasisFunction Evaluate method.
Definition: LeastSquares.cpp:553
Isis::PolynomialBivariate
Nth degree Polynomial with two variables.
Definition: PolynomialBivariate.h:37
Isis::SurfaceModel::AddTriplets
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...
Definition: SurfaceModel.cpp:33
Isis::SurfaceModel::AddTriplet
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...
Definition: SurfaceModel.cpp:24
Isis::LeastSquares
Generic least square fitting class.
Definition: LeastSquares.h:99
Isis::SurfaceModel::SurfaceModel
SurfaceModel()
Constructor.
Definition: SurfaceModel.cpp:11
Isis::SurfaceModel::Evaluate
double Evaluate(const double x, const double y)
Evaluate at x,y to compute z. This is available after the Solve method is invoked.
Definition: SurfaceModel.cpp:57
Isis::SurfaceModel::~SurfaceModel
~SurfaceModel()
Destructor.
Definition: SurfaceModel.cpp:17
Isis::LeastSquares::AddKnown
void AddKnown(const std::vector< double > &input, double expected, double weight=1.0)
Invoke this method for each set of knowns.
Definition: LeastSquares.cpp:96
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::SurfaceModel::MinMax
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 ...
Definition: SurfaceModel.cpp:70
Isis::BasisFunction::Coefficient
double Coefficient(int i) const
Returns the ith coefficient.
Definition: BasisFunction.h:107

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 07/13/2023 15:17:20