302_Sort.py 826 B

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