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
12namespace 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}
QString p_name
The name of the equation. Call it by using Name()
virtual void Expand(const std::vector< double > &vars)
This is the function you should replace depending on your needs.
double Evaluate(const std::vector< double > &vars)
Compute the equation using the input variables.
int p_numVars
The number of variables in the equation. Call it by using Variables()
BasisFunction(const QString &name, int numVars, int numCoefs)
Creates a BasisFunction object.
std::vector< double > p_terms
A vector of the terms in the equation.
std::vector< double > p_coefs
A vector of the coefficients in the equation.
void SetCoefficients(const std::vector< double > &coefs)
Set the coefficients for the equation.
int p_numCoefs
The number of coefficients in the equation.
Isis exception class.
Definition IException.h:91
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211