blob: e9a348e4fbf64c6f7ee28359b1e2583257f036ea [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
68 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_; }
80 double* mutable_points() {
81 return parameters_ + camera_block_size() * num_cameras_;
82 }
83
84 private:
85 void CameraToAngleAxisAndCenter(const double* camera,
86 double* angle_axis,
87 double* center) const;
88
89 void AngleAxisAndCenterToCamera(const double* angle_axis,
90 const double* center,
91 double* camera) const;
92 int num_cameras_;
93 int num_points_;
94 int num_observations_;
95 int num_parameters_;
96 bool use_quaternions_;
97
98 int* point_index_;
99 int* camera_index_;
100 double* observations_;
101 // The parameter vector is laid out as follows
102 // [camera_1, ..., camera_n, point_1, ..., point_m]
103 double* parameters_;
104};
105
106} // namespace examples
107} // namespace ceres
108
109#endif // CERES_EXAMPLES_BAL_PROBLEM_H_