104_Colors.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 <[email protected]> and Daniele Panozzo <[email protected]>
  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. C = igl.eigen.MatrixXd()
  20. # Load a mesh in OFF format
  21. igl.readOFF(TUTORIAL_SHARED_PATH + "screwdriver.off", V, F)
  22. # Plot the mesh
  23. viewer = igl.glfw.Viewer()
  24. viewer.data().set_mesh(V, F)
  25. # Use the z coordinate as a scalar field over the surface
  26. Z = V.col(2)
  27. # Compute per-vertex colors
  28. igl.jet(Z, True, C)
  29. # Add per-vertex colors
  30. viewer.data().set_colors(C)
  31. # Launch the viewer
  32. viewer.launch()