blob: e6d4ace2e27a0089161ec7c392d81fb9b75ac6da [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//
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
42namespace ceres {
43namespace examples {
44
45class BALProblem {
46 public:
47 explicit BALProblem(const std::string& filename, bool use_quaternions);
48 ~BALProblem();
49
50 void WriteToFile(const std::string& filename) const;
51 void WriteToPLYFile(const std::string& filename) const;
52
53 // Move the "center" of the reconstruction to the origin, where the
54 // center is determined by computing the marginal median of the
55 // points. The reconstruction is then scaled so that the median
56 // absolute deviation of the points measured from the origin is
57 // 100.0.
58 //
59 // The reprojection error of the problem remains the same.
60 void Normalize();
61
62 // Perturb the camera pose and the geometry with random normal
63 // numbers with corresponding standard deviations.
64 void Perturb(const double rotation_sigma,
65 const double translation_sigma,
66 const double point_sigma);
67
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080068 // clang-format off
Austin Schuh70cc9552019-01-21 19:46:48 -080069 int camera_block_size() const { return use_quaternions_ ? 10 : 9; }
70 int point_block_size() const { return 3; }
71 int num_cameras() const { return num_cameras_; }
72 int num_points() const { return num_points_; }
73 int num_observations() const { return num_observations_; }
74 int num_parameters() const { return num_parameters_; }
75 const int* point_index() const { return point_index_; }
76 const int* camera_index() const { return camera_index_; }
77 const double* observations() const { return observations_; }
78 const double* parameters() const { return parameters_; }
79 const double* cameras() const { return parameters_; }
80 double* mutable_cameras() { return parameters_; }
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080081 // clang-format on
Austin Schuh70cc9552019-01-21 19:46:48 -080082 double* mutable_points() {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080083 return parameters_ + camera_block_size() * num_cameras_;
Austin Schuh70cc9552019-01-21 19:46:48 -080084 }
85
86 private:
87 void CameraToAngleAxisAndCenter(const double* camera,
88 double* angle_axis,
89 double* center) const;
90
91 void AngleAxisAndCenterToCamera(const double* angle_axis,
92 const double* center,
93 double* camera) const;
94 int num_cameras_;
95 int num_points_;
96 int num_observations_;
97 int num_parameters_;
98 bool use_quaternions_;
99
100 int* point_index_;
101 int* camera_index_;
102 double* observations_;
103 // The parameter vector is laid out as follows
104 // [camera_1, ..., camera_n, point_1, ..., point_m]
105 double* parameters_;
106};
107
108} // namespace examples
109} // namespace ceres
110
111#endif // CERES_EXAMPLES_BAL_PROBLEM_H_