302_Sort.py 1.3 KB

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