A refactor of the cubic interpolation code
1. Push the boundary handling logic into the underlying array
object. This has two very significant impacts:
a. The interpolation code becomes extremely simple to write
and to test.
b. The user has more flexibility in implementing how out of bounds
values are handled. We provide one default implementation.
Change-Id: Ic2f6cf9257ce7110c62e492688e5a6c8be1e7df2
diff --git a/examples/sampled_function.cc b/examples/sampled_function.cc
index ada8a4a..093276a 100644
--- a/examples/sampled_function.cc
+++ b/examples/sampled_function.cc
@@ -35,7 +35,7 @@
#include "ceres/cubic_interpolation.h"
#include "glog/logging.h"
-using ceres::Array1D;
+using ceres::Grid1D;
using ceres::CubicInterpolator;
using ceres::AutoDiffCostFunction;
using ceres::CostFunction;
@@ -47,22 +47,23 @@
// values with automatic differentiation.
struct InterpolatedCostFunctor {
explicit InterpolatedCostFunctor(
- const CubicInterpolator<Array1D<double> >& interpolator)
+ const CubicInterpolator<Grid1D<double> >& interpolator)
: interpolator_(interpolator) {
}
template<typename T> bool operator()(const T* x, T* residuals) const {
- return interpolator_.Evaluate(*x, residuals);
+ interpolator_.Evaluate(*x, residuals);
+ return true;
}
static CostFunction* Create(
- const CubicInterpolator<Array1D<double> >& interpolator) {
+ const CubicInterpolator<Grid1D<double> >& interpolator) {
return new AutoDiffCostFunction<InterpolatedCostFunctor, 1, 1>(
new InterpolatedCostFunctor(interpolator));
}
private:
- const CubicInterpolator<Array1D<double> >& interpolator_;
+ const CubicInterpolator<Grid1D<double> >& interpolator_;
};
int main(int argc, char** argv) {
@@ -75,8 +76,8 @@
values[i] = (i - 4.5) * (i - 4.5);
}
- Array1D<double> array(values, kNumSamples);
- CubicInterpolator<Array1D<double> > interpolator(array);
+ Grid1D<double> array(values, 0, kNumSamples);
+ CubicInterpolator<Grid1D<double> > interpolator(array);
double x = 1.0;
Problem problem;