Browse Source

key_down usages for all examples 200-406

Former-commit-id: 6a7c38b6dc4340c3da6ce5b6fca020122a85d758
Alec Jacobson 11 years ago
parent
commit
466530002c

+ 2 - 1
include/igl/viewer/TODOs.txt

@@ -1,4 +1,4 @@
-- depth test for overlays cannot be disabled
+- `align_and_center_object` continues to zoom out on repeated calls
 - data.lines, data.points should not concatenate colors with coordinates
 - snap to canonical recenters origin but trackball does not
 - rewrite in libigl style
@@ -28,3 +28,4 @@
 + fix all -Wunused-but-set-variable
 + makefile for libiglviewer.a
 + Viewer.h should include Viewer.cpp
++ depth test for overlays cannot be disabled

+ 6 - 4
include/igl/viewer/Viewer.cpp

@@ -505,7 +505,7 @@ namespace igl
     if (data.V_uv.rows() == 0)
       data.grid_texture();
 
-    core.align_camera_center(data.V);
+    core.align_camera_center(data.V,data.F);
 
     for (unsigned int i = 0; i<plugins.size(); ++i)
       if (plugins[i]->post_load())
@@ -839,7 +839,9 @@ namespace igl
   }
   void TW_CALL Viewer::align_camera_center_cb(void *clientData)
   {
-    static_cast<Viewer *>(clientData)->core.align_camera_center(static_cast<Viewer *>(clientData)->data.V);
+    static_cast<Viewer *>(clientData)->core.align_camera_center(
+      static_cast<Viewer *>(clientData)->data.V,
+      static_cast<Viewer *>(clientData)->data.F);
   }
 
   void TW_CALL Viewer::save_scene_cb(void *clientData)
@@ -897,13 +899,13 @@ namespace igl
 
   void Viewer::align_camera_center()
   {
-    core.align_camera_center(data.V);
+    core.align_camera_center(data.V,data.F);
   }
 
   void Viewer::set_mesh(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F)
   {
     data.set_mesh(V,F);
-    core.align_camera_center(V);
+    core.align_camera_center(V,F);
   }
 
   void Viewer::set_vertices(const Eigen::MatrixXd& V)

+ 11 - 3
include/igl/viewer/ViewerCore.cpp

@@ -8,6 +8,7 @@
 
 #include "ViewerCore.h"
 #include <igl/quat_to_mat.h>
+#include <igl/massmatrix.h>
 #include <Eigen/Geometry>
 
 
@@ -137,23 +138,30 @@ void igl::ViewerCore::InitSerialization()
   #endif
 }
 
-IGL_INLINE void igl::ViewerCore::align_camera_center(const Eigen::MatrixXd& V)
+IGL_INLINE void igl::ViewerCore::align_camera_center(
+  const Eigen::MatrixXd& V,
+  const Eigen::MatrixXi& F)
 {
-  get_scale_and_shift_to_fit_mesh(V,model_zoom,model_translation);
+  get_scale_and_shift_to_fit_mesh(V,F,model_zoom,model_translation);
   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,
+  const Eigen::MatrixXi& F,
   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  = (max_point.array() + min_point.array())/2;
+  Eigen::RowVector3d centroid  = 0.5*(min_point + max_point);
 
   shift = -centroid.cast<float>();
   double x_scale = fabs(max_point[0] - min_point[0]);

+ 4 - 1
include/igl/viewer/ViewerCore.h

@@ -41,12 +41,15 @@ public:
   // ------------------- Camera control functions
 
   // Adjust the view to see the entire model
-  IGL_INLINE void align_camera_center(const Eigen::MatrixXd& V);
+  IGL_INLINE void align_camera_center(
+    const Eigen::MatrixXd& V,
+    const Eigen::MatrixXi& F);
 
   // 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,
+    const Eigen::MatrixXi& F,
     float & zoom,
     Eigen::Vector3f& shift);
 

+ 6 - 1
tutorial/201_Normals/main.cpp

@@ -3,6 +3,7 @@
 #include <igl/per_vertex_normals.h>
 #include <igl/per_face_normals.h>
 #include <igl/per_corner_normals.h>
+#include <iostream>
 
 Eigen::MatrixXd V;
 Eigen::MatrixXi F;
@@ -50,6 +51,10 @@ int main(int argc, char *argv[])
   viewer.callback_key_down = &key_down;
   viewer.core.show_lines = false;
   viewer.set_mesh(V, F);
-  viewer.set_normals(N_vertices);
+  viewer.set_normals(N_faces);
+  std::cout<<
+    "Press '1' for per-face normals."<<std::endl<<
+    "Press '2' for per-vertex normals."<<std::endl<<
+    "Press '3' for per-corner normals."<<std::endl;
   viewer.launch();
 }

+ 4 - 4
tutorial/203_CurvatureDirections/main.cpp

@@ -49,12 +49,12 @@ int main(int argc, char *argv[])
   // Average edge length for sizing
   const double avg = igl::avg_edge_length(V,F);
 
-  // Draw a red segment parallel to the minimal curvature direction
+  // Draw a blue segment parallel to the minimal curvature direction
   const RowVector3d red(1,0,0),blue(0,0,1);
-  viewer.add_edges(V + PD1*avg, V - PD1*avg, red);
+  viewer.add_edges(V + PD1*avg, V - PD1*avg, blue);
 
-  // Draw a blue segment parallel to the maximal curvature direction
-  viewer.add_edges(V + PD2*avg, V - PD2*avg, blue);
+  // Draw a red segment parallel to the maximal curvature direction
+  viewer.add_edges(V + PD2*avg, V - PD2*avg, red);
 
   // Hide wireframe
   viewer.core.show_lines = false;

+ 1 - 0
tutorial/302_Sort/main.cpp

@@ -19,6 +19,7 @@ int main(int argc, char *argv[])
   MatrixXd BC,sorted_BC;
   igl::barycenter(V,F,BC);
   VectorXi I,J;
+  // sorted_BC = BC(I,:)
   igl::sortrows(BC,true,sorted_BC,I);
   // Get sorted "place" from sorted indices
   J.resize(I.rows());

+ 2 - 0
tutorial/304_LinearEqualityConstraints/main.cpp

@@ -91,5 +91,7 @@ int main(int argc, char *argv[])
       }
     };
   viewer.callback_key_down_data = &data;
+  cout<<
+    "Press [space] to toggle between unconstrained and constrained."<<endl;
   viewer.launch();
 }

+ 3 - 0
tutorial/305_QuadraticProgramming/main.cpp

@@ -89,6 +89,9 @@ int main(int argc, char *argv[])
   Aeq = M.diagonal().transpose().sparseView();
   // (Empty inequality constraints)
   solve(viewer);
+  cout<<
+    "Press '.' to increase scale and resolve."<<endl<<
+    "Press ',' to decrease scale and resolve."<<endl;
 
   viewer.launch();
 }

+ 3 - 0
tutorial/401_BiharmonicDeformation/main.cpp

@@ -117,5 +117,8 @@ int main(int argc, char *argv[])
   viewer.callback_key_down = &key_down;
   //viewer.core.is_animating = true;
   viewer.core.animation_max_fps = 30.;
+  cout<<
+    "Press [space] to toggle deformation."<<endl<<
+    "Press 'd' to toggle between biharmonic surface or displacements."<<endl;
   viewer.launch();
 }

+ 4 - 0
tutorial/402_PolyharmonicDeformation/main.cpp

@@ -101,5 +101,9 @@ int main(int argc, char *argv[])
   viewer.callback_key_down = &key_down;
   viewer.core.is_animating = true;
   viewer.core.animation_max_fps = 30.;
+  cout<<
+    "Press [space] to toggle animation."<<endl<<
+    "Press '.' to increase k."<<endl<<
+    "Press ',' to decrease k."<<endl;
   viewer.launch();
 }

+ 4 - 0
tutorial/403_BoundedBiharmonicWeights/main.cpp

@@ -156,5 +156,9 @@ int main(int argc, char *argv[])
   viewer.callback_key_down = &key_down;
   viewer.core.is_animating = false;
   viewer.core.animation_max_fps = 30.;
+  cout<<
+    "Press '.' to show next weight function."<<endl<<
+    "Press ',' to show previous weight function."<<endl<<
+    "Press [space] to toggle animation."<<endl;
   viewer.launch();
 }

+ 10 - 7
tutorial/406_FastAutomaticSkinningTransformations/main.cpp

@@ -147,6 +147,8 @@ int main(int argc, char *argv[])
   MatrixXd W;
   igl::readDMAT("../shared/armadillo-weights.dmat",W);
   igl::lbs_matrix_column(V,W,M);
+
+  // Cluster according to weights
   VectorXi G;
   {
     VectorXi S;
@@ -154,18 +156,14 @@ int main(int argc, char *argv[])
     igl::partition(W,50,G,S,D);
   }
 
-  // vertices in selection (in regions with weight = delta)
-  //Matrix<bool,Dynamic,1> S = W.array().rowwise().maxCoeff()==1;
-  //igl::colon<int>(0,V.rows()-1,b);
-  //b.conservativeResize(stable_partition( b.data(), b.data()+b.size(), 
-  // [&](int i)->bool{return S(i);})-b.data());
-
+  // vertices corresponding to handles (those with maximum weight)
   {
     VectorXd maxW;
     igl::mat_max(W,1,maxW,b);
   }
 
   // Precomputation for FAST
+  cout<<"Initializing Fast Automatic Skinning Transformations..."<<endl;
   // number of weights
   const int m = W.cols();
   Aeq.resize(m*3,m*3*(3+1));
@@ -190,9 +188,11 @@ int main(int argc, char *argv[])
   igl::columnize(Istack,m,2,L);
 
   // Precomputation for ARAP
+  cout<<"Initializing ARAP..."<<endl;
   arap_data.max_iter = 1;
   igl::arap_precomputation(V,F,V.cols(),b,arap_data);
   // Grouped arap
+  cout<<"Initializing ARAP with grouped edge-sets..."<<endl;
   arap_grouped_data.max_iter = 2;
   arap_grouped_data.G = G;
   igl::arap_precomputation(V,F,V.cols(),b,arap_grouped_data);
@@ -211,6 +211,9 @@ int main(int argc, char *argv[])
   viewer.core.is_animating = false;
   viewer.core.animation_max_fps = 30.;
   cout<<
-    "Press [space] to toggle animation"<<endl;
+    "Press [space] to toggle animation."<<endl<<
+    "Press '0' to reset pose."<<endl<<
+    "Press '.' to switch to next deformation method."<<endl<<
+    "Press ',' to switch to previous deformation method."<<endl;
   viewer.launch();
 }

+ 2 - 2
tutorial/506_FrameField/main.cpp

@@ -174,7 +174,7 @@ int main(int argc, char *argv[])
   using namespace Eigen;
 
   // Load a mesh in OBJ format
-  igl::readOBJ("../shared/cube.obj", V, F);
+  igl::readOBJ("../shared/bumpy-cube.obj", V, F);
 
   // Compute face barycenters
   igl::barycenter(V, F, B);
@@ -184,7 +184,7 @@ int main(int argc, char *argv[])
 
   // Load constraints
   MatrixXd temp;
-  igl::readDMAT("../shared/cube.dmat",temp);
+  igl::readDMAT("../shared/bumpy-cube.dmat",temp);
 
   b   = temp.block(0,0,temp.rows(),1).cast<int>();
   bc1 = temp.block(0,1,temp.rows(),3);

+ 1 - 1
tutorial/603_MEX/compileMEX.m

@@ -4,7 +4,7 @@ mex readOBJ_mex.cpp ...
     -I/opt/local/include/eigen3 %% Change this path to point to your copy of Eigen
 
 %% Load an OBJ mesh
-[V,F] = readOBJ_mex('../shared/cube.obj');
+[V,F] = readOBJ_mex('../shared/bumpy-cube.obj');
 
 %% Plot the mesh
 trimesh(F,V(:,1),V(:,2),V(:,3));

+ 0 - 0
tutorial/shared/cube.dmat.REMOVED.git-id → tutorial/shared/bumpy-cube.dmat.REMOVED.git-id


+ 0 - 0
tutorial/shared/cube.obj.REMOVED.git-id → tutorial/shared/bumpy-cube.obj.REMOVED.git-id


+ 1 - 1
tutorial/tutorial.md.REMOVED.git-id

@@ -1 +1 @@
-f9f3805758e1b5e3e93dcc985f565fc191fb1860
+4b911c4ac0915f2ccf0b1014b1c10ddc5f05d814