main.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <igl/readOFF.h>
  2. #include <igl/viewer/Viewer.h>
  3. #include <nanogui/formhelper.h>
  4. #include <nanogui/screen.h>
  5. #include <iostream>
  6. #include "tutorial_shared_path.h"
  7. int main(int argc, char *argv[])
  8. {
  9. Eigen::MatrixXd V;
  10. Eigen::MatrixXi F;
  11. bool boolVariable = true;
  12. float floatVariable = 0.1f;
  13. enum Orientation { Up=0,Down,Left,Right } dir = Up;
  14. // Load a mesh in OFF format
  15. igl::readOFF(TUTORIAL_SHARED_PATH "/bunny.off", V, F);
  16. // Init the viewer
  17. igl::viewer::Viewer viewer;
  18. // Extend viewer menu
  19. viewer.callback_init = [&](igl::viewer::Viewer& viewer)
  20. {
  21. // Add new group
  22. viewer.ngui->addGroup("New Group");
  23. // Expose variable directly ...
  24. viewer.ngui->addVariable("float",floatVariable);
  25. // ... or using a custom callback
  26. viewer.ngui->addVariable<bool>("bool",[&](bool val) {
  27. boolVariable = val; // set
  28. },[&]() {
  29. return boolVariable; // get
  30. });
  31. // Expose an enumaration type
  32. viewer.ngui->addVariable<Orientation>("Direction",dir)->setItems({"Up","Down","Left","Right"});
  33. // Add a button
  34. viewer.ngui->addButton("Print Hello",[](){ std::cout << "Hello\n"; });
  35. // Add an additional menu window
  36. viewer.ngui->addWindow(Eigen::Vector2i(220,10),"New Window");
  37. // Expose the same variable directly ...
  38. viewer.ngui->addVariable("float",floatVariable);
  39. // Generate menu
  40. viewer.screen->performLayout();
  41. return false;
  42. };
  43. // Plot the mesh
  44. viewer.data.set_mesh(V, F);
  45. viewer.launch();
  46. }