From a482ab8ad5fdd214d6d38fe14ece3d25571a003e Mon Sep 17 00:00:00 2001 From: Sameer Agarwal Date: Tue, 18 Feb 2014 22:24:03 -0800 Subject: [PATCH] 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 --- include/ceres/problem.h | 6 +++++- internal/ceres/problem.cc | 12 ++++++++++++ internal/ceres/problem_impl.cc | 14 ++++++++++++++ internal/ceres/problem_impl.h | 3 +++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/include/ceres/problem.h b/include/ceres/problem.h index 77ff9702f..a7d78158d 100644 --- a/include/ceres/problem.h +++ b/include/ceres/problem.h @@ -300,7 +300,7 @@ class Problem { // 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 @@ class Problem { // 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 bc6d26a3a..9bdc1efc0 100644 --- a/internal/ceres/problem.cc +++ b/internal/ceres/problem.cc @@ -183,6 +183,18 @@ const LocalParameterization* Problem::GetParameterization( 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* residuals, diff --git a/internal/ceres/problem_impl.cc b/internal/ceres/problem_impl.cc index 988267784..99f3f8959 100644 --- a/internal/ceres/problem_impl.cc +++ b/internal/ceres/problem_impl.cc @@ -541,6 +541,20 @@ const LocalParameterization* ProblemImpl::GetParameterization( ->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* residuals, diff --git a/internal/ceres/problem_impl.h b/internal/ceres/problem_impl.h index da505782f..75bdc2ba7 100644 --- a/internal/ceres/problem_impl.h +++ b/internal/ceres/problem_impl.h @@ -129,6 +129,9 @@ class ProblemImpl { 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* residuals,