Add Problem::SetParameterLowerBound and Problem::SetParameterUpperBound. These two methods allow the user to associate upper and lower bounds with individual parameters inside parameter blocks. Change-Id: I68dc37f20b64408da510ba06b89a4f08df54ddad
diff --git a/include/ceres/problem.h b/include/ceres/problem.h index 77ff970..a7d7815 100644 --- a/include/ceres/problem.h +++ b/include/ceres/problem.h
@@ -300,7 +300,7 @@ // Hold the indicated parameter block constant during optimization. void SetParameterBlockConstant(double* values); - // Allow the indicated parameter to vary during optimization. + // Allow the indicated parameter block to vary during optimization. void SetParameterBlockVariable(double* values); // Set the local parameterization for one of the parameter blocks. @@ -317,6 +317,10 @@ // associated then NULL is returned. const LocalParameterization* GetParameterization(double* values) const; + // Set the lower/upper bound for the parameter with position "index". + void SetParameterLowerBound(double* values, int index, double lower_bound); + void SetParameterUpperBound(double* values, int index, double upper_bound); + // Number of parameter blocks in the problem. Always equals // parameter_blocks().size() and parameter_block_sizes().size(). int NumParameterBlocks() const;
diff --git a/internal/ceres/problem.cc b/internal/ceres/problem.cc index bc6d26a..9bdc1ef 100644 --- a/internal/ceres/problem.cc +++ b/internal/ceres/problem.cc
@@ -183,6 +183,18 @@ return problem_impl_->GetParameterization(values); } +void Problem::SetParameterLowerBound(double* values, + int index, + double lower_bound) { + problem_impl_->SetParameterLowerBound(values, index, lower_bound); +} + +void Problem::SetParameterUpperBound(double* values, + int index, + double upper_bound) { + problem_impl_->SetParameterUpperBound(values, index, upper_bound); +} + bool Problem::Evaluate(const EvaluateOptions& evaluate_options, double* cost, vector<double>* residuals,
diff --git a/internal/ceres/problem_impl.cc b/internal/ceres/problem_impl.cc index 9882677..99f3f89 100644 --- a/internal/ceres/problem_impl.cc +++ b/internal/ceres/problem_impl.cc
@@ -541,6 +541,20 @@ ->local_parameterization(); } +void ProblemImpl::SetParameterLowerBound(double* values, + int index, + double lower_bound) { + FindParameterBlockOrDie(parameter_block_map_, values) + ->SetLowerBound(index, lower_bound); +} + +void ProblemImpl::SetParameterUpperBound(double* values, + int index, + double upper_bound) { + FindParameterBlockOrDie(parameter_block_map_, values) + ->SetUpperBound(index, upper_bound); +} + bool ProblemImpl::Evaluate(const Problem::EvaluateOptions& evaluate_options, double* cost, vector<double>* residuals,
diff --git a/internal/ceres/problem_impl.h b/internal/ceres/problem_impl.h index da50578..75bdc2b 100644 --- a/internal/ceres/problem_impl.h +++ b/internal/ceres/problem_impl.h
@@ -129,6 +129,9 @@ LocalParameterization* local_parameterization); const LocalParameterization* GetParameterization(double* values) const; + void SetParameterLowerBound(double* values, int index, double lower_bound); + void SetParameterUpperBound(double* values, int index, double upper_bound); + bool Evaluate(const Problem::EvaluateOptions& options, double* cost, vector<double>* residuals,