vgl_compute_rigid_3d.h
Go to the documentation of this file.
1 // This is core/vgl/algo/vgl_compute_rigid_3d.h
2 #ifndef vgl_compute_rigid_3d_h_
3 #define vgl_compute_rigid_3d_h_
4 //:
5 // \file
6 // \brief Compute a rigid transformation between two corresponding sets of 3D points
7 // \author Matt Leotta, Dan Crispell
8 // \date April 15 2016
9 //
10 //
11 // Estimate translation \a t and rotation \a R such that
12 // sum ||R*p1 + t - p2|| is minimized over all pairs (p1,p2)
13 //
14 // \verbatim
15 // Modifications
16 // dec: Adapted from vgl_compute_similarity_3d
17 // \endverbatim
18 
19 #include <vector>
20 #ifdef _MSC_VER
21 # include <vcl_msvc_warnings.h>
22 #endif
23 #include <vgl/vgl_point_3d.h>
24 #include <vgl/vgl_vector_3d.h>
26 
27 
28 template <class T>
30 {
31  public:
32 
33  // Constructors/Initializers/Destructors-------------------------------------
34 
35  vgl_compute_rigid_3d() = default;
36 
37  vgl_compute_rigid_3d(std::vector<vgl_point_3d<T> > const& points1,
38  std::vector<vgl_point_3d<T> > const& points2);
39 
40  ~vgl_compute_rigid_3d() = default;
41 
42  // Operations---------------------------------------------------------------
43 
44  //: add a pair of points to point sets
45  void add_points(vgl_point_3d<T> const &p1,
46  vgl_point_3d<T> const &p2);
47 
48  //: clear internal data
49  void clear();
50 
51  //: estimates the rigid transformation from the stored points
52  bool estimate();
53 
54  // Data Access---------------------------------------------------------------
55 
56  //: Access the estimated rotation
57  const vgl_rotation_3d<T>& rotation() const { return rotation_; }
58 
59  //: Access the estimated translation
60  const vgl_vector_3d<T>& translation() const { return translation_; }
61 
62  protected:
63  // Internal functions--------------------------------------------------------
64 
65  //: center all the points at the origin, and return the applied translation
66  void center_points(std::vector<vgl_point_3d<T> >& pts,
67  vgl_vector_3d<T>& t) const;
68 
69  //: normalize the scale of the points, and return the applied scale
70  // The average distance from the origin will be sqrt(3)
71  void scale_points(std::vector<vgl_point_3d<T> >& pts,
72  T& s) const;
73 
74  // Data Members--------------------------------------------------------------
75  std::vector<vgl_point_3d<T> > points1_;
76  std::vector<vgl_point_3d<T> > points2_;
79 };
80 
81 #define VGL_COMPUTE_RIGID_3D_INSTANTIATE(T) \
82 extern "please include vgl/algo/vgl_compute_rigid_3d.hxx first"
83 
84 #endif // vgl_compute_rigid_3d_h_
void center_points(std::vector< vgl_point_3d< T > > &pts, vgl_vector_3d< T > &t) const
center all the points at the origin, and return the applied translation.
std::vector< vgl_point_3d< T > > points2_
vgl_compute_rigid_3d()=default
direction vector in Euclidean 3D space
const vgl_vector_3d< T > & translation() const
Access the estimated translation.
std::vector< vgl_point_3d< T > > points1_
void scale_points(std::vector< vgl_point_3d< T > > &pts, T &s) const
normalize the scale of the points, and return the applied scale.
a point in 3D nonhomogeneous space
vgl_vector_3d< T > translation_
A class representing a 3d rotation.
const vgl_rotation_3d< T > & rotation() const
Access the estimated rotation.
bool estimate()
estimates the rigid transformation from the stored points.
Direction vector in Euclidean 3D space, templated by type of element.
Definition: vgl_fwd.h:13
~vgl_compute_rigid_3d()=default
void add_points(vgl_point_3d< T > const &p1, vgl_point_3d< T > const &p2)
add a pair of points to point sets.
vgl_rotation_3d< T > rotation_
void clear()
clear internal data.