example2.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. % Launch the external viewer
  2. launch_viewer;
  3. V = py.igl.eigen.MatrixXd();
  4. F = py.igl.eigen.MatrixXi();
  5. py.igl.read_triangle_mesh('../tutorial/shared/fertility.off', V, F);
  6. % Alternative discrete mean curvature
  7. HN = py.igl.eigen.MatrixXd();
  8. L = py.igl.eigen.SparseMatrixd();
  9. M = py.igl.eigen.SparseMatrixd();
  10. Minv = py.igl.eigen.SparseMatrixd();
  11. py.igl.cotmatrix(V,F,L);
  12. py.igl.massmatrix(V,F,py.igl.MASSMATRIX_TYPE_VORONOI,M);
  13. py.igl.invert_diag(M,Minv);
  14. % Laplace-Beltrami of position
  15. HN = -Minv*(L*V);
  16. % Extract magnitude as mean curvature
  17. H = HN.rowwiseNorm();
  18. % Compute curvature directions via quadric fitting
  19. PD1 = py.igl.eigen.MatrixXd();
  20. PD2 = py.igl.eigen.MatrixXd();
  21. PV1 = py.igl.eigen.MatrixXd();
  22. PV2 = py.igl.eigen.MatrixXd();
  23. py.igl.principal_curvature(V,F,PD1,PD2,PV1,PV2);
  24. % Mean curvature
  25. H = 0.5*(PV1+PV2);
  26. viewer = py.tcpviewer_single.TCPViewer();
  27. viewer.data.set_mesh(V, F);
  28. % Compute pseudocolor
  29. C = py.igl.eigen.MatrixXd();
  30. py.igl.parula(H,true,C);
  31. viewer.data.set_colors(C);
  32. % Average edge length for sizing
  33. avg = py.igl.avg_edge_length(V,F);
  34. % Draw a blue segment parallel to the minimal curvature direction
  35. red = m2p([0.8,0.2,0.2]);
  36. blue = m2p([0.2,0.2,0.8]);
  37. viewer.data.add_edges(V + PD1*avg, V - PD1*avg, blue);
  38. % Draw a red segment parallel to the maximal curvature direction
  39. viewer.data.add_edges(V + PD2*avg, V - PD2*avg, red);
  40. % Plot
  41. viewer.launch()