43 #include <Eigen/Dense> 48 template<
class MeshT >
49 void moveToCOG(MeshT& _mesh) {
52 for (
typename MeshT::VertexIter v_it = _mesh.vertices_begin(); v_it != _mesh.vertices_end(); ++v_it) {
53 mean += _mesh.point(*v_it);
56 mean /= (double)_mesh.n_vertices();
58 for (TriMesh::VertexIter v_it = _mesh.vertices_begin(); v_it != _mesh.vertices_end(); ++v_it) {
59 _mesh.set_point(*v_it, _mesh.point(*v_it) - mean);
64 template<
class MeshT >
65 void rotate(MeshT& _mesh) {
66 using namespace Eigen;
68 Matrix3Xd data = Matrix3Xd::Zero(3, _mesh.n_vertices());
70 for (
typename MeshT::VertexIter v_it = _mesh.vertices_begin(); v_it != _mesh.vertices_end(); ++v_it, ++i) {
72 data.col(i) = Vector3d(tmp[0], tmp[1], tmp[2]);
75 Matrix3d covar = (data * data.transpose()) / (
double)_mesh.n_vertices();
77 JacobiSVD<Matrix3d> svd(covar, ComputeFullU | ComputeFullV);
79 const Matrix3d& u = svd.matrixU();
81 Eigen::Vector3d v0 = u.col(0);
82 Eigen::Vector3d v1 = u.col(1);
83 Eigen::Vector3d v2 = v0.cross(v1);
94 Matrix3d invTrans = trans.inverse();
98 for (i = 0; i < 3; ++i) {
99 for (
size_t j = 0; j < 3; ++j) {
100 mat(i,j) = invTrans(i,j);
104 for (
typename MeshT::VertexIter v_it = _mesh.vertices_begin(); v_it != _mesh.vertices_end(); ++v_it, ++i) {
105 const ACG::Vec4d tmp(_mesh.point(*v_it)[0], _mesh.point(*v_it)[1], _mesh.point(*v_it)[2], 1.0);
108 _mesh.set_point(*v_it,
ACG::Vec3d(res[0], res[1],res[2]));
112 template<
class MeshT >
113 void moveCenterOfBBToOrigin(MeshT& _mesh) {
117 for (
typename MeshT::VertexIter v_it = _mesh.vertices_begin(); v_it != _mesh.vertices_end(); ++v_it) {
118 min.minimize(_mesh.point(*v_it));
119 max.maximize(_mesh.point(*v_it));
125 for (
typename MeshT::VertexIter v_it = _mesh.vertices_begin(); v_it != _mesh.vertices_end(); ++v_it) {
126 _mesh.point(*v_it) -= center;
void identity()
setup an identity matrix
void rotate(const ACG::Vec3d &_axis, const double _angle, const ACG::Vec3d &_center, int _viewer)
Rotate Scene around axis.