Helios++
Helios software for LiDAR simulations
ParametricClosestLesserSampleFunction.h
1 #pragma once
2 
3 #include <fluxionum/Function.h>
4 
5 #include <armadillo>
6 
7 namespace fluxionum{
8 
9 template <typename A, typename B>
10 class ParametricClosestLesserSampleFunction : public Function<A, arma::Col<B>>{
11 protected:
12  // *** ATTRIBUTES *** //
13  // ******************** //
18  arma::Col<A> const &t;
25  arma::Mat<B> const &y;
29  size_t i;
30 
31 public:
32  // *** CONSTRUCTION / DESTRUCTION *** //
33  // ************************************ //
43  arma::Col<A> const &t,
44  arma::Mat<B> const &y,
45  size_t const i=0
46  ) :
47  t(t),
48  y(y),
49  i(i)
50  {}
51  virtual ~ParametricClosestLesserSampleFunction() = default;
52 
53  // *** ASSIGNMENT *** //
54  // ******************** //
62  pclsf.t, pclsf.y, pclsf.i
63  );
64  return *this;
65  }
66 
67  // *** FUNCTION METHODS *** //
68  // ************************** //
76  arma::Col<B> eval(A const &tx) override{
77  // Update index if necessary
78  if((i < (t.n_elem)-1) && (tx >= t.at(i+1) || tx < t.at(i))){
79  if(i < (t.n_elem-2) && tx < t.at(i+2)) ++i;
80  else{
81  i = 0;
82  for(size_t j = t.n_elem-1 ; j > 0 ; --j){
83  if(tx >= t.at(j)){
84  i = j;
85  break;
86  }
87  }
88  }
89  }
90  // Return the image of the closest lesser sample
91  return y.row(i).as_col();
92  }
93 
98  virtual void restart(){setCurrentSampleIndex(0);}
99 
100  // *** GETTERs and SETTERs *** //
101  // ***************************** //
105  inline arma::Col<A> const & getT() const {return t;}
109  inline arma::Mat<B> const & getY() const {return y;}
113  inline size_t getCurrentSampleIndex() const {return i;}
117  inline void setCurrentSampleIndex(size_t const i) {this->i = i;}
118 };
119 
120 }
Abstract class representing a function.
Definition: Function.h:27
Definition: ParametricClosestLesserSampleFunction.h:10
ParametricClosestLesserSampleFunction(arma::Col< A > const &t, arma::Mat< B > const &y, size_t const i=0)
ParametricClosestLesserSampleFunction default constructor.
Definition: ParametricClosestLesserSampleFunction.h:42
arma::Mat< B > const & getY() const
Definition: ParametricClosestLesserSampleFunction.h:109
arma::Col< B > eval(A const &tx) override
Find the sample with closest lesser domain with respect to given and return its known vector image .
Definition: ParametricClosestLesserSampleFunction.h:76
arma::Col< A > const & t
The vector of sorted domain components .
Definition: ParametricClosestLesserSampleFunction.h:18
size_t i
The index of the current sorted domain sample.
Definition: ParametricClosestLesserSampleFunction.h:29
ParametricClosestLesserSampleFunction< A, B > & operator=(ParametricClosestLesserSampleFunction< A, B > const &pclsf)
Assignment reference operator.
Definition: ParametricClosestLesserSampleFunction.h:59
void setCurrentSampleIndex(size_t const i)
Definition: ParametricClosestLesserSampleFunction.h:117
arma::Mat< B > const & y
The matrix of sorted image components such that , where is the -th row of as row vector.
Definition: ParametricClosestLesserSampleFunction.h:25
arma::Col< A > const & getT() const
Definition: ParametricClosestLesserSampleFunction.h:105
size_t getCurrentSampleIndex() const
Definition: ParametricClosestLesserSampleFunction.h:113
virtual void restart()
Restart the ParametricClosestLesserSampleFunction so it is at its initial state again (it is,...
Definition: ParametricClosestLesserSampleFunction.h:98