302_Sort.py 963 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import sys, os
  2. # Add the igl library to the modules search path
  3. sys.path.insert(0, os.getcwd() + "/../")
  4. import pyigl as igl
  5. from shared import TUTORIAL_SHARED_PATH, check_dependencies
  6. dependencies = ["viewer"]
  7. check_dependencies(dependencies)
  8. V = igl.eigen.MatrixXd()
  9. F = igl.eigen.MatrixXi()
  10. igl.readOFF(TUTORIAL_SHARED_PATH + "decimated-knight.off", V, F)
  11. # Sort barycenters lexicographically
  12. BC = igl.eigen.MatrixXd()
  13. sorted_BC = igl.eigen.MatrixXd()
  14. igl.barycenter(V, F, BC)
  15. I = igl.eigen.MatrixXi()
  16. J = igl.eigen.MatrixXi()
  17. # sorted_BC = BC(I,:)
  18. igl.sortrows(BC, True, sorted_BC, I)
  19. # Get sorted "place" from sorted indices
  20. J.resize(I.rows(), 1)
  21. # J(I) = 1:numel(I)
  22. igl.slice_into(igl.coloni(0, I.size() - 1), I, J)
  23. # Pseudo-color based on sorted place
  24. C = igl.eigen.MatrixXd()
  25. igl.jet(J.castdouble(), True, C)
  26. # Plot the mesh with pseudocolors
  27. viewer = igl.viewer.Viewer()
  28. viewer.data.set_mesh(V, F)
  29. viewer.data.set_colors(C)
  30. viewer.launch()