Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce right-hand-rule on PCA eigenvectors #2946

Merged
merged 2 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/include/pcl/common/impl/pca.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ pcl::PCA<PointT>::initCompute ()
eigenvalues_[i] = evd.eigenvalues () [2-i];
eigenvectors_.col (i) = evd.eigenvectors ().col (2-i);
}
// Enforce right hand rule
eigenvectors_.col(2) = eigenvectors_.col(0).cross(eigenvectors_.col(1));
// If not basis only then compute the coefficients
if (!basis_only_)
coefficients_ = eigenvectors_.transpose() * cloud_demean.topRows<3> ();
Expand Down
7 changes: 5 additions & 2 deletions common/include/pcl/common/pca.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ namespace pcl
/** Principal Component analysis (PCA) class.\n
* Principal components are extracted by singular values decomposition on the
* covariance matrix of the centered input cloud. Available data after pca computation
* are the mean of the input data, the eigenvalues (in descending order) and
* corresponding eigenvectors.\n
* are:\n
* - The Mean of the input data\n
* - The Eigenvectors: Ordered set of vectors representing the resultant principal components and the eigenspace cartesian basis (right-handed coordinate system).\n
* - The Eigenvalues: Eigenvectors correspondent loadings ordered in descending order.\n\n
* Other methods allow projection in the eigenspace, reconstruction from eigenspace and
* update of the eigenspace with a new datum (according Matej Artec, Matjaz Jogan and
* Ales Leonardis: "Incremental PCA for On-line Visual Learning and Recognition").
Expand Down Expand Up @@ -189,6 +191,7 @@ namespace pcl
}

/** Eigen Vectors accessor
* \return Column ordered eigenvectors, representing the eigenspace cartesian basis (right-handed coordinate system).
* \throw InitFailedException
*/
inline Eigen::Matrix3f&
Expand Down