mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-29 16:40:38 +08:00
Simplify instantiation of cost functions and their functors
If arguments are passed to a cost function that can be used to construct the functor, the latter will be instantiated by the cost function using std::make_unique to ensure exception safety. This not only avoids static analysis warnings caused by calling new but also spelling the cost functor type name multiple times. Also expand deduction guides for instantiating Dynamic(Auto|Numeric)DiffCostFunction from std::unique_ptr enabled constructor overloads. Finally, make CostFunction default move constructible and assignable but only through derived classes. This in turn allows derived classes to be movable without relying on custom implementations of corresponding operators. Change-Id: Idee8b9871d862bc9f9f8b5a8d0bedc52863e93c0
This commit is contained in:
@@ -118,12 +118,13 @@ An implementation of the above three steps looks as follows:
|
||||
y[0] = y_in[0];
|
||||
y[1] = y_in[1];
|
||||
|
||||
compute_distortion.reset(new ceres::CostFunctionToFunctor<1, 1>(
|
||||
new ceres::NumericDiffCostFunction<ComputeDistortionValueFunctor,
|
||||
ceres::CENTRAL,
|
||||
1,
|
||||
1>(
|
||||
new ComputeDistortionValueFunctor)));
|
||||
compute_distortion = std::make_unique<ceres::CostFunctionToFunctor<1, 1>>(
|
||||
std::make_unique<ceres::NumericDiffCostFunction<
|
||||
ComputeDistortionValueFunctor
|
||||
, ceres::CENTRAL, 1, 1
|
||||
>
|
||||
>()
|
||||
);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@@ -140,7 +141,7 @@ An implementation of the above three steps looks as follows:
|
||||
|
||||
double x[2];
|
||||
double y[2];
|
||||
std::unique_ptr<ceres::CostFunctionToFunctor<1, 1> > compute_distortion;
|
||||
std::unique_ptr<ceres::CostFunctionToFunctor<1, 1>> compute_distortion;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user