1 // Ceres Solver - A fast non-linear least squares minimizer 2 // Copyright 2010, 2011, 2012 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 (at) google.com (Sameer Agarwal) 30 // keir (at) 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 38 namespace ceres { 39 40 Problem::Problem() : problem_impl_(new internal::ProblemImpl) {} 41 Problem::Problem(const Problem::Options& options) 42 : problem_impl_(new internal::ProblemImpl(options)) {} 43 Problem::~Problem() {} 44 45 ResidualBlockId 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 54 ResidualBlockId 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 63 ResidualBlockId 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 72 ResidualBlockId 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 81 ResidualBlockId 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 90 ResidualBlockId 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 99 ResidualBlockId 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 108 ResidualBlockId 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 118 ResidualBlockId 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 128 ResidualBlockId 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 138 ResidualBlockId 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 149 void Problem::AddParameterBlock(double* values, int size) { 150 problem_impl_->AddParameterBlock(values, size); 151 } 152 153 void Problem::AddParameterBlock(double* values, 154 int size, 155 LocalParameterization* local_parameterization) { 156 problem_impl_->AddParameterBlock(values, size, local_parameterization); 157 } 158 159 void Problem::RemoveResidualBlock(ResidualBlockId residual_block) { 160 problem_impl_->RemoveResidualBlock(residual_block); 161 } 162 163 void Problem::RemoveParameterBlock(double* values) { 164 problem_impl_->RemoveParameterBlock(values); 165 } 166 167 void Problem::SetParameterBlockConstant(double* values) { 168 problem_impl_->SetParameterBlockConstant(values); 169 } 170 171 void Problem::SetParameterBlockVariable(double* values) { 172 problem_impl_->SetParameterBlockVariable(values); 173 } 174 175 void Problem::SetParameterization( 176 double* values, 177 LocalParameterization* local_parameterization) { 178 problem_impl_->SetParameterization(values, local_parameterization); 179 } 180 181 bool Problem::Evaluate(const EvaluateOptions& evaluate_options, 182 double* cost, 183 vector<double>* residuals, 184 vector<double>* gradient, 185 CRSMatrix* jacobian) { 186 return problem_impl_->Evaluate(evaluate_options, 187 cost, 188 residuals, 189 gradient, 190 jacobian); 191 } 192 193 int Problem::NumParameterBlocks() const { 194 return problem_impl_->NumParameterBlocks(); 195 } 196 197 int Problem::NumParameters() const { 198 return problem_impl_->NumParameters(); 199 } 200 201 int Problem::NumResidualBlocks() const { 202 return problem_impl_->NumResidualBlocks(); 203 } 204 205 int Problem::NumResiduals() const { 206 return problem_impl_->NumResiduals(); 207 } 208 209 int Problem::ParameterBlockSize(const double* parameter_block) const { 210 return problem_impl_->ParameterBlockSize(parameter_block); 211 }; 212 213 int Problem::ParameterBlockLocalSize(const double* parameter_block) const { 214 return problem_impl_->ParameterBlockLocalSize(parameter_block); 215 }; 216 217 void Problem::GetParameterBlocks(vector<double*>* parameter_blocks) const { 218 problem_impl_->GetParameterBlocks(parameter_blocks); 219 } 220 221 } // namespace ceres 222