Helios++
Helios software for LiDAR simulations
ParametricLinearPiecesFunction.h
1 #pragma once
2 
3 #include <fluxionum/Function.h>
4 #include <fluxionum/LinearPiecesFunction.h>
5 
6 #include <armadillo>
7 
8 namespace fluxionum{
9 
32 template <typename A, typename B>
34  public Function<A, arma::Col<B>>
35 {
36 protected:
37  // *** ATTRIBUTES *** //
38  // ******************** //
43  arma::Col<A> const &start;
48  arma::Mat<B> const &slope;
53  arma::Mat<B> const &intercept;
54 
55 public:
56  // *** CONSTRUCTION / DESTRUCTION *** //
57  // ************************************ //
65  Col<A> const &start,
66  Mat<B> const &slope,
67  Mat<B> const &intercept
68  ) :
69  start(start),
70  slope(slope),
72  {}
73  virtual ~ParametricLinearPiecesFunction() = default;
74 
75  // *** FUNCTION METHODS *** //
76  // ************************** //
85  arma::Col<B> eval(A const &x) override{
86  size_t const xIdx = findIndex(x);
87  return (x-getStart(xIdx))*getSlope(xIdx) + getIntercept(xIdx);
88  }
89 
90 
91  // *** LINEAR FUNCTION *** //
92  // ************************* //
96  inline A getStart(size_t const i=0) const {return start.at(i);}
105  inline arma::Col<B> getSlope(size_t const i=0) const
106  {return slope.row(i).as_col();}
116  inline arma::Col<B> getIntercept(size_t const i=0) const
117  {return intercept.row(i).as_col();}
121  inline size_t findIndex(A const &x) const
123 };
124 
125 }
Abstract class representing a function.
Definition: Function.h:27
size_t findIndex(A const &x) const
Obtain the index identifying the interval where belongs to. It is, find such that .
Definition: LinearPiecesFunction.h:115
Parametric linear pieces function.
Definition: ParametricLinearPiecesFunction.h:35
arma::Col< A > const & start
The set of sorted start points.
Definition: ParametricLinearPiecesFunction.h:43
ParametricLinearPiecesFunction(Col< A > const &start, Mat< B > const &slope, Mat< B > const &intercept)
ParametricLinearPiecesFunction default constructor.
Definition: ParametricLinearPiecesFunction.h:64
arma::Col< B > getSlope(size_t const i=0) const
Obtain the -th slope vector of the linear function.
Definition: ParametricLinearPiecesFunction.h:105
size_t findIndex(A const &x) const
Definition: ParametricLinearPiecesFunction.h:121
arma::Mat< B > const & slope
The slope for each piece so is the slope of the -th variable at the -th interval.
Definition: ParametricLinearPiecesFunction.h:48
A getStart(size_t const i=0) const
Definition: ParametricLinearPiecesFunction.h:96
arma::Col< B > getIntercept(size_t const i=0) const
Obtain the -th intercept vector of the linear function.
Definition: ParametricLinearPiecesFunction.h:116
arma::Mat< B > const & intercept
The intercept for each piece so is the intercept of the -th variable at the -th interval.
Definition: ParametricLinearPiecesFunction.h:53
arma::Col< B > eval(A const &x) override
Calculate the image of by assuming a linear behavior for each component. In this context,...
Definition: ParametricLinearPiecesFunction.h:85