301_Slice.py 852 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. from __future__ import print_function
  2. import igl
  3. from iglhelpers import *
  4. V = igl.eigen.MatrixXd()
  5. F = igl.eigen.MatrixXi()
  6. igl.readOFF("../tutorial/shared/decimated-knight.off",V,F)
  7. temp = igl.eigen.MatrixXd()
  8. # 100 random indicies into rows of F
  9. temp.setRandom(100,1)
  10. I = igl.eigen.MatrixXi()
  11. igl.floor((0.5*(temp+1.)*F.rows()),I);
  12. # 50 random indicies into rows of I
  13. temp.setRandom(50,1)
  14. J = igl.eigen.MatrixXi()
  15. igl.floor((0.5*(temp+1.)*I.rows()),J)
  16. # K = I(J);
  17. K = igl.eigen.MatrixXi()
  18. igl.slice(I,J,K)
  19. # default green for all faces
  20. C = p2e(np.array([[0.4,0.8,0.3]])).replicate(F.rows(),1)
  21. # Red for each in K
  22. R = p2e(np.array([[1.0,0.3,0.3]])).replicate(K.rows(),1)
  23. # C(K,:) = R
  24. igl.slice_into(R,K,1,C)
  25. # Plot the mesh with pseudocolors
  26. viewer = igl.viewer.Viewer()
  27. viewer.data.set_mesh(V, F)
  28. viewer.data.set_colors(C)
  29. viewer.launch()