mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-30 00:50:37 +08:00
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:
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user