301_Slice.py 1.5 KB

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