From 1d2624a10e2c559f8ba9ef89eaa30832c0a83a96 Mon Sep 17 00:00:00 2001 From: Sascha Haeberling Date: Tue, 23 Jul 2013 19:00:21 -0700 Subject: Update ceres to the latest version in google3. Change-Id: I0165fffa55f60714f23e0096eac89fa68df75a05 --- examples/simple_bundle_adjuster.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'examples/simple_bundle_adjuster.cc') diff --git a/examples/simple_bundle_adjuster.cc b/examples/simple_bundle_adjuster.cc index cc6f04a..736d4a2 100644 --- a/examples/simple_bundle_adjuster.cc +++ b/examples/simple_bundle_adjuster.cc @@ -160,6 +160,14 @@ struct SnavelyReprojectionError { return true; } + // Factory to hide the construction of the CostFunction object from + // the client code. + static ceres::CostFunction* Create(const double observed_x, + const double observed_y) { + return (new ceres::AutoDiffCostFunction( + new SnavelyReprojectionError(observed_x, observed_y))); + } + double observed_x; double observed_y; }; @@ -177,6 +185,8 @@ int main(int argc, char** argv) { return 1; } + const double* observations = bal_problem.observations(); + // Create residuals for each observation in the bundle adjustment problem. The // parameters for cameras and points are added automatically. ceres::Problem problem; @@ -184,12 +194,10 @@ int main(int argc, char** argv) { // Each Residual block takes a point and a camera as input and outputs a 2 // dimensional residual. Internally, the cost function stores the observed // image location and compares the reprojection against the observation. - ceres::CostFunction* cost_function = - new ceres::AutoDiffCostFunction( - new SnavelyReprojectionError( - bal_problem.observations()[2 * i + 0], - bal_problem.observations()[2 * i + 1])); + ceres::CostFunction* cost_function = + SnavelyReprojectionError::Create(observations[2 * i + 0], + observations[2 * i + 1]); problem.AddResidualBlock(cost_function, NULL /* squared loss */, bal_problem.mutable_camera_for_observation(i), -- cgit v1.2.3