main.cpp 1.2 KB

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