1 #ifndef _RSLF_INTERPOLATION 2 #define _RSLF_INTERPOLATION 27 template<
typename DataType>
34 virtual DataType
interpolate(
const Mat& line_matrix,
float index) = 0;
46 template<
typename DataType>
58 template<
typename DataType>
81 template<
typename DataType>
84 const Mat& line_matrix,
88 int rounded_index = (int)std::round(index);
89 if (rounded_index < 0 || rounded_index > line_matrix.cols - 1)
90 return nan_type<DataType>();
91 return line_matrix.at<DataType>(0, rounded_index);
94 template<
typename DataType>
97 const Mat& data_matrix,
112 card_non_nan.setTo(0.0);
115 for (
int r=0; r<indices.rows; r++) {
116 const DataType* data_ptr = data_matrix.ptr<DataType>(r);
117 DataType* res_ptr = res.ptr<DataType>(r);
118 const int* ind_ptr = indices.ptr<
int>(r);
120 for (
int c=0; c<indices.cols; c++) {
121 int rounded_index = (int)std::round(ind_ptr[c]);
122 if (rounded_index > -1 && rounded_index < data_matrix.cols)
124 res_ptr[c] = data_ptr[rounded_index];
125 card_non_nan.at<
float>(c) += 1.0;
129 res_ptr[c] = nan_type<DataType>();
135 template<
typename DataType>
138 const Mat& line_matrix,
142 int rounded_index_inf = (int)std::floor(index);
143 int rounded_index_sup = (int)std::ceil(index);
145 if (rounded_index_sup < 0 || rounded_index_inf > line_matrix.cols - 1)
146 return nan_type<DataType>();
147 if (rounded_index_sup == 0)
148 return line_matrix.at<DataType>(0, 0);
149 if (rounded_index_inf == line_matrix.cols - 1)
150 return line_matrix.at<DataType>(0, line_matrix.cols - 1);
153 float t = index - rounded_index_inf;
154 return line_matrix.at<DataType>(0, rounded_index_inf) * (1 - t) + line_matrix.at<DataType>(0, rounded_index_sup) * t;
157 template<
typename DataType>
160 const Mat& data_matrix,
171 card_non_nan.setTo(0.0);
174 for (
int r=0; r<indices.rows; r++) {
175 const DataType* data_ptr = data_matrix.ptr<DataType>(r);
176 DataType* res_ptr = res.ptr<DataType>(r);
177 const float* ind_ptr = indices.ptr<
float>(r);
179 for (
int c=0; c<indices.cols; c++) {
180 int ind_i = (int)std::floor(ind_ptr[c]);
181 int ind_s = (int)std::ceil(ind_ptr[c]);
182 float ind_residue = ind_ptr[c] - ind_i;
183 if (!(ind_i < 0 || ind_s > data_matrix.cols - 1))
185 res_ptr[c] = (1-ind_residue)*data_ptr[ind_i] + ind_residue*data_ptr[ind_s];
186 card_non_nan.at<
float>(c) += 1.0;
190 res_ptr[c] = nan_type<DataType>();
virtual void interpolate_mat(const Mat &data_matrix, const Mat &indices, Mat &res, Mat &card_non_nan)=0
Get the matrix with interpolation value at the index on the provided line for each element...
Template linear interpolation class.
Definition: rslf_interpolation.hpp:59
Definition: rslf_depth_computation.hpp:14
virtual DataType interpolate(const Mat &line_matrix, float index)=0
Get the interpolation value at the requested index on the provided line.
Implement a toolbox of utilitary functions.
void interpolate_mat(const Mat &data_matrix, const Mat &indices, Mat &res, Mat &card_non_nan)
Get the matrix with interpolation value at the index on the provided line for each element...
Definition: rslf_interpolation.hpp:159
Nearest neighbour interpolation class.
Definition: rslf_interpolation.hpp:47
cv::Mat Mat
RSLF Matrix class (cv::Mat)
Definition: rslf_types.hpp:26
DataType interpolate(const Mat &line_matrix, float index)
Get the interpolation value at the requested index on the provided line.
Definition: rslf_interpolation.hpp:83
Pure virtual class implementing a generic interpolation instance.
Definition: rslf_interpolation.hpp:28
DataType interpolate(const Mat &line_matrix, float index)
Get the interpolation value at the requested index on the provided line.
Definition: rslf_interpolation.hpp:137
void interpolate_mat(const Mat &data_matrix, const Mat &indices, Mat &res, Mat &card_non_nan)
Get the matrix with interpolation value at the index on the provided line for each element...
Definition: rslf_interpolation.hpp:96