203_CurvatureDirections.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. temp = igl.eigen.SparseMatrixd();
  15. temp = L*V
  16. HN = -Minv*(L*V);
  17. # Extract magnitude as mean curvature
  18. # VectorXd H = HN.rowwise().norm();
  19. #
  20. # // Compute curvature directions via quadric fitting
  21. # MatrixXd PD1,PD2;
  22. # VectorXd PV1,PV2;
  23. # igl::principal_curvature(V,F,PD1,PD2,PV1,PV2);
  24. # // mean curvature
  25. # H = 0.5*(PV1+PV2);
  26. #
  27. # igl::viewer::Viewer viewer;
  28. # viewer.data.set_mesh(V, F);
  29. #
  30. #
  31. # // Compute pseudocolor
  32. # MatrixXd C;
  33. # igl::parula(H,true,C);
  34. # viewer.data.set_colors(C);
  35. #
  36. # // Average edge length for sizing
  37. # const double avg = igl::avg_edge_length(V,F);
  38. #
  39. # // Draw a blue segment parallel to the minimal curvature direction
  40. # const RowVector3d red(0.8,0.2,0.2),blue(0.2,0.2,0.8);
  41. # viewer.data.add_edges(V + PD1*avg, V - PD1*avg, blue);
  42. #
  43. # // Draw a red segment parallel to the maximal curvature direction
  44. # viewer.data.add_edges(V + PD2*avg, V - PD2*avg, red);
  45. #
  46. # // Hide wireframe
  47. # viewer.core.show_lines = false;
  48. #
  49. # viewer.launch();
  50. # }