ParameterizedFunction.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * @file ParameterizedFunction.cpp
  3. * @brief Simple parameterized multi-dimensional function (Implementation)
  4. * @author Erik Rodner
  5. * @date 01/04/2012
  6. */
  7. #include <iostream>
  8. #include "ParameterizedFunction.h"
  9. using namespace NICE;
  10. using namespace std;
  11. ParameterizedFunction::ParameterizedFunction( uint dimension )
  12. {
  13. m_parameters.resize(dimension);
  14. }
  15. void ParameterizedFunction::applyFunctionToDataMatrix ( std::vector< std::vector< double > > & dataMatrix ) const
  16. {
  17. // REMARK: might be inefficient due to virtual calls
  18. int iCnt(0);
  19. for ( vector< vector<double> >::iterator i = dataMatrix.begin() ; i != dataMatrix.end(); i++, iCnt++ )
  20. {
  21. uint index = 0;
  22. for ( vector<double>::iterator j = i->begin(); j != i->end(); j++, index++ )
  23. {
  24. *j = f ( iCnt, *j );
  25. }
  26. }
  27. }
  28. void ParameterizedFunction::restore ( std::istream & is, int format )
  29. {
  30. if (is.good())
  31. {
  32. is.precision (numeric_limits<double>::digits10 + 1);
  33. string tmp;
  34. is >> tmp;
  35. is >> m_parameters;
  36. }
  37. }
  38. void ParameterizedFunction::store ( std::ostream & os, int format ) const
  39. {
  40. if (os.good())
  41. {
  42. os.precision (numeric_limits<double>::digits10 + 1);
  43. os << "m_parameters: " << std::endl << m_parameters << std::endl;
  44. }
  45. };