00001 // This is core/vgl/algo/vgl_compute_similarity_3d.h 00002 #ifndef vgl_compute_similarity_3d_h_ 00003 #define vgl_compute_similarity_3d_h_ 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \brief Compute a similarity transformation between two corresponding sets of 3D points 00010 // \author Matt Leotta 00011 // \date April 7, 2010 00012 // 00013 // 00014 // Estimate scale \a s, translation \a t, and rotation \a R such that 00015 // sum ||s*R*p1 + t - p2|| is minimized over all pairs (p1,p2) 00016 // 00017 // \verbatim 00018 // Modifications 00019 // none 00020 // \endverbatim 00021 00022 #include <vcl_vector.h> 00023 #include <vgl/vgl_point_3d.h> 00024 #include <vgl/vgl_vector_3d.h> 00025 #include <vgl/algo/vgl_rotation_3d.h> 00026 00027 00028 template <class T> 00029 class vgl_compute_similarity_3d 00030 { 00031 public: 00032 00033 // Constructors/Initializers/Destructors------------------------------------- 00034 00035 vgl_compute_similarity_3d() {} 00036 00037 vgl_compute_similarity_3d(vcl_vector<vgl_point_3d<T> > const& points1, 00038 vcl_vector<vgl_point_3d<T> > const& points2); 00039 00040 ~vgl_compute_similarity_3d() {} 00041 00042 // Operations--------------------------------------------------------------- 00043 00044 //: add a pair of points to point sets 00045 void add_points(vgl_point_3d<T> const &p1, 00046 vgl_point_3d<T> const &p2); 00047 00048 //: clear internal data 00049 void clear(); 00050 00051 //: estimates the similarity transformation from the stored points 00052 bool estimate(); 00053 00054 // Data Access--------------------------------------------------------------- 00055 00056 //: Access the estimated rotation 00057 const vgl_rotation_3d<T>& rotation() const { return rotation_; } 00058 00059 //: Access the estimated translation 00060 const vgl_vector_3d<T>& translation() const { return translation_; } 00061 00062 //: Access he estimated scale 00063 T scale() const { return scale_; } 00064 00065 protected: 00066 // Internal functions-------------------------------------------------------- 00067 00068 //: center all the points at the origin, and return the applied translation 00069 void center_points(vcl_vector<vgl_point_3d<T> >& pts, 00070 vgl_vector_3d<T>& t) const; 00071 00072 //: normalize the scale of the points, and return the applied scale 00073 // The average distance from the origin will be sqrt(3) 00074 void scale_points(vcl_vector<vgl_point_3d<T> >& pts, 00075 T& s) const; 00076 00077 // Data Members-------------------------------------------------------------- 00078 vcl_vector<vgl_point_3d<T> > points1_; 00079 vcl_vector<vgl_point_3d<T> > points2_; 00080 T scale_; 00081 vgl_rotation_3d<T> rotation_; 00082 vgl_vector_3d<T> translation_; 00083 }; 00084 00085 #define VGL_COMPUTE_SIMILARITY_3D_INSTANTIATE(T) \ 00086 extern "please include vgl/algo/vgl_compute_similarity_3d.txx first" 00087 00088 #endif // vgl_compute_similarity_3d_h_