Isis 3 Programmer Reference
BasisFunction.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include <iostream>
8 #include "BasisFunction.h"
9 #include "IException.h"
10 #include "IString.h"
11 
12 namespace Isis {
13 
29  BasisFunction::BasisFunction(const QString &name, int numVars, int numCoefs) {
30 
31  p_name = name;
32  p_numVars = numVars;
33  p_numCoefs = numCoefs;
34  }
35 
36 
42  void BasisFunction::SetCoefficients(const std::vector<double> &coefs) {
43 
44  if ( (int)coefs.size() != p_numCoefs ) {
45  QString msg = "Unable to set coefficients vector. The size of the given vector ["
46  + toString((int)coefs.size()) + "] does not match number of coefficients "
47  "in the basis equation [" + toString(p_numCoefs) + "]";
48  throw IException(IException::Programmer, msg, _FILEINFO_);
49  }
50 
51  p_coefs = coefs;
52  }
53 
54 
64  double BasisFunction::Evaluate(const std::vector<double> &vars) {
65 
66  if ( (int)vars.size() != p_numVars ) {
67  QString msg = "Unable to evaluate function for the given vector of values. "
68  "The size of the given vector ["
69  + toString((int)vars.size()) + "] does not match number of variables "
70  "in the basis equation [" + toString(p_numVars) + "]";
71  throw IException(IException::Programmer, msg, _FILEINFO_);
72  }
73 
74  Expand(vars);
75 
76  if ( (int)p_terms.size() != p_numCoefs ) {
77  QString msg = "Unable to evaluate function for the given vector of values. "
78  "The number of terms in the expansion ["
79  + toString( (int)p_terms.size() ) + "] does not match number of coefficients "
80  "in the basis equation [" + toString(p_numCoefs) + "]";
81  throw IException(IException::Programmer, msg, _FILEINFO_);
82  }
83 
84  double result = 0.0;
85 
86  for (int i = 0; i < p_numCoefs; i++) {
87  result += p_coefs[i] * p_terms[i];
88  }
89 
90  return result;
91  }
92 
93 
101  double BasisFunction::Evaluate(const double &var) {
102 
103  std::vector<double> vars;
104  vars.push_back(var);
105  return BasisFunction::Evaluate(vars);
106  }
107 
108 
123  void BasisFunction::Expand(const std::vector<double> &vars) {
124  p_terms = vars;
125  }
126 }
Isis::BasisFunction::p_name
QString p_name
The name of the equation. Call it by using Name()
Definition: BasisFunction.h:109
Isis::BasisFunction::p_numVars
int p_numVars
The number of variables in the equation. Call it by using Variables()
Definition: BasisFunction.h:115
Isis::BasisFunction::SetCoefficients
void SetCoefficients(const std::vector< double > &coefs)
Set the coefficients for the equation.
Definition: BasisFunction.cpp:42
Isis::BasisFunction::p_coefs
std::vector< double > p_coefs
A vector of the coefficients in the equation.
Definition: BasisFunction.h:123
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::BasisFunction::BasisFunction
BasisFunction(const QString &name, int numVars, int numCoefs)
Creates a BasisFunction object.
Definition: BasisFunction.cpp:29
Isis::BasisFunction::Expand
virtual void Expand(const std::vector< double > &vars)
This is the function you should replace depending on your needs.
Definition: BasisFunction.cpp:123
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::BasisFunction::p_numCoefs
int p_numCoefs
The number of coefficients in the equation.
Definition: BasisFunction.h:119
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
Isis::BasisFunction::p_terms
std::vector< double > p_terms
A vector of the terms in the equation.
Definition: BasisFunction.h:127
Isis::BasisFunction::Evaluate
double Evaluate(const std::vector< double > &vars)
Compute the equation using the input variables.
Definition: BasisFunction.cpp:64
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16