Explorar el Código

adapted align_camera_center and get_scale_and_shift_mesh to work with points only (so one can display point clouds)

Former-commit-id: 06f6073e8677e8accaf33cd992a9a7390d73044f
Olga Diamanti hace 10 años
padre
commit
ca55652110
Se han modificado 2 ficheros con 49 adiciones y 0 borrados
  1. 38 0
      include/igl/viewer/ViewerCore.cpp
  2. 11 0
      include/igl/viewer/ViewerCore.h

+ 38 - 0
include/igl/viewer/ViewerCore.cpp

@@ -125,6 +125,44 @@ IGL_INLINE void igl::ViewerCore::get_scale_and_shift_to_fit_mesh(
   zoom = 2.0 / std::max(z_scale,std::max(x_scale,y_scale));
 }
 
+IGL_INLINE void igl::ViewerCore::align_camera_center(
+                                                     const Eigen::MatrixXd& V)
+{
+  if(V.rows() == 0)
+    return;
+  
+  get_scale_and_shift_to_fit_mesh(V,model_zoom,model_translation);
+  // Rather than crash on empty mesh...
+  if(V.size() > 0)
+  {
+    object_scale = (V.colwise().maxCoeff() - V.colwise().minCoeff()).norm();
+  }
+}
+
+IGL_INLINE void igl::ViewerCore::get_scale_and_shift_to_fit_mesh(
+                                                                 const Eigen::MatrixXd& V,
+                                                                 float& zoom,
+                                                                 Eigen::Vector3f& shift)
+{
+  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);
+  
+  shift = -centroid.cast<float>();
+  double x_scale = fabs(max_point[0] - min_point[0]);
+  double y_scale = fabs(max_point[1] - min_point[1]);
+  double z_scale = fabs(max_point[2] - min_point[2]);
+  zoom = 2.0 / std::max(z_scale,std::max(x_scale,y_scale));
+}
+
+
 IGL_INLINE void igl::ViewerCore::clear_framebuffers()
 {
   glClearColor(background_color[0],

+ 11 - 0
include/igl/viewer/ViewerCore.h

@@ -51,6 +51,17 @@ public:
     float & zoom,
     Eigen::Vector3f& shift);
 
+    // Adjust the view to see the entire model
+    IGL_INLINE void align_camera_center(
+      const Eigen::MatrixXd& V);
+
+    // Determines how much to zoom and shift such that the mesh fills the unit
+    // box (centered at the origin)
+    IGL_INLINE void get_scale_and_shift_to_fit_mesh(
+      const Eigen::MatrixXd& V,
+      float & zoom,
+      Eigen::Vector3f& shift);
+
   // ------------------- Drawing functions
 
   // Clear the frame buffers