Fix sampled_function.cc to use the new CubicInterpolator API.

Change-Id: I1b2063505dc2296c141989c93a939175d5dba7e1
This commit is contained in:
Sameer Agarwal
2015-02-08 10:53:37 -08:00
parent 3125c23228
commit c62bb845cd
+8 -4
View File
@@ -35,6 +35,7 @@
#include "ceres/cubic_interpolation.h"
#include "glog/logging.h"
using ceres::Array1D;
using ceres::CubicInterpolator;
using ceres::AutoDiffCostFunction;
using ceres::CostFunction;
@@ -45,7 +46,8 @@ using ceres::Solve;
// A simple cost functor that interfaces an interpolated table of
// values with automatic differentiation.
struct InterpolatedCostFunctor {
explicit InterpolatedCostFunctor(const CubicInterpolator& interpolator)
explicit InterpolatedCostFunctor(
const CubicInterpolator<Array1D<double> >& interpolator)
: interpolator_(interpolator) {
}
@@ -53,13 +55,14 @@ struct InterpolatedCostFunctor {
return interpolator_.Evaluate(*x, residuals);
}
static CostFunction* Create(const CubicInterpolator& interpolator) {
static CostFunction* Create(
const CubicInterpolator<Array1D<double> >& interpolator) {
return new AutoDiffCostFunction<InterpolatedCostFunctor, 1, 1>(
new InterpolatedCostFunctor(interpolator));
}
private:
const CubicInterpolator& interpolator_;
const CubicInterpolator<Array1D<double> >& interpolator_;
};
int main(int argc, char** argv) {
@@ -72,7 +75,8 @@ int main(int argc, char** argv) {
values[i] = (i - 4.5) * (i - 4.5);
}
CubicInterpolator interpolator(values, kNumSamples);
Array1D<double> array(values, kNumSamples);
CubicInterpolator<Array1D<double> > interpolator(array);
double x = 1.0;
Problem problem;