00001 // This is gel/mrc/vpgl/algo/vpgl_interpolate.h 00002 #ifndef vpgl_interpolate_h_ 00003 #define vpgl_interpolate_h_ 00004 //: 00005 // \file 00006 // \brief Methods for interpolating between cameras 00007 // \author J. L. Mundy 00008 // \date Dec 29, 2007 00009 // 00010 // \verbatim 00011 // Modifications 00012 // Jun 22, 2009 I. Eden Added the method: interpolate_next 00013 // \endverbatim 00014 00015 #include <vcl_vector.h> 00016 #include <vnl/vnl_double_3.h> 00017 #include <vnl/vnl_double_3x3.h> 00018 #include <vpgl/vpgl_perspective_camera.h> 00019 00020 class vpgl_interpolate 00021 { 00022 public: 00023 ~vpgl_interpolate(); 00024 00025 //: the log of a rotation matrix 00026 // 00027 // \verbatim 00028 // phi 00029 // log(R) = --------- (R - transpose(R)) 00030 // 2*sin(phi) 00031 // \endverbatim 00032 // 00033 // where 1 + 2*cos(phi) = Trace(R) 00034 // 00035 // 00036 static vnl_double_3x3 logR(vnl_double_3x3 const& R); 00037 00038 //: the exponential form of a rotation Lie algebra element 00039 // 00040 // \verbatim 00041 // sin(|r|) 1-cos(|r|) 00042 // exp(r) = I + --------- r ----------- r*r 00043 // |r| |r|*|r| 00044 // \endverbatim 00045 // 00046 // where r is a skew-symmetric matric matrix formed from a vector, v as, 00047 // \verbatim 00048 // _ _ 00049 // | 0 -vz vy | 00050 // r = | vz 0 -vx | ,and |r| = |v|. Note this norm is different from 00051 // | -vy vx 0 | the Frobenius norm of r as a 3x3 matrix. 00052 // - - 00053 // \endverbatim 00054 // 00055 static vnl_double_3x3 expr(vnl_double_3x3 const& r); 00056 00057 //: the "A" matrix in the exp operator for Special Euclidean 3-d (SE3) 00058 // Let r be as above. 00059 // Then 00060 // \verbatim 00061 // 1 - cos(|r|) |r| - sin(|r|) 00062 // A = I + ------------ r + -------------- r*r 00063 // |r|*|r| |r|*|r|*|r| 00064 // \endverbatim 00065 // 00066 static vnl_double_3x3 A(vnl_double_3x3 const& r); 00067 00068 //: the inverse A matrix for log operator on Special Euclidean 3-d (SE3) 00069 // Let r be as above. 00070 // Then 00071 // \verbatim 00072 // 1 2*sin(|r|)-|r|*(1+cos(|r|) 00073 // Ainv = I + - r + -------------------------- r*r 00074 // 2 2 |r|*|r|*sin(|r|) 00075 // \endverbatim 00076 // 00077 static vnl_double_3x3 Ainv(vnl_double_3x3 const& r); 00078 00079 //:Interpolate between two rotation matrices, R0 and R1 00080 // Lie group theory can be used to find a two-point interpolation of rotation 00081 // with respect to a parameter s, where 0<= s <=1 00082 // The solution is: 00083 // 00084 // R(s) = R0*exp(s r) 00085 // where r = log(transpose(R0).R1) 00086 // 00087 // for more details, see 00088 // F. C. Park, B. Ravani,"Smooth invariant interpolation of rotations," 00089 // ACM Transactions on Graphics, Vol. 16, No. 3, July 1997, pp. 277-295. 00090 // 00091 static vcl_vector<vnl_double_3x3> interpolateR(vnl_double_3x3 R0, 00092 vnl_double_3x3 R1, 00093 unsigned n_between); 00094 00095 //:Interpolate both R and t at the specified intervals 00096 static void interpolateRt(vnl_double_3x3 R0, 00097 vnl_double_3 t0, 00098 vnl_double_3x3 R1, 00099 vnl_double_3 t1, 00100 unsigned n_between, 00101 vcl_vector<vnl_double_3x3>& Rintrp, 00102 vcl_vector<vnl_double_3>& tintrp); 00103 00104 //:Interpolate between two perpspective cameras with the same K given that cam0 = K[R0|t0], cam1 = K[R1|t1] 00105 // The interpolation produces cameras on uniform intervals in Lie distance 00106 static bool interpolate(vpgl_perspective_camera<double> const& cam0, 00107 vpgl_perspective_camera<double> const& cam1, 00108 unsigned n_between, 00109 vcl_vector<vpgl_perspective_camera<double> >& cams); 00110 00111 //:Linearly interpolate (or extrapolate if abs(alpha) > 1) a rotation 00112 // Using the Lie algebra about R0, the interpolated rotation = R0 + alpha*(R1 - R0) 00113 static vnl_double_3x3 interpolateR(double alpha, vnl_double_3x3 R0, vnl_double_3x3 R1); 00114 00115 //:Interpolate the next perpspective camera with the same K given 00116 static bool interpolate_next(vpgl_perspective_camera<double> const& prev, 00117 vpgl_perspective_camera<double> const& curr, 00118 double const& rel_step_size, 00119 vpgl_perspective_camera<double>& next); 00120 00121 private: 00122 //: constructor private - static methods only 00123 vpgl_interpolate(); 00124 }; 00125 00126 #endif // vpgl_interpolate_h_
1.7.5.1