40 #include <pcl/common/eigen.h>
41 #include <pcl/common/vector_average.h>
43 #include <Eigen/Eigenvalues>
47 template <
typename real,
int dimension>
53 template <
typename real,
int dimension>
57 accumulatedWeight_ = 0.0;
62 template <
typename real,
int dimension>
68 accumulatedWeight_ += weight;
69 real alpha = weight/accumulatedWeight_;
71 Eigen::Matrix<real, dimension, 1> diff = sample - mean_;
72 covariance_ = (covariance_ + (diff * diff.transpose())*alpha)*(1.0f-alpha);
74 mean_ += (diff)*alpha;
83 template <
typename real,
int dimension>
85 Eigen::Matrix<real, dimension, 1>& eigen_vector2, Eigen::Matrix<real, dimension, 1>& eigen_vector3)
const
98 Eigen::SelfAdjointEigenSolver<Eigen::Matrix<real, dimension, dimension> > ei_symm(covariance_);
99 eigen_values = ei_symm.eigenvalues();
100 Eigen::Matrix<real, dimension, dimension> eigen_vectors = ei_symm.eigenvectors();
102 eigen_vector1 = eigen_vectors.col(0);
103 eigen_vector2 = eigen_vectors.col(1);
104 eigen_vector3 = eigen_vectors.col(2);
107 template <
typename real,
int dimension>
116 Eigen::SelfAdjointEigenSolver<Eigen::Matrix<real, dimension, dimension> > ei_symm(covariance_,
false);
117 eigen_values = ei_symm.eigenvalues();
120 template <
typename real,
int dimension>
134 Eigen::SelfAdjointEigenSolver<Eigen::Matrix<real, dimension, dimension> > ei_symm(covariance_);
135 Eigen::Matrix<real, dimension, dimension> eigen_vectors = ei_symm.eigenvectors();
136 eigen_vector1 = eigen_vectors.col(0);
148 Eigen::Matrix<float, 3, 1>& eigen_vector2, Eigen::Matrix<float, 3, 1>& eigen_vector3)
const
151 Eigen::Matrix<float, 3, 3> eigen_vectors;
152 eigen33(covariance_, eigen_vectors, eigen_values);
153 eigen_vector1 = eigen_vectors.col(0);
154 eigen_vector2 = eigen_vectors.col(1);
155 eigen_vector3 = eigen_vectors.col(2);
167 Eigen::Vector3f::Scalar eigen_value;
168 Eigen::Vector3f eigen_vector;
169 eigen33(covariance_, eigen_value, eigen_vector);
170 eigen_vector1 = eigen_vector;
178 Eigen::Matrix<double, 3, 1>& eigen_vector2, Eigen::Matrix<double, 3, 1>& eigen_vector3)
const
181 Eigen::Matrix<double, 3, 3> eigen_vectors;
182 eigen33(covariance_, eigen_vectors, eigen_values);
183 eigen_vector1 = eigen_vectors.col(0);
184 eigen_vector2 = eigen_vectors.col(1);
185 eigen_vector3 = eigen_vectors.col(2);
197 Eigen::Vector3d::Scalar eigen_value;
198 Eigen::Vector3d eigen_vector;
199 eigen33(covariance_, eigen_value, eigen_vector);
200 eigen_vector1 = eigen_vector;
void add(const VectorType &sample, real weight=1.0)
Add a new sample.
void reset()
Reset the object to work with a new data set.
VectorAverage()
Constructor - dimension gives the size of the vectors to work with.
void doPCA(VectorType &eigen_values, VectorType &eigen_vector1, VectorType &eigen_vector2, VectorType &eigen_vector3) const
Do Principal component analysis.
void getEigenVector1(VectorType &eigen_vector1) const
Get the eigenvector corresponding to the smallest eigenvalue.
void eigen33(const Matrix &mat, typename Matrix::Scalar &eigenvalue, Vector &eigenvector)
determines the eigenvector and eigenvalue of the smallest eigenvalue of the symmetric positive semi d...
void computeRoots(const Matrix &m, Roots &roots)
computes the roots of the characteristic polynomial of the input matrix m, which are the eigenvalues