Helios++
Helios software for LiDAR simulations
ClosestLesserSampleFunction.h
1 #pragma once
2 
3 #include <fluxionum/Function.h>
4 
5 #include <armadillo>
6 
7 namespace fluxionum{
8 
27 template <typename A, typename B>
29 protected:
30  // *** ATTRIBUTES *** //
31  // ******************** //
36  arma::Col<A> const &t;
42  arma::Col<B> const &y;
46  size_t i;
47 
48 public:
49  // *** CONSTRUCTION / DESTRUCTION *** //
50  // ************************************ //
60  arma::Col<A> const &t,
61  arma::Col<B> const &y,
62  size_t const i=0
63  ) :
64  t(t),
65  y(y),
66  i(i)
67  {}
68  virtual ~ClosestLesserSampleFunction() = default;
69 
70  // *** ASSIGNMENT *** //
71  // ******************** //
78  new(this) ClosestLesserSampleFunction<A, B>(clsf.t, clsf.y, clsf.i);
79  return *this;
80  }
81 
82  // *** FUNCTION METHODS *** //
83  // ************************** //
90  B eval(A const &tx) override{
91  // Update index if necessary
92  if((i < (t.n_elem)-1) && (tx >= t.at(i+1) || tx < t.at(i))){
93  if(i < (t.n_elem-2) && tx < t.at(i+2)) ++i;
94  else{
95  i = 0;
96  for(size_t j = t.n_elem-1 ; j > 0 ; --j){
97  if(tx >= t.at(j)){
98  i = j;
99  break;
100  }
101  }
102  }
103  }
104  // Return the image of the closest lesser sample
105  return y.at(i);
106  }
107 
112  virtual void restart(){setCurrentSampleIndex(0);}
113 
114  // *** GETTERs and SETTERs *** //
115  // ***************************** //
119  inline arma::Col<A> const & getT() const {return t;}
123  inline arma::Col<B> const & getY() const {return y;}
127  inline size_t getCurrentSampleIndex() const {return i;}
131  inline void setCurrentSampleIndex(size_t const i) {this->i = i;}
132 };
133 
134 }
Closest lesser sample function.
Definition: ClosestLesserSampleFunction.h:28
size_t i
The index of the current sorted domain sample.
Definition: ClosestLesserSampleFunction.h:46
arma::Col< B > const & y
The vector of sorted image components such that .
Definition: ClosestLesserSampleFunction.h:42
arma::Col< B > const & getY() const
Definition: ClosestLesserSampleFunction.h:123
arma::Col< A > const & t
The vector of sorted domain components .
Definition: ClosestLesserSampleFunction.h:36
virtual void restart()
Restart the ClosestLesserSampleFunction so it is at its initial state again (it is,...
Definition: ClosestLesserSampleFunction.h:112
ClosestLesserSampleFunction< A, B > & operator=(ClosestLesserSampleFunction< A, B > const &clsf)
Assignment reference operator.
Definition: ClosestLesserSampleFunction.h:76
void setCurrentSampleIndex(size_t const i)
Definition: ClosestLesserSampleFunction.h:131
size_t getCurrentSampleIndex() const
Definition: ClosestLesserSampleFunction.h:127
B eval(A const &tx) override
Find the sample with closest lesser domain with respect to given and return its known image .
Definition: ClosestLesserSampleFunction.h:90
arma::Col< A > const & getT() const
Definition: ClosestLesserSampleFunction.h:119
ClosestLesserSampleFunction(arma::Col< A > const &t, arma::Col< B > const &y, size_t const i=0)
ClosestLesserSampleFunction default constructor.
Definition: ClosestLesserSampleFunction.h:59
Abstract class representing a function.
Definition: Function.h:27