Browse Source

Merge pull request #1185 from txstc55/master

Added more comments to 407 and 604
Jérémie Dumas 6 years ago
parent
commit
8a448d4af4
2 changed files with 34 additions and 0 deletions
  1. 23 0
      tutorial/407_BiharmonicCoordinates/main.cpp
  2. 11 0
      tutorial/604_Triangle/main.cpp

+ 23 - 0
tutorial/407_BiharmonicCoordinates/main.cpp

@@ -33,6 +33,9 @@ int main(int argc, char * argv[])
   using namespace Eigen;
   using namespace std;
   using namespace igl;
+  
+  // read the mesh, if the code is prepared outside of tutorial, the TUTORIAL_SHARED_PATH
+  // should be the data folder
   if(!readMESH(TUTORIAL_SHARED_PATH "/octopus-low.mesh",low.V,low.T,low.F))
   {
     cout<<"failed to load mesh"<<endl;
@@ -46,25 +49,43 @@ int main(int argc, char * argv[])
   {
     Eigen::VectorXi b;
     {
+      // this will create a vector from 0 to V.rows()-1 where the gap is 1
       Eigen::VectorXi J = Eigen::VectorXi::LinSpaced(high.V.rows(),0,high.V.rows()-1);
       Eigen::VectorXd sqrD;
       Eigen::MatrixXd _2;
       cout<<"Finding closest points..."<<endl;
+      // using J which is N by 1 instead of a matrix that represents faces of N by 3
+      // so that we will find the closest vertices istead of closest point on the face
+      // so far the two meshes are not seperated. So what we are really doing here
+      // is computing handles from low resolution and use that for the high resolution one
       igl::point_mesh_squared_distance(low.V,high.V,J,sqrD,b,_2);
       assert(sqrD.minCoeff() < 1e-7 && "low.V should exist in high.V");
     }
     // force perfect positioning, rather have popping in low-res than high-res.
     // The correct/elaborate thing to do is express original low.V in terms of
     // linear interpolation (or extrapolation) via elements in (high.V,high.F)
+
+    // this is to replace the vertices on low resolution
+    // with the vertices in high resolution. b is the list of vertices
+    // corresponding to the indices in high resolution which has closest
+    // distance to the points in low resolution
     igl::slice(high.V,b,1,low.V);
+
+
     // list of points --> list of singleton lists
     std::vector<std::vector<int> > S;
+    // S will hav size of low.V.rows() and each list inside will have 1 element
     igl::matrix_to_list(b,S);
     cout<<"Computing weights for "<<b.size()<<
       " handles at "<<high.V.rows()<<" vertices..."<<endl;
     // Technically k should equal 3 for smooth interpolation in 3d, but 2 is
     // faster and looks OK
     const int k = 2;
+
+    // using all the points in low resolution as handles for the region
+    // it will be too expansive to use all the points in high reolution as handles
+    // but since low and high resembles the same thing, using points in low reesolution
+    // will give you similar performance
     igl::biharmonic_coordinates(high.V,high.T,S,k,W);
     cout<<"Reindexing..."<<endl;
     // Throw away interior tet-vertices, keep weights and indices of boundary
@@ -97,6 +118,7 @@ int main(int argc, char * argv[])
   Eigen::SparseMatrix<double> M;
   igl::massmatrix(low.V,low.T,igl::MASSMATRIX_TYPE_DEFAULT,M);
   const size_t n = low.V.rows();
+  // f = ma
   arap_data.f_ext =  M * RowVector3d(0,-9.8,0).replicate(n,1);
   // Random initial velocities to wiggle things
   arap_data.vel = MatrixXd::Random(n,3);
@@ -104,6 +126,7 @@ int main(int argc, char * argv[])
   igl::opengl::glfw::Viewer viewer;
   // Create one huge mesh containing both meshes
   igl::cat(1,low.U,high.U,scene.U);
+  // need to remap the indices since we cat the V matrices
   igl::cat(1,low.F,MatrixXi(high.F.array()+low.V.rows()),scene.F);
   // Color each mesh
   viewer.data().set_mesh(scene.U,scene.F);

+ 11 - 0
tutorial/604_Triangle/main.cpp

@@ -19,15 +19,26 @@ int main(int argc, char *argv[])
   E.resize(8,2);
   H.resize(1,2);
 
+  // create two squares, one with edge length of 4,
+  // one with edge length of 2
+  // both centered at origin
   V << -1,-1, 1,-1, 1,1, -1, 1,
        -2,-2, 2,-2, 2,2, -2, 2;
 
+  // add the edges of the squares
   E << 0,1, 1,2, 2,3, 3,0,
        4,5, 5,6, 6,7, 7,4;
 
+  // specify a point that is inside a closed shape
+  // where we do not want triangulation to happen
   H << 0,0;
 
   // Triangulate the interior
+  // a0.005 means that the area of each triangle should
+  // not be greater than 0.005
+  // q means that no angles will be smaller than 20 degrees
+  // for a detailed set of commands please refer to:
+  // https://www.cs.cmu.edu/~quake/triangle.switch.html
   igl::triangle::triangulate(V,E,H,"a0.005q",V2,F2);
 
   // Plot the generated mesh