10 #include <ceres/ceres.h>
14 #include <unordered_set>
79 const std::unordered_set<image_t>&
Images()
const;
85 std::unordered_set<camera_t> constant_camera_ids_;
86 std::unordered_set<image_t> image_ids_;
87 std::unordered_set<point3D_t> variable_point3D_ids_;
88 std::unordered_set<point3D_t> constant_point3D_ids_;
89 std::unordered_set<image_t> constant_poses_;
90 std::unordered_map<image_t, std::vector<int>> constant_tvecs_;
153 #if CERES_VERSION_MAJOR < 2
165 const ceres::Problem& problem)
const;
180 const ceres::Solver::Summary&
Summary()
const;
184 ceres::LossFunction* loss_function);
187 void AddImageToProblem(
const image_t image_id,
189 ceres::LossFunction* loss_function);
191 void AddPointToProblem(
const point3D_t point3D_id,
193 ceres::LossFunction* loss_function);
211 class ParallelBundleAdjuster {
215 bool print_summary =
true;
218 int max_num_iterations = 50;
224 int num_threads = -1;
229 int min_num_residuals_for_cpu_multi_threading = 50000;
234 ParallelBundleAdjuster(
const Options& options,
235 const BundleAdjustmentOptions& ba_options,
236 const BundleAdjustmentConfig& config);
238 bool Solve(Reconstruction* reconstruction);
241 const ceres::Solver::Summary& Summary()
const;
245 static bool IsSupported(
const BundleAdjustmentOptions& options,
246 const Reconstruction& reconstruction);
249 void SetUp(Reconstruction* reconstruction);
250 void TearDown(Reconstruction* reconstruction);
252 void AddImagesToProblem(Reconstruction* reconstruction);
253 void AddPointsToProblem(Reconstruction* reconstruction);
255 const Options options_;
256 const BundleAdjustmentOptions ba_options_;
257 BundleAdjustmentConfig config_;
258 ceres::Solver::Summary summary_;
260 size_t num_measurements_;
261 std::vector<pba::CameraT> cameras_;
262 std::vector<pba::Point3D> points3D_;
263 std::vector<pba::Point2D> measurements_;
264 std::unordered_set<camera_t> camera_ids_;
265 std::unordered_set<point3D_t> point3D_ids_;
266 std::vector<int> camera_idxs_;
267 std::vector<int> point3D_idxs_;
268 std::vector<image_t> ordered_image_ids_;
269 std::vector<point3D_t> ordered_point3D_ids_;
270 std::unordered_map<image_t, int> image_id_to_camera_idx_;
293 std::vector<CameraRig>* camera_rigs);
297 std::vector<CameraRig>* camera_rigs,
298 ceres::LossFunction* loss_function);
300 const std::vector<CameraRig>& camera_rigs);
302 void AddImageToProblem(
const image_t image_id,
304 std::vector<CameraRig>* camera_rigs,
305 ceres::LossFunction* loss_function);
307 void AddPointToProblem(
const point3D_t point3D_id,
309 ceres::LossFunction* loss_function);
312 const std::vector<CameraRig>& camera_rigs);
319 std::unordered_map<image_t, CameraRig*> image_id_to_camera_rig_;
322 std::unordered_map<image_t, Eigen::Vector4d*> image_id_to_rig_qvec_;
323 std::unordered_map<image_t, Eigen::Vector3d*> image_id_to_rig_tvec_;
326 std::vector<std::vector<Eigen::Vector4d>> camera_rig_qvecs_;
327 std::vector<std::vector<Eigen::Vector3d>> camera_rig_tvecs_;
331 std::unordered_set<double*> parameterized_qvec_data_;
std::unique_ptr< ceres::Problem > problem_
const BundleAdjustmentOptions options_
BundleAdjustmentConfig config_
std::unordered_set< camera_t > camera_ids_
const ceres::Solver::Summary & Summary() const
bool Solve(Reconstruction *reconstruction)
std::unordered_map< point3D_t, size_t > point3D_num_observations_
ceres::Solver::Summary summary_
void ParameterizeCameras(Reconstruction *reconstruction)
BundleAdjuster(const BundleAdjustmentOptions &options, const BundleAdjustmentConfig &config)
void ParameterizePoints(Reconstruction *reconstruction)
void RemoveConstantPoint(const point3D_t point3D_id)
void AddVariablePoint(const point3D_t point3D_id)
size_t NumConstantPoses() const
bool HasConstantPose(const image_t image_id) const
size_t NumConstantTvecs() const
void SetVariableCamera(const camera_t camera_id)
void SetVariablePose(const image_t image_id)
bool IsConstantCamera(const camera_t camera_id) const
const std::vector< int > & ConstantTvec(const image_t image_id) const
bool HasConstantTvec(const image_t image_id) const
const std::unordered_set< point3D_t > & VariablePoints() const
bool HasVariablePoint(const point3D_t point3D_id) const
const std::unordered_set< image_t > & Images() const
void RemoveImage(const image_t image_id)
void SetConstantCamera(const camera_t camera_id)
void SetConstantPose(const image_t image_id)
const std::unordered_set< point3D_t > & ConstantPoints() const
bool HasPoint(const point3D_t point3D_id) const
void RemoveConstantTvec(const image_t image_id)
size_t NumConstantPoints() const
void AddImage(const image_t image_id)
size_t NumConstantCameras() const
void SetConstantTvec(const image_t image_id, const std::vector< int > &idxs)
void RemoveVariablePoint(const point3D_t point3D_id)
void AddConstantPoint(const point3D_t point3D_id)
size_t NumVariablePoints() const
bool HasConstantPoint(const point3D_t point3D_id) const
size_t NumResiduals(const Reconstruction &reconstruction) const
bool HasImage(const image_t image_id) const
RigBundleAdjuster(const BundleAdjustmentOptions &options, const Options &rig_options, const BundleAdjustmentConfig &config)
bool Solve(Reconstruction *reconstruction, std::vector< CameraRig > *camera_rigs)
void Solve(const Tensor &A, const Tensor &B, Tensor &X)
Solve AX = B with LU decomposition. A is a square matrix.
void PrintSolverSummary(const ceres::Solver::Summary &summary)
ceres::Solver::Options CreateSolverOptions(const BundleAdjustmentConfig &config, const ceres::Problem &problem) const
LossFunctionType loss_function_type
int min_num_images_gpu_solver
bool refine_principal_point
int max_num_images_direct_dense_cpu_solver
int max_num_images_direct_sparse_gpu_solver
int max_num_images_direct_dense_gpu_solver
double loss_function_scale
BundleAdjustmentOptions()
int min_num_residuals_for_cpu_multi_threading
ceres::Solver::Options solver_options
int max_num_images_direct_sparse_cpu_solver
ceres::LossFunction * CreateLossFunction() const
bool refine_relative_poses