PFIdentity.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /**
  2. * @file PFIdentity.h
  3. * @author Alexander Freytag
  4. * @brief Parameterized Function: simple identity (Interface + Implementation)
  5. * @date 01/09/2015
  6. */
  7. #ifndef _NICE_PFIDENTITYINCLUDE
  8. #define _NICE_PFIDENTITYINCLUDE
  9. // STL includes
  10. #include <math.h>
  11. // NICE-core includes
  12. #include <core/vector/VectorT.h>
  13. // NICE-core includes
  14. #include "ParameterizedFunction.h"
  15. namespace NICE {
  16. /**
  17. * @class PFIdentity
  18. * @brief Parameterized Function: simple identity
  19. * @author Alexander Freytag
  20. */
  21. class PFIdentity : public ParameterizedFunction
  22. {
  23. protected:
  24. public:
  25. /** simple constructor, we only have one parameter */
  26. PFIdentity( ) :
  27. ParameterizedFunction(0)
  28. {
  29. };
  30. ~PFIdentity(){};
  31. double f ( uint _index, double _x ) const {
  32. return _x;
  33. }
  34. bool isOrderPreserving() const { return true; };
  35. Vector getParameterUpperBounds() const { return NICE::Vector(0); };
  36. Vector getParameterLowerBounds() const { return NICE::Vector(0); };
  37. void setParameterLowerBounds(const NICE::Vector & _newLowerBounds) { };
  38. void setParameterUpperBounds(const NICE::Vector & _newUpperBounds) { };
  39. /** Persistent interface */
  40. virtual void restore ( std::istream & is, int format = 0 )
  41. {
  42. if (is.good())
  43. {
  44. is.precision (std::numeric_limits<double>::digits10 + 1);
  45. std::string tmp;
  46. bool b_endOfBlock ( false ) ;
  47. while ( !b_endOfBlock )
  48. {
  49. is >> tmp; // start of block
  50. if ( this->isEndTag( tmp, "PFIdentity" ) )
  51. {
  52. b_endOfBlock = true;
  53. continue;
  54. }
  55. tmp = this->removeStartTag ( tmp );
  56. if ( tmp.compare("ParameterizedFunction") == 0 )
  57. {
  58. // restore parent object
  59. ParameterizedFunction::restore(is);
  60. }
  61. else
  62. {
  63. std::cerr << "WARNING -- unexpected PFIdentity object -- " << tmp << " -- for restoration... aborting" << std::endl;
  64. throw;
  65. }
  66. }
  67. }
  68. else
  69. {
  70. std::cerr << "PFIdentity::restore -- InStream not initialized - restoring not possible!" << std::endl;
  71. }
  72. };
  73. virtual void store ( std::ostream & os, int format = 0 ) const
  74. {
  75. if (os.good())
  76. {
  77. // show starting point
  78. os << this->createStartTag( "PFIdentity" ) << std::endl;
  79. os.precision (std::numeric_limits<double>::digits10 + 1);
  80. // store parent object
  81. ParameterizedFunction::store(os);
  82. // done
  83. os << this->createEndTag( "PFIdentity" ) << std::endl;
  84. }
  85. };
  86. virtual void clear () {};
  87. virtual std::string sayYourName() const {return "identity";};
  88. };
  89. }
  90. #endif