Cleanup example code

Remove "using ceres:foo" directives from example code. The using
directives actually make the code harder to read unless you already
know the ceres API. By making the namespace explicit it is clear
to the reader that these are functions and objects from the Ceres
API.

Change-Id: I89b1281c754bf71c0f82e39e1607c5e40a148388
This commit is contained in:
Sameer Agarwal
2023-09-27 14:30:58 -07:00
parent 59182a42c3
commit 3712650941
10 changed files with 77 additions and 133 deletions
+7 -13
View File
@@ -34,13 +34,6 @@
#include "ceres/ceres.h"
#include "glog/logging.h"
using ceres::CENTRAL;
using ceres::CostFunction;
using ceres::NumericDiffCostFunction;
using ceres::Problem;
using ceres::Solve;
using ceres::Solver;
// A cost functor that implements the residual r = 10 - x.
struct CostFunctor {
bool operator()(const double* const x, double* residual) const {
@@ -58,19 +51,20 @@ int main(int argc, char** argv) {
const double initial_x = x;
// Build the problem.
Problem problem;
ceres::Problem problem;
// Set up the only cost function (also known as residual). This uses
// numeric differentiation to obtain the derivative (jacobian).
CostFunction* cost_function =
new NumericDiffCostFunction<CostFunctor, CENTRAL, 1, 1>(new CostFunctor);
ceres::CostFunction* cost_function =
new ceres::NumericDiffCostFunction<CostFunctor, ceres::CENTRAL, 1, 1>(
new CostFunctor);
problem.AddResidualBlock(cost_function, nullptr, &x);
// Run the solver!
Solver::Options options;
ceres::Solver::Options options;
options.minimizer_progress_to_stdout = true;
Solver::Summary summary;
Solve(options, &problem, &summary);
ceres::Solver::Summary summary;
ceres::Solve(options, &problem, &summary);
std::cout << summary.BriefReport() << "\n";
std::cout << "x : " << initial_x << " -> " << x << "\n";