00001
00002
00003 #ifndef _VIEWS_MANAGER2_HPP
00004 #define _VIEWS_MANAGER2_HPP
00005
00006 #include "geom/t3d.hpp"
00007 #include "geom/t3dPointTools.hpp"
00008 #include "camera/cameraContainer.hpp"
00009 #include "jmath/jblas.hpp"
00010 #include "jmath/vlls.hpp"
00011 #include "jmath/ublasExtra.hpp"
00012 #include "kernel/jafarException.hpp"
00013 #include "bundler/bundlerException.hpp"
00014
00015 namespace jafar {
00016
00017 namespace bundler {
00018
00024 class ViewsManager2 {
00025 private:
00027 jafar::camera::CameraContainer container;
00029 jmath::VariableSizeLinearLeastSquares2 vlls;
00031 jblas::vec3 center;
00033 double error;
00035 std::map<size_t, geom::T3D*> references;
00037 std::map<size_t, jblas::vec2> pixels;
00038 size_t counter;
00039 bool saveData;
00040 geom::T3D* lastKnownLocation;
00041 bool one_camera;
00043 void computeReprojectionError();
00045 inline geom::T3D* refByIndex(size_t _index) const {
00046 std::map<size_t, geom::T3D*>::const_iterator it = references.find(_index);
00047 JFR_PRED_ERROR(it != references.end(),
00048 BundlerException,
00049 BundlerException::VIEWSMANAGER_POS_NOT_FOUND,
00050 "refByIndex: "<<_index<<" not found!")
00051 return it->second;
00052 }
00053
00054 public:
00060 ViewsManager2(bool save = false) :
00061 vlls(3), counter(0), saveData(save), lastKnownLocation(NULL), one_camera(false) {};
00070 ViewsManager2(const std::string& camCalibFile,
00071 jafar::camera::CameraType camType = jafar::camera::MONO,
00072 bool save = false) :
00073 vlls(3), counter(0), saveData(save), lastKnownLocation(NULL), one_camera(true)
00074 {
00075 setCamera(camType, camCalibFile);
00076 }
00085 ViewsManager2(const jblas::vec& camParams,
00086 camera::CameraType camType = jafar::camera::MONO,
00087 bool save = false) :
00088 vlls(3), counter(0), saveData(save), lastKnownLocation(NULL), one_camera(true)
00089 {
00090 setCamera(camType, camParams);
00091 }
00093 ~ViewsManager2();
00095 void setCamera(camera::CameraType camType, const std::string& camCalibFile);
00097 void setCamera(camera::CameraType camType, const jblas::vec& camParams);
00099 std::string camCalibFile() const;
00107 void insert(jblas::vec2 pixel, geom::T3D* ref, size_t index = -1,
00108 const camera::CameraContainer &thisContainer = camera::CameraContainer());
00114 void insertPixel(size_t index, const jblas::vec2& pixel,
00115 const camera::CameraContainer &container = camera::CameraContainer()) {
00116 JFR_PRED_ERROR(lastKnownLocation,
00117 BundlerException,
00118 BundlerException::VIEWSMANAGER_POS_NOT_FOUND,
00119 "last known frame is NULL")
00120 if(saveData)
00121 pixels[index] = pixel;
00122
00123 insert(pixel, lastKnownLocation, index, container);
00124 lastKnownLocation = NULL;
00125 }
00127 void insertReference(size_t index, geom::T3D* ref) {
00128 if(saveData)
00129 references[index] = ref;
00130 lastKnownLocation = ref;
00131 }
00133 void solve()
00134 {
00135 vlls.solve();
00136 center = vlls.x();
00137 };
00139 jblas::vec3 solution() const { return center; };
00141 double reprojectionError(){
00142 computeReprojectionError();
00143 return error;
00144 }
00145 };
00146
00147 }
00148
00149 }
00150
00151 #endif