302_Sort.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python
  2. #
  3. # This file is part of libigl, a simple c++ geometry processing library.
  4. #
  5. # Copyright (C) 2017 Sebastian Koch <s.koch@tu-berlin.de> and Daniele Panozzo <daniele.panozzo@gmail.com>
  6. #
  7. # This Source Code Form is subject to the terms of the Mozilla Public License
  8. # v. 2.0. If a copy of the MPL was not distributed with this file, You can
  9. # obtain one at http://mozilla.org/MPL/2.0/.
  10. import sys, os
  11. # Add the igl library to the modules search path
  12. sys.path.insert(0, os.getcwd() + "/../")
  13. import pyigl as igl
  14. from shared import TUTORIAL_SHARED_PATH, check_dependencies
  15. dependencies = ["glfw"]
  16. check_dependencies(dependencies)
  17. V = igl.eigen.MatrixXd()
  18. F = igl.eigen.MatrixXi()
  19. igl.readOFF(TUTORIAL_SHARED_PATH + "decimated-knight.off", V, F)
  20. # Sort barycenters lexicographically
  21. BC = igl.eigen.MatrixXd()
  22. sorted_BC = igl.eigen.MatrixXd()
  23. igl.barycenter(V, F, BC)
  24. I = igl.eigen.MatrixXi()
  25. J = igl.eigen.MatrixXi()
  26. # sorted_BC = BC(I,:)
  27. igl.sortrows(BC, True, sorted_BC, I)
  28. # Get sorted "place" from sorted indices
  29. J.resize(I.rows(), 1)
  30. # J(I) = 1:numel(I)
  31. igl.slice_into(igl.coloni(0, I.size() - 1), I, J)
  32. # Pseudo-color based on sorted place
  33. C = igl.eigen.MatrixXd()
  34. igl.jet(J.castdouble(), True, C)
  35. # Plot the mesh with pseudocolors
  36. viewer = igl.glfw.Viewer()
  37. viewer.data().set_mesh(V, F)
  38. viewer.data().set_colors(C)
  39. viewer.launch()