302_Sort.py 708 B

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