1// Ceres Solver - A fast non-linear least squares minimizer 2// Copyright 2013 Google Inc. All rights reserved. 3// http://code.google.com/p/ceres-solver/ 4// 5// Redistribution and use in source and binary forms, with or without 6// modification, are permitted provided that the following conditions are met: 7// 8// * Redistributions of source code must retain the above copyright notice, 9// this list of conditions and the following disclaimer. 10// * Redistributions in binary form must reproduce the above copyright notice, 11// this list of conditions and the following disclaimer in the documentation 12// and/or other materials provided with the distribution. 13// * Neither the name of Google Inc. nor the names of its contributors may be 14// used to endorse or promote products derived from this software without 15// specific prior written permission. 16// 17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27// POSSIBILITY OF SUCH DAMAGE. 28// 29// Author: sameeragarwal@google.com (Sameer Agarwal) 30// keir@google.com (Keir Mierle) 31 32#include "ceres/problem.h" 33 34#include <vector> 35#include "ceres/crs_matrix.h" 36#include "ceres/problem_impl.h" 37 38namespace ceres { 39 40Problem::Problem() : problem_impl_(new internal::ProblemImpl) {} 41Problem::Problem(const Problem::Options& options) 42 : problem_impl_(new internal::ProblemImpl(options)) {} 43Problem::~Problem() {} 44 45ResidualBlockId Problem::AddResidualBlock( 46 CostFunction* cost_function, 47 LossFunction* loss_function, 48 const vector<double*>& parameter_blocks) { 49 return problem_impl_->AddResidualBlock(cost_function, 50 loss_function, 51 parameter_blocks); 52} 53 54ResidualBlockId Problem::AddResidualBlock( 55 CostFunction* cost_function, 56 LossFunction* loss_function, 57 double* x0) { 58 return problem_impl_->AddResidualBlock(cost_function, 59 loss_function, 60 x0); 61} 62 63ResidualBlockId Problem::AddResidualBlock( 64 CostFunction* cost_function, 65 LossFunction* loss_function, 66 double* x0, double* x1) { 67 return problem_impl_->AddResidualBlock(cost_function, 68 loss_function, 69 x0, x1); 70} 71 72ResidualBlockId Problem::AddResidualBlock( 73 CostFunction* cost_function, 74 LossFunction* loss_function, 75 double* x0, double* x1, double* x2) { 76 return problem_impl_->AddResidualBlock(cost_function, 77 loss_function, 78 x0, x1, x2); 79} 80 81ResidualBlockId Problem::AddResidualBlock( 82 CostFunction* cost_function, 83 LossFunction* loss_function, 84 double* x0, double* x1, double* x2, double* x3) { 85 return problem_impl_->AddResidualBlock(cost_function, 86 loss_function, 87 x0, x1, x2, x3); 88} 89 90ResidualBlockId Problem::AddResidualBlock( 91 CostFunction* cost_function, 92 LossFunction* loss_function, 93 double* x0, double* x1, double* x2, double* x3, double* x4) { 94 return problem_impl_->AddResidualBlock(cost_function, 95 loss_function, 96 x0, x1, x2, x3, x4); 97} 98 99ResidualBlockId Problem::AddResidualBlock( 100 CostFunction* cost_function, 101 LossFunction* loss_function, 102 double* x0, double* x1, double* x2, double* x3, double* x4, double* x5) { 103 return problem_impl_->AddResidualBlock(cost_function, 104 loss_function, 105 x0, x1, x2, x3, x4, x5); 106} 107 108ResidualBlockId Problem::AddResidualBlock( 109 CostFunction* cost_function, 110 LossFunction* loss_function, 111 double* x0, double* x1, double* x2, double* x3, double* x4, double* x5, 112 double* x6) { 113 return problem_impl_->AddResidualBlock(cost_function, 114 loss_function, 115 x0, x1, x2, x3, x4, x5, x6); 116} 117 118ResidualBlockId Problem::AddResidualBlock( 119 CostFunction* cost_function, 120 LossFunction* loss_function, 121 double* x0, double* x1, double* x2, double* x3, double* x4, double* x5, 122 double* x6, double* x7) { 123 return problem_impl_->AddResidualBlock(cost_function, 124 loss_function, 125 x0, x1, x2, x3, x4, x5, x6, x7); 126} 127 128ResidualBlockId Problem::AddResidualBlock( 129 CostFunction* cost_function, 130 LossFunction* loss_function, 131 double* x0, double* x1, double* x2, double* x3, double* x4, double* x5, 132 double* x6, double* x7, double* x8) { 133 return problem_impl_->AddResidualBlock(cost_function, 134 loss_function, 135 x0, x1, x2, x3, x4, x5, x6, x7, x8); 136} 137 138ResidualBlockId Problem::AddResidualBlock( 139 CostFunction* cost_function, 140 LossFunction* loss_function, 141 double* x0, double* x1, double* x2, double* x3, double* x4, double* x5, 142 double* x6, double* x7, double* x8, double* x9) { 143 return problem_impl_->AddResidualBlock( 144 cost_function, 145 loss_function, 146 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9); 147} 148 149void Problem::AddParameterBlock(double* values, int size) { 150 problem_impl_->AddParameterBlock(values, size); 151} 152 153void Problem::AddParameterBlock(double* values, 154 int size, 155 LocalParameterization* local_parameterization) { 156 problem_impl_->AddParameterBlock(values, size, local_parameterization); 157} 158 159void Problem::RemoveResidualBlock(ResidualBlockId residual_block) { 160 problem_impl_->RemoveResidualBlock(residual_block); 161} 162 163void Problem::RemoveParameterBlock(double* values) { 164 problem_impl_->RemoveParameterBlock(values); 165} 166 167void Problem::SetParameterBlockConstant(double* values) { 168 problem_impl_->SetParameterBlockConstant(values); 169} 170 171void Problem::SetParameterBlockVariable(double* values) { 172 problem_impl_->SetParameterBlockVariable(values); 173} 174 175void Problem::SetParameterization( 176 double* values, 177 LocalParameterization* local_parameterization) { 178 problem_impl_->SetParameterization(values, local_parameterization); 179} 180 181const LocalParameterization* Problem::GetParameterization( 182 double* values) const { 183 return problem_impl_->GetParameterization(values); 184} 185 186void Problem::SetParameterLowerBound(double* values, 187 int index, 188 double lower_bound) { 189 problem_impl_->SetParameterLowerBound(values, index, lower_bound); 190} 191 192void Problem::SetParameterUpperBound(double* values, 193 int index, 194 double upper_bound) { 195 problem_impl_->SetParameterUpperBound(values, index, upper_bound); 196} 197 198bool Problem::Evaluate(const EvaluateOptions& evaluate_options, 199 double* cost, 200 vector<double>* residuals, 201 vector<double>* gradient, 202 CRSMatrix* jacobian) { 203 return problem_impl_->Evaluate(evaluate_options, 204 cost, 205 residuals, 206 gradient, 207 jacobian); 208} 209 210int Problem::NumParameterBlocks() const { 211 return problem_impl_->NumParameterBlocks(); 212} 213 214int Problem::NumParameters() const { 215 return problem_impl_->NumParameters(); 216} 217 218int Problem::NumResidualBlocks() const { 219 return problem_impl_->NumResidualBlocks(); 220} 221 222int Problem::NumResiduals() const { 223 return problem_impl_->NumResiduals(); 224} 225 226int Problem::ParameterBlockSize(const double* parameter_block) const { 227 return problem_impl_->ParameterBlockSize(parameter_block); 228}; 229 230int Problem::ParameterBlockLocalSize(const double* parameter_block) const { 231 return problem_impl_->ParameterBlockLocalSize(parameter_block); 232}; 233 234bool Problem::HasParameterBlock(const double* values) const { 235 return problem_impl_->HasParameterBlock(values); 236} 237 238void Problem::GetParameterBlocks(vector<double*>* parameter_blocks) const { 239 problem_impl_->GetParameterBlocks(parameter_blocks); 240} 241 242void Problem::GetResidualBlocks( 243 vector<ResidualBlockId>* residual_blocks) const { 244 problem_impl_->GetResidualBlocks(residual_blocks); 245} 246 247void Problem::GetParameterBlocksForResidualBlock( 248 const ResidualBlockId residual_block, 249 vector<double*>* parameter_blocks) const { 250 problem_impl_->GetParameterBlocksForResidualBlock(residual_block, 251 parameter_blocks); 252} 253 254void Problem::GetResidualBlocksForParameterBlock( 255 const double* values, 256 vector<ResidualBlockId>* residual_blocks) const { 257 problem_impl_->GetResidualBlocksForParameterBlock(values, 258 residual_blocks); 259} 260 261} // namespace ceres 262