CurvatureDirections.m 1.4 KB

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