301_Slice.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. # 100 random indices into rows of F
  21. I = igl.eigen.MatrixXi()
  22. igl.floor((0.5 * (igl.eigen.MatrixXd.Random(100, 1) + 1.) * F.rows()), I)
  23. # 50 random indices into rows of I
  24. J = igl.eigen.MatrixXi()
  25. igl.floor((0.5 * (igl.eigen.MatrixXd.Random(50, 1) + 1.) * I.rows()), J)
  26. # K = I(J);
  27. K = igl.eigen.MatrixXi()
  28. igl.slice(I, J, K)
  29. # default green for all faces
  30. # C = p2e(np.array([[0.4,0.8,0.3]])).replicate(F.rows(),1)
  31. C = igl.eigen.MatrixXd([[0.4, 0.8, 0.3]]).replicate(F.rows(), 1)
  32. # Red for each in K
  33. R = igl.eigen.MatrixXd([[1.0, 0.3, 0.3]]).replicate(K.rows(), 1)
  34. # C(K,:) = R
  35. igl.slice_into(R, K, 1, C)
  36. # Plot the mesh with pseudocolors
  37. viewer = igl.glfw.Viewer()
  38. viewer.data().set_mesh(V, F)
  39. viewer.data().set_colors(C)
  40. viewer.launch()