Browse Source

center around center of mass of faces (in case there are many unref verts)

Former-commit-id: ebdf2856f9c5604ab88269b6f4070c3463ccdd5f
Alec Jacobson 10 years ago
parent
commit
112ba7f809
1 changed files with 5 additions and 2 deletions
  1. 5 2
      include/igl/viewer/ViewerCore.cpp

+ 5 - 2
include/igl/viewer/ViewerCore.cpp

@@ -9,6 +9,7 @@
 #include "ViewerCore.h"
 #include <igl/quat_to_mat.h>
 #include <igl/massmatrix.h>
+#include <igl/barycenter.h>
 #include <Eigen/Geometry>
 #include <iostream>
 
@@ -191,8 +192,10 @@ IGL_INLINE void igl::ViewerCore::get_scale_and_shift_to_fit_mesh(
   //igl::massmatrix(V,F,igl::MASSMATRIX_TYPE_VORONOI,M);
   //const auto & MV = M*V;
   //Eigen::RowVector3d centroid  = MV.colwise().sum()/M.diagonal().sum();
-  Eigen::RowVector3d min_point = V.colwise().minCoeff();
-  Eigen::RowVector3d max_point = V.colwise().maxCoeff();
+  Eigen::MatrixXd BC;
+  igl::barycenter(V,F,BC);
+  Eigen::RowVector3d min_point = BC.colwise().minCoeff();
+  Eigen::RowVector3d max_point = BC.colwise().maxCoeff();
   Eigen::RowVector3d centroid  = 0.5*(min_point + max_point);
 
   shift = -centroid.cast<float>();