瀏覽代碼

fixed bug in centering for 2d coordinates

Former-commit-id: 5ed1178fdd989f192496b0d4c9d72102c0ab6225
Daniele Panozzo 10 年之前
父節點
當前提交
51d28b322b
共有 2 個文件被更改,包括 18 次插入8 次删除
  1. 17 7
      include/igl/viewer/ViewerCore.cpp
  2. 1 1
      include/igl/viewer/ViewerData.cpp

+ 17 - 7
include/igl/viewer/ViewerCore.cpp

@@ -147,14 +147,24 @@ IGL_INLINE void igl::viewer::ViewerCore::get_scale_and_shift_to_fit_mesh(
   if (V.rows() == 0)
     return;
 
-  //Eigen::SparseMatrix<double> M;
-  //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::RowVector3d centroid  = 0.5*(min_point + max_point);
+  Eigen::RowVector3d min_point;
+  Eigen::RowVector3d max_point;
+  Eigen::RowVector3d centroid;
+
+  if (V.cols() == 3)
+  {
+    min_point = V.colwise().minCoeff();
+    max_point = V.colwise().maxCoeff();
+  }
+  else if (V.cols() == 2)
+  {
+    min_point << V.colwise().minCoeff(),0;
+    max_point << V.colwise().maxCoeff(),0;
+  }
+  else
+    return;
 
+  centroid = 0.5 * (min_point + max_point);
   shift = -centroid.cast<float>();
   double x_scale = fabs(max_point[0] - min_point[0]);
   double y_scale = fabs(max_point[1] - min_point[1]);

+ 1 - 1
include/igl/viewer/ViewerData.cpp

@@ -316,7 +316,7 @@ IGL_INLINE void igl::viewer::ViewerData::add_label(const Eigen::VectorXd& P,  co
   if (P.size() == 2)
   {
     P_temp = Eigen::RowVectorXd::Zero(3);
-    P_temp << P, 0;
+    P_temp << P.transpose(), 0;
   }
   else
     P_temp = P;