main.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include <igl/readOFF.h>
  2. #include <igl/opengl/glfw/Viewer.h>
  3. #include <igl/opengl/glfw/imgui/ImGuiPlugin.h>
  4. #include <igl/opengl/glfw/imgui/ImGuiMenu.h>
  5. #include <igl/opengl/glfw/imgui/ImGuiHelpers.h>
  6. #include <iostream>
  7. int main(int argc, char *argv[])
  8. {
  9. Eigen::MatrixXd V;
  10. Eigen::MatrixXi F;
  11. // Load a mesh in OFF format
  12. igl::readOFF(TUTORIAL_SHARED_PATH "/bunny.off", V, F);
  13. // Init the viewer
  14. igl::opengl::glfw::Viewer viewer;
  15. // Attach a menu plugin
  16. igl::opengl::glfw::imgui::ImGuiPlugin plugin;
  17. viewer.plugins.push_back(&plugin);
  18. igl::opengl::glfw::imgui::ImGuiMenu menu;
  19. plugin.widgets.push_back(&menu);
  20. // Customize the menu
  21. double doubleVariable = 0.1f; // Shared between two menus
  22. // Add content to the default menu window
  23. menu.callback_draw_viewer_menu = [&]()
  24. {
  25. // Draw parent menu content
  26. menu.draw_viewer_menu();
  27. // Add new group
  28. if (ImGui::CollapsingHeader("New Group", ImGuiTreeNodeFlags_DefaultOpen))
  29. {
  30. // Expose variable directly ...
  31. ImGui::InputDouble("double", &doubleVariable, 0, 0, "%.4f");
  32. // ... or using a custom callback
  33. static bool boolVariable = true;
  34. if (ImGui::Checkbox("bool", &boolVariable))
  35. {
  36. // do something
  37. std::cout << "boolVariable: " << std::boolalpha << boolVariable << std::endl;
  38. }
  39. // Expose an enumeration type
  40. enum Orientation { Up=0, Down, Left, Right };
  41. static Orientation dir = Up;
  42. ImGui::Combo("Direction", (int *)(&dir), "Up\0Down\0Left\0Right\0\0");
  43. // We can also use a std::vector<std::string> defined dynamically
  44. static int num_choices = 3;
  45. static std::vector<std::string> choices;
  46. static int idx_choice = 0;
  47. if (ImGui::InputInt("Num letters", &num_choices))
  48. {
  49. num_choices = std::max(1, std::min(26, num_choices));
  50. }
  51. if (num_choices != (int) choices.size())
  52. {
  53. choices.resize(num_choices);
  54. for (int i = 0; i < num_choices; ++i)
  55. choices[i] = std::string(1, 'A' + i);
  56. if (idx_choice >= num_choices)
  57. idx_choice = num_choices - 1;
  58. }
  59. ImGui::Combo("Letter", &idx_choice, choices);
  60. // Add a button
  61. if (ImGui::Button("Print Hello", ImVec2(-1,0)))
  62. {
  63. std::cout << "Hello\n";
  64. }
  65. }
  66. };
  67. // Draw additional windows
  68. menu.callback_draw_custom_window = [&]()
  69. {
  70. // Define next window position + size
  71. ImGui::SetNextWindowPos(ImVec2(180.f * menu.menu_scaling(), 10), ImGuiCond_FirstUseEver);
  72. ImGui::SetNextWindowSize(ImVec2(200, 160), ImGuiCond_FirstUseEver);
  73. ImGui::Begin(
  74. "New Window", nullptr,
  75. ImGuiWindowFlags_NoSavedSettings
  76. );
  77. // Expose the same variable directly ...
  78. ImGui::PushItemWidth(-80);
  79. ImGui::DragScalar("double", ImGuiDataType_Double, &doubleVariable, 0.1, 0, 0, "%.4f");
  80. ImGui::PopItemWidth();
  81. static std::string str = "bunny";
  82. ImGui::InputText("Name", str);
  83. ImGui::End();
  84. };
  85. // Plot the mesh
  86. viewer.data().set_mesh(V, F);
  87. viewer.data().add_label(viewer.data().V.row(0) + viewer.data().V_normals.row(0).normalized()*0.005, "Hello World!");
  88. viewer.launch();
  89. }