2 #ifndef vgl_compute_rigid_3d_hxx_ 3 #define vgl_compute_rigid_3d_hxx_ 10 #include <vnl/vnl_double_4.h> 11 #include <vnl/algo/vnl_svd.h> 12 #include <vnl/algo/vnl_determinant.h> 13 #include <vnl/vnl_matrix.h> 15 # include <vcl_msvc_warnings.h> 26 assert(points1.size() == points2.size());
33 points1_.push_back(p1);
34 points2_.push_back(p2);
54 for (
unsigned i=0; i<pts.size(); ++i)
59 for (
unsigned i=0; i<pts.size(); ++i)
75 for (
unsigned i=0; i<pts.size(); ++i)
77 s += (pts[i]-origin).
length();
79 s = std::sqrt(3.0)*pts.size()/s;
80 for (
unsigned i=0; i<pts.size(); ++i)
83 p.
set(p.
x()*s, p.
y()*s, p.
z()*s);
92 std::vector<vgl_point_3d<T> > pts1(points1_), pts2(points2_);
93 center_points(pts1, t1);
94 center_points(pts2, t2);
97 scale_points(pts2, s2);
99 for (
unsigned i=0; i<pts1.size(); ++i)
102 p.
set(p.
x()*s1, p.
y()*s1, p.
z()*s1);
106 vnl_matrix<T> M(3,3,0.0);
107 for (
unsigned i=0; i<pts1.size(); ++i)
111 M(0,0) += p1.
x()*p2.
x();
112 M(0,1) += p1.
x()*p2.
y();
113 M(0,2) += p1.
x()*p2.
z();
114 M(1,0) += p1.
y()*p2.
x();
115 M(1,1) += p1.
y()*p2.
y();
116 M(1,2) += p1.
y()*p2.
z();
117 M(2,0) += p1.
z()*p2.
x();
118 M(2,1) += p1.
z()*p2.
y();
119 M(2,2) += p1.
z()*p2.
z();
122 vnl_matrix<T> N(4,4);
123 N(0,0) = M(0,0) - M(1,1) - M(2,2);
124 N(1,1) = - M(0,0) + M(1,1) - M(2,2);
125 N(2,2) = - M(0,0) - M(1,1) + M(2,2);
126 N(3,3) = M(0,0) + M(1,1) + M(2,2);
127 N(0,1) = N(1,0) = M(0,1) + M(1,0);
128 N(0,2) = N(2,0) = M(2,0) + M(0,2);
129 N(1,2) = N(2,1) = M(1,2) + M(2,1);
130 N(3,0) = N(0,3) = M(1,2) - M(2,1);
131 N(3,1) = N(1,3) = M(2,0) - M(0,2);
132 N(3,2) = N(2,3) = M(0,1) - M(1,0);
135 vnl_double_4 q(svd.V().get_column(0));
137 translation_ = (rotation_*t1) - t2;
143 #undef VGL_COMPUTE_RIGID_3D_INSTANTIATE 144 #define VGL_COMPUTE_RIGID_3D_INSTANTIATE(T) \ 145 template class vgl_compute_rigid_3d<T > 147 #endif // vgl_compute_rigid_3d_hxx_ 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_rigid_3d()=default
double length(v const &a)
Return the length of a vector.
void scale_points(std::vector< vgl_point_3d< T > > &pts, T &s) const
normalize the scale of the points, and return the applied scale.
Compute a rigid transformation between two corresponding sets of 3D points.
bool estimate()
estimates the rigid transformation from the stored points.
Direction vector in Euclidean 3D space, templated by type of element.
void set(T vx, T vy, T vz)
Assignment.
void set(Type px, Type py, Type pz)
Set x, y and z.
void add_points(vgl_point_3d< T > const &p1, vgl_point_3d< T > const &p2)
add a pair of points to point sets.
void clear()
clear internal data.
The similarity transform that normalizes a 3-d point set.