00001 #ifndef ICP_SVDICP_HPP
00002 #define ICP_SVDICP_HPP
00003
00004 #include <iostream>
00005 #include "jmath/jann.hpp"
00006 #include "jmath/jblas.hpp"
00007 #include "jmath/ublasExtra.hpp"
00008
00009 namespace jafar {
00010 namespace icp {
00011
00019 class SVDICP {
00020 private:
00022 double m_epsilon;
00024 double m_max_dist;
00026 int m_max_iter;
00028 unsigned int m_model_nb_points;
00030 unsigned int m_scene_nb_points;
00032 ublas::matrix<double> m_model_points;
00034 ublas::matrix<double> m_scene_points;
00036 jann::KD_tree_index< flann::L2<double> > *m_model_index;
00038 size_t m_K;
00039 jblas::mat R;
00040 jblas::vec T;
00041
00042
00043
00044
00045
00046
00047
00051 inline void barycenter(const jblas::mat&points, jblas::vec& center);
00052 public:
00053
00054 SVDICP(size_t max_nb_points = 1024, double epsilon = 1e-3, double max_dist = 5.,
00055
00056 int max_iter = 100) :
00057 m_K(1),
00058 m_epsilon(epsilon), m_max_dist(max_dist), m_max_iter(max_iter),
00059 m_model_nb_points(0), m_scene_nb_points(0) {}
00060
00061 SVDICP(const jblas::mat& model, jblas::mat& scene,
00062 double epsilon = 1e-3, double max_dist = 5.,
00063
00064 int max_iter = 100) :
00065 m_K(1),
00066 m_epsilon(epsilon), m_max_dist(max_dist), m_max_iter(max_iter),
00067 m_model_nb_points(model.size1()), m_scene_nb_points(scene.size1()),
00068 m_model_points(model), m_scene_points(scene)
00069 {
00070 JFR_ASSERT((scene.size2() == 3) && (scene.size2() == model.size2()),
00071
00072
00073 "points of model and scene must be of same dimension")
00074 }
00075
00076 ~SVDICP()
00077 {
00078 delete m_model_index;
00079 }
00080
00081 void add_model_entry(const jblas::vec& entry)
00082 {
00083 JFR_ASSERT(entry.size() == m_model_points.size2(),
00084 "entry must be of dimension " << m_model_points.size1())
00085 row(m_model_points,m_model_nb_points) = entry;
00086 m_model_nb_points++;
00087 }
00088
00089 void add_scene_entry(const jblas::vec3& entry)
00090 {
00091 JFR_ASSERT(entry.size() == m_scene_points.size2(),
00092 "entry must be of dimension "<<m_scene_points.size1())
00093 row(m_scene_points,m_scene_nb_points) = entry;
00094 m_scene_nb_points++;
00095 }
00096
00097 void compute_RT(const jblas::mat& model, const jblas::mat& scene,
00098 jblas::mat& R, jblas::vec& T);
00099
00100 void run();
00101 };
00102 }
00103 }
00104
00105 #endif