Skip to content
Snippets Groups Projects
Commit 0f632ec2 authored by Tariq Uake's avatar Tariq Uake
Browse files
parents c675bee3 cc41d3a1
No related branches found
No related tags found
No related merge requests found
......@@ -30,7 +30,47 @@ void Norma::translate(SurfaceMesh& mesh)
}
}
void Norma::pca(SurfaceMesh& mesh) {}
void Norma::pca(SurfaceMesh& mesh) {
unsigned int n_vertices = mesh.n_vertices();
MatrixXf input(3, n_vertices);
unsigned int i = 0;
for (auto v : mesh.vertices())
{
input.row(i)[0] = mesh.position(v)[0];
input.row(i)[1] = mesh.position(v)[1];
input.row(i++)[2] = mesh.position(v)[2];
}
VectorXf mean = input.rowwise().mean();
MatrixXf centered = input.colwise() - mean;
MatrixXf cov = centered * centered.adjoint();
cov = cov.array() / (input.rows() - 1);
SelfAdjointEigenSolver<MatrixXf> eig(cov);
VectorXf::Index maxv, minv;
float val = eig.eigenvalues().maxCoeff(&maxv);
eig.eigenvalues().minCoeff(&minv);
Matrix3f transfer;
transfer.col(0) = eig.eigenvectors().col(maxv);
transfer.col(2) = eig.eigenvectors().col(minv);
transfer.col(1) = transfer.col(0).cross(transfer.col(2));
/*Vector3f pos_temp;
for (auto v : mesh.vertices())
{
pos_temp[0] = mesh.position(v)[0];
pos_temp[1] = mesh.position(v)[1];
pos_temp[2] = mesh.position(v)[2];
pos_temp *= transfer;
pos_temp /= val;
mesh.position(v)[0] = pos_temp[0];
mesh.position(v)[1] = pos_temp[1];
mesh.position(v)[2] = pos_temp[2];
}*/
}
void Norma::flip(SurfaceMesh& mesh) {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment