AliceVision
Photogrammetric Computer Vision Framework
ISolver.hpp
1 // This file is part of the AliceVision project.
2 // Copyright (c) 2019 AliceVision contributors.
3 // This Source Code Form is subject to the terms of the Mozilla Public License,
4 // v. 2.0. If a copy of the MPL was not distributed with this file,
5 // You can obtain one at https://mozilla.org/MPL/2.0/.
6 
7 #pragma once
8 
9 #include <aliceVision/numeric/numeric.hpp>
10 #include <aliceVision/numeric/Container.hpp>
11 
12 #include <vector>
13 
14 namespace aliceVision {
15 namespace robustEstimation {
16 
20 template<typename ModelT_>
21 class ISolver
22 {
23  public:
28  virtual std::size_t getMinimumNbRequiredSamples() const = 0;
29 
34  virtual std::size_t getMaximumNbModels() const = 0;
35 
42  virtual void solve(const Mat& x1, const Mat& x2, std::vector<ModelT_>& models) const = 0;
43 
51  virtual void solve(const Mat& x1, const Mat& x2, std::vector<ModelT_>& models, const std::vector<double>& weights) const = 0;
52 };
53 
57 template<typename ModelT_>
58 class UndefinedSolver : public ISolver<ModelT_>
59 {
60  public:
61  std::size_t getMinimumNbRequiredSamples() const override
62  {
63  throw std::runtime_error("Undefined solver used in kernel.");
64  return 0;
65  }
66 
67  std::size_t getMaximumNbModels() const override
68  {
69  throw std::runtime_error("Undefined solver used in kernel.");
70  return 0;
71  }
72 
73  void solve(const Mat& x1, const Mat& x2, std::vector<ModelT_>& models) const override
74  {
75  throw std::runtime_error("Undefined solver used in kernel.");
76  }
77 
78  void solve(const Mat& x1, const Mat& x2, std::vector<ModelT_>& models, const std::vector<double>& weights) const override
79  {
80  throw std::runtime_error("Undefined solver used in kernel.");
81  }
82 };
83 
87 template<typename MatrixT>
89 {
90  MatrixModel() = default;
91 
92  explicit MatrixModel(const MatrixT& matrix)
93  : _matrix(matrix)
94  {}
95 
96  inline const MatrixT& getMatrix() const { return _matrix; }
97 
98  inline MatrixT& getMatrix() { return _matrix; }
99 
100  inline void setMatrix(const MatrixT& matrix) { _matrix = matrix; }
101 
102  protected:
103  MatrixT _matrix{};
104 };
105 
110 
115 
116 } // namespace robustEstimation
117 } // namespace aliceVision
aliceVision::robustEstimation::ISolver::getMinimumNbRequiredSamples
virtual std::size_t getMinimumNbRequiredSamples() const =0
Return the minimum number of required samples.
aliceVision::robustEstimation::UndefinedSolver::solve
void solve(const Mat &x1, const Mat &x2, std::vector< ModelT_ > &models, const std::vector< double > &weights) const override
Solve the problem.
Definition: ISolver.hpp:78
aliceVision::robustEstimation::ISolver::solve
virtual void solve(const Mat &x1, const Mat &x2, std::vector< ModelT_ > &models) const =0
Solve the problem.
aliceVision
Definition: checkerDetector.cpp:32
aliceVision::robustEstimation::UndefinedSolver::solve
void solve(const Mat &x1, const Mat &x2, std::vector< ModelT_ > &models) const override
Solve the problem.
Definition: ISolver.hpp:73
aliceVision::robustEstimation::MatrixModel
Matrix based model to be used in a solver.
Definition: ISolver.hpp:88
aliceVision::robustEstimation::UndefinedSolver::getMinimumNbRequiredSamples
std::size_t getMinimumNbRequiredSamples() const override
Return the minimum number of required samples.
Definition: ISolver.hpp:61
aliceVision::robustEstimation::UndefinedSolver::getMaximumNbModels
std::size_t getMaximumNbModels() const override
Return the maximum number of models.
Definition: ISolver.hpp:67
aliceVision::robustEstimation::ISolver::getMaximumNbModels
virtual std::size_t getMaximumNbModels() const =0
Return the maximum number of models.
aliceVision::robustEstimation::ISolver
Generic solver interface.
Definition: ISolver.hpp:21
aliceVision::robustEstimation::UndefinedSolver
An Undefined Solver.
Definition: ISolver.hpp:58