blob: 93effc311c5cc99919865c07d5fd5a173dd503e4 [file] [log] [blame]
Austin Schuh70cc9552019-01-21 19:46:48 -08001// Ceres Solver - A fast non-linear least squares minimizer
Austin Schuh3de38b02024-06-25 18:25:10 -07002// Copyright 2023 Google Inc. All rights reserved.
Austin Schuh70cc9552019-01-21 19:46:48 -08003// 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//
31// Class for loading and holding in memory bundle adjustment problems
32// from the BAL (Bundle Adjustment in the Large) dataset from the
33// University of Washington.
34//
35// For more details see http://grail.cs.washington.edu/projects/bal/
36
37#ifndef CERES_EXAMPLES_BAL_PROBLEM_H_
38#define CERES_EXAMPLES_BAL_PROBLEM_H_
39
40#include <string>
41
Austin Schuh3de38b02024-06-25 18:25:10 -070042namespace ceres::examples {
Austin Schuh70cc9552019-01-21 19:46:48 -080043
44class BALProblem {
45 public:
46 explicit BALProblem(const std::string& filename, bool use_quaternions);
47 ~BALProblem();
48
49 void WriteToFile(const std::string& filename) const;
50 void WriteToPLYFile(const std::string& filename) const;
51
52 // Move the "center" of the reconstruction to the origin, where the
53 // center is determined by computing the marginal median of the
54 // points. The reconstruction is then scaled so that the median
55 // absolute deviation of the points measured from the origin is
56 // 100.0.
57 //
58 // The reprojection error of the problem remains the same.
59 void Normalize();
60
61 // Perturb the camera pose and the geometry with random normal
62 // numbers with corresponding standard deviations.
63 void Perturb(const double rotation_sigma,
64 const double translation_sigma,
65 const double point_sigma);
66
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080067 // clang-format off
Austin Schuh70cc9552019-01-21 19:46:48 -080068 int camera_block_size() const { return use_quaternions_ ? 10 : 9; }
69 int point_block_size() const { return 3; }
70 int num_cameras() const { return num_cameras_; }
71 int num_points() const { return num_points_; }
72 int num_observations() const { return num_observations_; }
73 int num_parameters() const { return num_parameters_; }
74 const int* point_index() const { return point_index_; }
75 const int* camera_index() const { return camera_index_; }
76 const double* observations() const { return observations_; }
77 const double* parameters() const { return parameters_; }
78 const double* cameras() const { return parameters_; }
79 double* mutable_cameras() { return parameters_; }
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080080 // clang-format on
Austin Schuh70cc9552019-01-21 19:46:48 -080081 double* mutable_points() {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080082 return parameters_ + camera_block_size() * num_cameras_;
Austin Schuh70cc9552019-01-21 19:46:48 -080083 }
84
85 private:
86 void CameraToAngleAxisAndCenter(const double* camera,
87 double* angle_axis,
88 double* center) const;
89
90 void AngleAxisAndCenterToCamera(const double* angle_axis,
91 const double* center,
92 double* camera) const;
93 int num_cameras_;
94 int num_points_;
95 int num_observations_;
96 int num_parameters_;
97 bool use_quaternions_;
98
99 int* point_index_;
100 int* camera_index_;
101 double* observations_;
102 // The parameter vector is laid out as follows
103 // [camera_1, ..., camera_n, point_1, ..., point_m]
104 double* parameters_;
105};
106
Austin Schuh3de38b02024-06-25 18:25:10 -0700107} // namespace ceres::examples
Austin Schuh70cc9552019-01-21 19:46:48 -0800108
109#endif // CERES_EXAMPLES_BAL_PROBLEM_H_