203_CurvatureDirections.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import igl
  2. V = igl.eigen.MatrixXd();
  3. F = igl.eigen.MatrixXi();
  4. igl.read_triangle_mesh("../tutorial/shared/fertility.off", V, F);
  5. # Alternative discrete mean curvature
  6. HN = igl.eigen.MatrixXd();
  7. L = igl.eigen.SparseMatrixd();
  8. M = igl.eigen.SparseMatrixd();
  9. Minv = igl.eigen.SparseMatrixd();
  10. igl.cotmatrix(V,F,L);
  11. igl.massmatrix(V,F,igl.MASSMATRIX_TYPE_VORONOI,M);
  12. igl.invert_diag(M,Minv);
  13. # Laplace-Beltrami of position
  14. HN = -Minv*(L*V);
  15. # Extract magnitude as mean curvature
  16. H = HN.rowwiseNorm();
  17. # Compute curvature directions via quadric fitting
  18. PD1 = igl.eigen.MatrixXd()
  19. PD2 = igl.eigen.MatrixXd()
  20. PV1 = igl.eigen.VectorXd()
  21. PV2 = igl.eigen.VectorXd()
  22. igl.principal_curvature(V,F,PD1,PD2,PV1,PV2);
  23. # Mean curvature
  24. H = 0.5*(PV1+PV2);
  25. # igl::viewer::Viewer viewer;
  26. # viewer.data.set_mesh(V, F);
  27. #
  28. # Compute pseudocolor
  29. C = igl.eigen.MatrixXd();
  30. igl.parula(H,True,C);
  31. # viewer.data.set_colors(C);
  32. # Average edge length for sizing
  33. # const double avg = igl::avg_edge_length(V,F);
  34. #
  35. # // Draw a blue segment parallel to the minimal curvature direction
  36. # const RowVector3d red(0.8,0.2,0.2),blue(0.2,0.2,0.8);
  37. # viewer.data.add_edges(V + PD1*avg, V - PD1*avg, blue);
  38. #
  39. # // Draw a red segment parallel to the maximal curvature direction
  40. # viewer.data.add_edges(V + PD2*avg, V - PD2*avg, red);
  41. #
  42. # // Hide wireframe
  43. # viewer.core.show_lines = false;
  44. #
  45. # viewer.launch();
  46. # }