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
@@ -37,17 +37,11 @@
#include "ceres/ceres.h"
#include "glog/logging.h"
using ceres::CostFunction;
using ceres::Problem;
using ceres::SizedCostFunction;
using ceres::Solve;
using ceres::Solver;
// A CostFunction implementing analytically derivatives for the
// function f(x) = 10 - x.
class QuadraticCostFunction
: public SizedCostFunction<1 /* number of residuals */,
1 /* size of first parameter */> {
: public ceres::SizedCostFunction<1 /* number of residuals */,
1 /* size of first parameter */> {
public:
bool Evaluate(double const* const* parameters,
double* residuals,
@@ -86,17 +80,17 @@ 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).
CostFunction* cost_function = new QuadraticCostFunction;
ceres::CostFunction* cost_function = new QuadraticCostFunction;
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";