00001 #ifndef ICP_OICP_HPP
00002 #define ICP_OICP_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
00021 class OICP {
00022 private:
00024 double m_epsilon;
00026 double m_max_dist;
00028 int m_max_iter;
00030 unsigned int m_model_nb_points;
00032 unsigned int m_scene_nb_points;
00034 ublas::matrix<double> m_model_points;
00036 ublas::matrix<double> m_scene_points;
00038 jann::KD_tree_index< flann::L2<double> > *m_model_index;
00040 size_t m_K;
00041 jblas::mat R;
00042 jblas::vec T;
00043
00047 inline void barycenter(const jblas::mat&points, jblas::vec& center);
00048 public:
00049
00050 OICP(size_t max_nb_points = 1024, double epsilon = 1e-4, double max_dist = 5.,
00051
00052 int max_iter = 100) :
00053 m_epsilon(epsilon), m_max_dist(max_dist), m_max_iter(max_iter), m_K(1),
00054 m_model_nb_points(0), m_scene_nb_points(0) {}
00055
00056 OICP(const jblas::mat& model, jblas::mat& scene,
00057 double epsilon = 1e-4, double max_dist = 5.,
00058
00059 int max_iter = 100) :
00060 m_epsilon(epsilon), m_max_dist(max_dist), m_max_iter(max_iter), m_K(1),
00061 m_model_nb_points(model.size1()), m_scene_nb_points(scene.size1()),
00062 m_model_points(model), m_scene_points(scene)
00063 {
00064 JFR_ASSERT(scene.size2() == model.size2(),
00065 "points of model and scene must be of same dimension")
00066 }
00067
00068 ~OICP()
00069 {
00070 delete m_model_index;
00071 }
00072
00073 void add_model_entry(const jblas::vec& entry)
00074 {
00075 JFR_ASSERT(entry.size() == m_model_points.size2(),
00076 "entry must be of dimension " << m_model_points.size2())
00077
00078
00079
00080
00081 row(m_model_points,m_model_nb_points) = entry;
00082 m_model_nb_points++;
00083 }
00084
00085 void add_scene_entry(const jblas::vec& entry)
00086 {
00087 JFR_ASSERT(entry.size() == m_scene_points.size2(),
00088 "entry must be of dimension " << m_scene_points.size2())
00089
00090
00091
00092
00093 row(m_scene_points,m_scene_nb_points) = entry;
00094 m_scene_nb_points++;
00095 }
00097 void compute_RT(const jblas::mat& model, const jblas::mat& scene,
00098 jblas::mat& R, jblas::vec& T);
00099 void run();
00100 };
00101 }
00102 }
00103
00104 #endif