00001
00002
00003 #ifndef _INCREMENTAL_BUNDLER_HPP
00004 #define _INCREMENTAL_BUNDLER_HPP
00005
00006 #include "geom/t3d.hpp"
00007 #include "geom/t3dPointTools.hpp"
00008 #include "geom/Declarations.hpp"
00009 #include "camera/cameraContainer.hpp"
00010 #include "bundler/view.hpp"
00011 #include "jmath/jblas.hpp"
00012 #include "jmath/vlls.hpp"
00013 #include <boost/tuple/tuple.hpp>
00014 #include <boost/tuple/tuple_io.hpp>
00015
00016 namespace jafar {
00017 namespace bundler {
00018
00028 class IncrementalBundler {
00029 private:
00031 std::map<int, jblas::mat34> m_projections;
00033 std::map<int, jblas::vec2> m_pixels;
00035 std::map<int, double> m_errors;
00037 jblas::vec3 m_solution;
00039 double error;
00041 jmath::VariableSizeLinearLeastSquares2 vlls;
00042
00043 public:
00045 IncrementalBundler() : vlls(4) {};
00046 ~IncrementalBundler();
00050 inline jblas::vec solve() {
00051 vlls.solve();
00052 JFR_DEBUG("vlls solution "<<vlls.x())
00053 return vlls.x();
00054 };
00056 inline jblas::vec3 solution() {
00057 jblas::vec homogenious = vlls.x();
00058 if(homogenious(3) != 1) {
00059 m_solution(0) = homogenious(0) / homogenious(3);
00060 m_solution(1) = homogenious(1) / homogenious(3);
00061 m_solution(2) = homogenious(2) / homogenious(3);
00062 } else {
00063 m_solution(0) = homogenious(0);
00064 m_solution(1) = homogenious(1);
00065 m_solution(2) = homogenious(2);
00066 }
00067 JFR_DEBUG("normalized solution "<<m_solution)
00068 return m_solution;
00069 };
00074 double reprojectionError();
00076 void addEntry(const jblas::vec2& pixel, const jblas::mat34& projection);
00078 void addEntry(int index, const jblas::vec2& pixel, const jblas::mat34& projection);
00080 void addProjection(const jblas::mat34& projection, const int& id);
00082 void addObservation(const jblas::vec2& pixel, const int& view);
00084 void fill();
00089 std::map<int, double>& errors() {
00090 return m_errors;
00091 };
00097 bool refine(const double& coef = 1.5, size_t minentries =3);
00105 double tune(const double& wish = 0.2,
00106 const double& coef = 1.5,
00107 size_t minentries = 3,
00108 int maxiter = 10);
00109
00110
00111
00112 inline int entries() const {
00113 return vlls.countMeasures()/2;
00114 }
00115
00116 inline std::pair<jblas::mat34, jblas::vec2> data(int viewId){
00117 JFR_PRECOND(m_projections.size()!=0 && m_pixels.size()!=0,
00118 "IncrementalBundler::data no data is saved!")
00119
00120 std::map<int, jblas::mat34>::const_iterator projection = m_projections.find(viewId);
00121 JFR_PRECOND(projection != m_projections.end(),
00122 "IncrementalBundler::data no projection data for this entry")
00123 std::map<int, jblas::vec2>::const_iterator pixel = m_pixels.find(viewId);
00124 JFR_PRECOND(pixel != m_pixels.end(),
00125 "IncrementalBundler::data no pixel data for this entry")
00126 std::pair<jblas::mat34, jblas::vec2> datum(projection->second, pixel->second);
00127 return datum;
00128 }
00129 };
00130
00131 }
00132
00133 }
00134
00135 #endif