blob: 6939b46ed20d21c147217994c53f9f31a46f8f05 [file] [log] [blame]
Austin Schuh70cc9552019-01-21 19:46:48 -08001// Ceres Solver - A fast non-linear least squares minimizer
2// Copyright 2015 Google Inc. All rights reserved.
3// http://ceres-solver.org/
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
40using std::vector;
41
42Problem::Problem() : problem_impl_(new internal::ProblemImpl) {}
43Problem::Problem(const Problem::Options& options)
44 : problem_impl_(new internal::ProblemImpl(options)) {}
45Problem::~Problem() {}
46
47ResidualBlockId Problem::AddResidualBlock(
48 CostFunction* cost_function,
49 LossFunction* loss_function,
50 const vector<double*>& parameter_blocks) {
51 return problem_impl_->AddResidualBlock(
52 cost_function,
53 loss_function,
54 parameter_blocks.data(),
55 static_cast<int>(parameter_blocks.size()));
56}
57
58ResidualBlockId Problem::AddResidualBlock(
59 CostFunction* cost_function,
60 LossFunction* loss_function,
61 double* const* const parameter_blocks,
62 int num_parameter_blocks) {
63 return problem_impl_->AddResidualBlock(cost_function,
64 loss_function,
65 parameter_blocks,
66 num_parameter_blocks);
67}
68
69void Problem::AddParameterBlock(double* values, int size) {
70 problem_impl_->AddParameterBlock(values, size);
71}
72
73void Problem::AddParameterBlock(double* values,
74 int size,
75 LocalParameterization* local_parameterization) {
76 problem_impl_->AddParameterBlock(values, size, local_parameterization);
77}
78
79void Problem::RemoveResidualBlock(ResidualBlockId residual_block) {
80 problem_impl_->RemoveResidualBlock(residual_block);
81}
82
83void Problem::RemoveParameterBlock(double* values) {
84 problem_impl_->RemoveParameterBlock(values);
85}
86
87void Problem::SetParameterBlockConstant(double* values) {
88 problem_impl_->SetParameterBlockConstant(values);
89}
90
91void Problem::SetParameterBlockVariable(double* values) {
92 problem_impl_->SetParameterBlockVariable(values);
93}
94
95bool Problem::IsParameterBlockConstant(double* values) const {
96 return problem_impl_->IsParameterBlockConstant(values);
97}
98
99void Problem::SetParameterization(
100 double* values,
101 LocalParameterization* local_parameterization) {
102 problem_impl_->SetParameterization(values, local_parameterization);
103}
104
105const LocalParameterization* Problem::GetParameterization(
106 double* values) const {
107 return problem_impl_->GetParameterization(values);
108}
109
110void Problem::SetParameterLowerBound(double* values,
111 int index,
112 double lower_bound) {
113 problem_impl_->SetParameterLowerBound(values, index, lower_bound);
114}
115
116void Problem::SetParameterUpperBound(double* values,
117 int index,
118 double upper_bound) {
119 problem_impl_->SetParameterUpperBound(values, index, upper_bound);
120}
121
122double Problem::GetParameterUpperBound(double* values, int index) const {
123 return problem_impl_->GetParameterUpperBound(values, index);
124}
125
126double Problem::GetParameterLowerBound(double* values, int index) const {
127 return problem_impl_->GetParameterLowerBound(values, index);
128}
129
130bool Problem::Evaluate(const EvaluateOptions& evaluate_options,
131 double* cost,
132 vector<double>* residuals,
133 vector<double>* gradient,
134 CRSMatrix* jacobian) {
135 return problem_impl_->Evaluate(evaluate_options,
136 cost,
137 residuals,
138 gradient,
139 jacobian);
140}
141
142int Problem::NumParameterBlocks() const {
143 return problem_impl_->NumParameterBlocks();
144}
145
146int Problem::NumParameters() const {
147 return problem_impl_->NumParameters();
148}
149
150int Problem::NumResidualBlocks() const {
151 return problem_impl_->NumResidualBlocks();
152}
153
154int Problem::NumResiduals() const {
155 return problem_impl_->NumResiduals();
156}
157
158int Problem::ParameterBlockSize(const double* parameter_block) const {
159 return problem_impl_->ParameterBlockSize(parameter_block);
160}
161
162int Problem::ParameterBlockLocalSize(const double* parameter_block) const {
163 return problem_impl_->ParameterBlockLocalSize(parameter_block);
164}
165
166bool Problem::HasParameterBlock(const double* values) const {
167 return problem_impl_->HasParameterBlock(values);
168}
169
170void Problem::GetParameterBlocks(vector<double*>* parameter_blocks) const {
171 problem_impl_->GetParameterBlocks(parameter_blocks);
172}
173
174void Problem::GetResidualBlocks(
175 vector<ResidualBlockId>* residual_blocks) const {
176 problem_impl_->GetResidualBlocks(residual_blocks);
177}
178
179void Problem::GetParameterBlocksForResidualBlock(
180 const ResidualBlockId residual_block,
181 vector<double*>* parameter_blocks) const {
182 problem_impl_->GetParameterBlocksForResidualBlock(residual_block,
183 parameter_blocks);
184}
185
186const CostFunction* Problem::GetCostFunctionForResidualBlock(
187 const ResidualBlockId residual_block) const {
188 return problem_impl_->GetCostFunctionForResidualBlock(residual_block);
189}
190
191const LossFunction* Problem::GetLossFunctionForResidualBlock(
192 const ResidualBlockId residual_block) const {
193 return problem_impl_->GetLossFunctionForResidualBlock(residual_block);
194}
195
196void Problem::GetResidualBlocksForParameterBlock(
197 const double* values,
198 vector<ResidualBlockId>* residual_blocks) const {
199 problem_impl_->GetResidualBlocksForParameterBlock(values,
200 residual_blocks);
201}
202
203} // namespace ceres