main.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <igl/floor.h>
  2. #include <igl/placeholders.h>
  3. #include <igl/readOFF.h>
  4. #include <igl/find.h>
  5. #include <igl/opengl/glfw/Viewer.h>
  6. #include <iostream>
  7. int main(int argc, char *argv[])
  8. {
  9. using namespace Eigen;
  10. using namespace std;
  11. MatrixXd V;
  12. MatrixXi F;
  13. igl::readOFF(TUTORIAL_SHARED_PATH "/decimated-knight.off",V,F);
  14. // 100 random indices into rows of F
  15. VectorXi I;
  16. igl::floor((0.5*(VectorXd::Random(100,1).array()+1.)*F.rows()).eval(),I);
  17. // 50 random indices into rows of I
  18. VectorXi J;
  19. igl::floor((0.5*(VectorXd::Random(50,1).array()+1.)*I.rows()).eval(),J);
  20. VectorXi K = I(J);
  21. // igl::slice(I,J,K); no longer needed
  22. // default green for all faces
  23. MatrixXd C = RowVector3d(0.4,0.8,0.3).replicate(F.rows(),1);
  24. // Red for each in K
  25. MatrixXd R = RowVector3d(1.0,0.3,0.3).replicate(K.rows(),1);
  26. // C(K,:) = R
  27. C(K,igl::placeholders::all) = R;
  28. // igl::slice_into(R,K,1,C); no longer needed
  29. Eigen::Array<bool,Eigen::Dynamic,1> W = Eigen::VectorXd::Random(F.rows()).array()>0.5;
  30. // Set 1/4 of the colors to blue
  31. MatrixXd B = RowVector3d(0.3,0.3,1.0).replicate(W.count(),1);
  32. C(igl::find(W),igl::placeholders::all) = B;
  33. // Plot the mesh with pseudocolors
  34. igl::opengl::glfw::Viewer viewer;
  35. viewer.data().set_mesh(V, F);
  36. viewer.data().set_colors(C);
  37. viewer.launch();
  38. }