USGS

Isis 3.0 Object Programmers' Reference

Home

BasisFunction.cpp

Go to the documentation of this file.
00001 
00023 #include <iostream>
00024 #include "BasisFunction.h"
00025 #include "iException.h"
00026 
00027 namespace Isis {
00028 
00044   BasisFunction::BasisFunction(const std::string &name, int numVars, int numCoefs) {
00045     p_name = name;
00046     p_numVars = numVars;
00047     p_numCoefs = numCoefs;
00048   }
00049 
00055   void BasisFunction::SetCoefficients(const std::vector<double> &coefs) {
00056     if ((int)coefs.size() != p_numCoefs) {
00057       std::string msg = "[coefs] does not match number of coefficients ";
00058       msg += "in the basis equation";
00059       throw Isis::iException::Message(Isis::iException::Programmer,msg,_FILEINFO_);
00060     }
00061     p_coefs = coefs;
00062   }
00063 
00073   double BasisFunction::Evaluate (const std::vector<double> &vars) {
00074     if ((int)vars.size() != p_numVars) {
00075       std::string msg = "[vars] does not match the number of variables ";
00076       msg += "in the basis equation";
00077       throw Isis::iException::Message(Isis::iException::Programmer,msg,_FILEINFO_);
00078     }
00079   
00080     Expand(vars);
00081     if ((int)p_terms.size() != p_numCoefs) {
00082       std::string msg = "Expansion of [terms] does not match number of ";
00083       msg += "coefficients in the basis equation";
00084       throw Isis::iException::Message(Isis::iException::Programmer,msg,_FILEINFO_);
00085     }
00086   
00087     double result = 0.0;
00088     for (int i=0; i<p_numCoefs; i++) {
00089       result += p_coefs[i] * p_terms[i];
00090     }
00091     return result;
00092   }
00093 
00108   void BasisFunction::Expand(const std::vector<double> &vars) {
00109     p_terms = vars;
00110   }
00111 }