Go to the documentation of this file.00001
00059
00060
00061
00062
00063
00064
00065
00066 #include <Eigen/SVD>
00067 #include <Eigen/LU>
00068 #include <Eigen/Dense>
00069
00070 namespace pcl {
00071
00072 RotationFromCorrespondences::RotationFromCorrespondences ()
00073 {
00074 reset();
00075 }
00076
00077 RotationFromCorrespondences::~RotationFromCorrespondences ()
00078 {
00079 }
00080
00081 inline void
00082 RotationFromCorrespondences::reset ()
00083 {
00084 no_of_samples_ = 0;
00085 accumulated_weight_ = 0.0;
00086 accumulated_weight2_=(0);
00087 covariance_.fill(0);
00088 var_.fill(0);
00089
00090 va_.fill(0);
00091 vb_.fill(0);
00092 vA_.fill(0);
00093 vB_.fill(0);
00094 }
00095
00096 Eigen::Vector3f elmwiseMul(const Eigen::Vector3f& n1, const Eigen::Vector3f& n2)
00097 {
00098 Eigen::Vector3f r;
00099 r(0)=n1(0)*std::abs(n2(0));
00100 r(1)=n1(1)*std::abs(n2(1));
00101 r(2)=n1(2)*std::abs(n2(2));
00102 return r;
00103 }
00104
00105 template<typename M>
00106 M elmwiseDiv(const M& n1, const M& n2)
00107 {
00108 M r;
00109 for(int x=0; x<n1.rows(); x++)
00110 for(int y=0; y<n1.cols(); y++)
00111 if(std::abs(n2(x,y))>0.0000001f) r(x,y)=n1(x,y)/n2(x,y);
00112 return r;
00113 }
00114
00115 Eigen::Vector3f elmwiseAbs(const Eigen::Vector3f& n1)
00116 {
00117 Eigen::Vector3f r;
00118 r(0)=std::abs(n1(0));
00119 r(1)=std::abs(n1(1));
00120 r(2)=std::abs(n1(2));
00121 return r;
00122 }
00123
00124 inline void
00125 RotationFromCorrespondences::add (const Eigen::Vector3f& point, const Eigen::Vector3f& corresponding_point,
00126 const Eigen::Vector3f& n1, const Eigen::Vector3f& n2,
00127 const Eigen::Vector3f& cn1, const Eigen::Vector3f& cn2,
00128 float weight, float weight2)
00129 {
00130 if (weight==0.0f)
00131 return;
00132
00133 ++no_of_samples_;
00134 accumulated_weight_ += weight;
00135
00136
00137 covariance_ += weight*(corresponding_point * point.transpose());
00138 var_ += weight*(corresponding_point * corresponding_point.transpose());
00139 static int i=0;
00140
00141
00142 accumulated_weight2_ += weight2;
00143
00144
00145
00146 va_ += weight*corresponding_point;
00147 vb_ += weight*point;
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 vA_ += weight2*corresponding_point;
00181 vB_ += weight2*point;
00182 ++i;
00183 }
00184
00185 inline Eigen::Matrix3f
00186 RotationFromCorrespondences::getTransformation ()
00187 {
00188
00189
00190
00191 std::cout<<"accumulated_weight_\n"<<accumulated_weight_<<"\n";
00192 std::cout<<"C:\n"<<covariance_<<"\n";
00193 std::cout<<"vA:\n"<<(vA_*vB_.transpose())<<"\n";
00194 std::cout<<"vB:\n"<<(va_*vB_.transpose())<<"\n";
00195 std::cout<<"A:\n"<<(vA_*vB_.transpose())*accumulated_weight_/(accumulated_weight2_*accumulated_weight2_)-((va_*vB_.transpose())+(vA_*vb_.transpose()))/accumulated_weight2_<<"\n";
00196 std::cout<<"ab:\n"<<(va_*vb_.transpose())/(accumulated_weight_)<<"\n";
00197
00198
00199 covariance_ -= (vA_*vB_.transpose())/(accumulated_weight2_);
00200
00201
00202 Eigen::JacobiSVD<Eigen::Matrix<float, 3, 3> > svd (covariance_, Eigen::ComputeFullU | Eigen::ComputeFullV);
00203 const Eigen::Matrix<float, 3, 3>& u = svd.matrixU(),
00204 & v = svd.matrixV();
00205
00206 std::cout<<"s:\n"<<svd.singularValues()<<"\n";
00207 std::cout<<"C:\n"<<covariance_<<"\n";
00208
00209 Eigen::Matrix<float, 3, 3> s;
00210 s.setIdentity();
00211 if (u.determinant()*v.determinant() < 0.0f)
00212 s(2,2) = -1.0f;
00213
00214 Eigen::Matrix<float, 3, 3> r = u * s * v.transpose();
00215
00216 return r;
00217 }
00218
00219 }