vgl_compute_similarity_3d.h
Go to the documentation of this file.
1 // This is core/vgl/algo/vgl_compute_similarity_3d.h
2 #ifndef vgl_compute_similarity_3d_h_
3 #define vgl_compute_similarity_3d_h_
4 //:
5 // \file
6 // \brief Compute a similarity transformation between two corresponding sets of 3D points
7 // \author Matt Leotta
8 // \date April 7, 2010
9 //
10 //
11 // Estimate scale \a s, translation \a t, and rotation \a R such that
12 // sum ||s*R*p1 + t - p2|| is minimized over all pairs (p1,p2)
13 //
14 // \verbatim
15 // Modifications
16 // dec: Factored out rigid transform computation to vgl_compute_rigid_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_similarity_3d() = default;
36 
37  vgl_compute_similarity_3d(std::vector<vgl_point_3d<T> > const& points1,
38  std::vector<vgl_point_3d<T> > const& points2);
39 
40  ~vgl_compute_similarity_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 similarity 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  //: Access he estimated scale
63  T scale() const { return scale_; }
64 
65  protected:
66  // Internal functions--------------------------------------------------------
67 
68  //: center all the points at the origin, and return the applied translation
69  void center_points(std::vector<vgl_point_3d<T> >& pts,
70  vgl_vector_3d<T>& t) const;
71 
72  //: normalize the scale of the points, and return the applied scale
73  // The average distance from the origin will be sqrt(3)
74  void scale_points(std::vector<vgl_point_3d<T> >& pts,
75  T& s) const;
76 
77  // Data Members--------------------------------------------------------------
78  std::vector<vgl_point_3d<T> > points1_;
79  std::vector<vgl_point_3d<T> > points2_;
80  T scale_;
83 };
84 
85 #define VGL_COMPUTE_SIMILARITY_3D_INSTANTIATE(T) \
86 extern "please include vgl/algo/vgl_compute_similarity_3d.hxx first"
87 
88 #endif // vgl_compute_similarity_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.
~vgl_compute_similarity_3d()=default
const vgl_rotation_3d< T > & rotation() const
Access the estimated rotation.
direction vector in Euclidean 3D space
void add_points(vgl_point_3d< T > const &p1, vgl_point_3d< T > const &p2)
add a pair of points to point sets.
vgl_compute_similarity_3d()=default
bool estimate()
estimates the similarity transformation from the stored points.
a point in 3D nonhomogeneous space
A class representing a 3d rotation.
Direction vector in Euclidean 3D space, templated by type of element.
Definition: vgl_fwd.h:13
void clear()
clear internal data.
const vgl_vector_3d< T > & translation() const
Access the estimated translation.
std::vector< vgl_point_3d< T > > points1_
T scale() const
Access he estimated scale.
void scale_points(std::vector< vgl_point_3d< T > > &pts, T &s) const
normalize the scale of the points, and return the applied scale.
std::vector< vgl_point_3d< T > > points2_