blob: 50da0299470422b0f72c9145c7f7aede8d4f477b [file] [log] [blame]
Sameer Agarwal02706c12013-05-12 22:07:55 -07001// Ceres Solver - A fast non-linear least squares minimizer
Sameer Agarwal5a30cae2023-09-19 15:29:34 -07002// Copyright 2023 Google Inc. All rights reserved.
Keir Mierle7492b0d2015-03-17 22:30:16 -07003// http://ceres-solver.org/
Sameer Agarwal02706c12013-05-12 22:07:55 -07004//
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
31#include "ceres/covariance.h"
32
33#include <utility>
34#include <vector>
Nikolaus Demmel7b8f6752020-09-20 21:45:24 +020035
Sameer Agarwal02706c12013-05-12 22:07:55 -070036#include "ceres/covariance_impl.h"
37#include "ceres/problem.h"
38#include "ceres/problem_impl.h"
39
40namespace ceres {
41
42Covariance::Covariance(const Covariance::Options& options) {
Sameer Agarwalae652192022-02-02 13:17:29 -080043 impl_ = std::make_unique<internal::CovarianceImpl>(options);
Sameer Agarwal02706c12013-05-12 22:07:55 -070044}
45
Sergiu Deitscha35bd1b2022-02-09 00:56:10 +010046Covariance::~Covariance() = default;
Sameer Agarwal45ac14f2013-05-20 09:15:57 -070047
Sameer Agarwal02706c12013-05-12 22:07:55 -070048bool Covariance::Compute(
Sameer Agarwal9602ed72023-01-14 05:54:24 -080049 const std::vector<std::pair<const double*, const double*>>&
50 covariance_blocks,
Sameer Agarwal02706c12013-05-12 22:07:55 -070051 Problem* problem) {
Dmitriy Korchemkinb7116822022-09-20 13:46:08 +030052 return impl_->Compute(covariance_blocks, problem->mutable_impl());
Sameer Agarwal02706c12013-05-12 22:07:55 -070053}
54
Alexander Ivanov53df5dd2023-01-11 16:51:38 +000055bool Covariance::Compute(const std::vector<const double*>& parameter_blocks,
Nikolaus Demmel7b8f6752020-09-20 21:45:24 +020056 Problem* problem) {
Dmitriy Korchemkinb7116822022-09-20 13:46:08 +030057 return impl_->Compute(parameter_blocks, problem->mutable_impl());
Wannes Van Loockb0bf9fd2015-12-07 14:51:23 +010058}
59
Sameer Agarwal02706c12013-05-12 22:07:55 -070060bool Covariance::GetCovarianceBlock(const double* parameter_block1,
61 const double* parameter_block2,
62 double* covariance_block) const {
Steve Hsua1579be2015-03-12 09:30:11 -070063 return impl_->GetCovarianceBlockInTangentOrAmbientSpace(parameter_block1,
64 parameter_block2,
65 true, // ambient
66 covariance_block);
67}
68
69bool Covariance::GetCovarianceBlockInTangentSpace(
70 const double* parameter_block1,
71 const double* parameter_block2,
72 double* covariance_block) const {
73 return impl_->GetCovarianceBlockInTangentOrAmbientSpace(parameter_block1,
74 parameter_block2,
75 false, // tangent
76 covariance_block);
Sameer Agarwal02706c12013-05-12 22:07:55 -070077}
78
Wannes Van Loockb0bf9fd2015-12-07 14:51:23 +010079bool Covariance::GetCovarianceMatrix(
Alexander Ivanov53df5dd2023-01-11 16:51:38 +000080 const std::vector<const double*>& parameter_blocks,
Johannes Beck84fdac32020-03-24 08:02:21 +010081 double* covariance_matrix) const {
Wannes Van Loockb0bf9fd2015-12-07 14:51:23 +010082 return impl_->GetCovarianceMatrixInTangentOrAmbientSpace(parameter_blocks,
83 true, // ambient
84 covariance_matrix);
85}
86
87bool Covariance::GetCovarianceMatrixInTangentSpace(
Nikolaus Demmel7b8f6752020-09-20 21:45:24 +020088 const std::vector<const double*>& parameter_blocks,
89 double* covariance_matrix) const {
Wannes Van Loockb0bf9fd2015-12-07 14:51:23 +010090 return impl_->GetCovarianceMatrixInTangentOrAmbientSpace(parameter_blocks,
91 false, // tangent
92 covariance_matrix);
93}
94
Sameer Agarwal02706c12013-05-12 22:07:55 -070095} // namespace ceres