Selaa lähdekoodia

Update ImGui menu + update tutorial.

Former-commit-id: b52e8fe1807f07a2c61acbc510c4962463d8adb0
Jérémie Dumas 7 vuotta sitten
vanhempi
commit
039ca104c2

+ 0 - 94
include/igl/opengl/glfw/TextRenderer.cpp

@@ -1,94 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2014 Wenzel Jacob <wenzel@inf.ethz.ch>
-//
-// This Source Code Form is subject to the terms of the Mozilla Public License
-// v. 2.0. If a copy of the MPL was not distributed with this file, You can
-// obtain one at http://mozilla.org/MPL/2.0/.
-#ifdef IGL_VIEWER_WITH_NANOGUI
-#include "TextRenderer.h"
-#include "TextRenderer_fonts.h"
-#include <igl/project.h>
-
-#include <nanogui/opengl.h>
-#include <nanovg.h>
-
-#include <Eigen/Dense>
-
-#define NANOVG_GL3
-#include <nanovg_gl.h>
-
-
-IGL_INLINE igl::opengl::glfw::TextRenderer::TextRenderer(): ctx(nullptr) {}
-
-IGL_INLINE int igl::opengl::glfw::TextRenderer::Init()
-{
-  using namespace std;
-  #ifdef NDEBUG
-    ctx = nvgCreateGL3(NVG_STENCIL_STROKES | NVG_ANTIALIAS);
-  #else
-    ctx = nvgCreateGL3(NVG_STENCIL_STROKES | NVG_ANTIALIAS | NVG_DEBUG);
-  #endif
-
-  nvgCreateFontMem(ctx, "sans", igl_roboto_regular_ttf,
-                             igl_roboto_regular_ttf_size, 0);
-
-  return 0;
-}
-
-IGL_INLINE int igl::opengl::glfw::TextRenderer::Shut()
-{
-  using namespace std;
-  if(ctx)
-    nvgDeleteGL3(ctx);
-  return 0;
-}
-
-IGL_INLINE void igl::opengl::glfw::TextRenderer::BeginDraw(
-  const Eigen::Matrix4f &view,
-  const Eigen::Matrix4f &proj,
-  const Eigen::Vector4f &_viewport,
-  float _object_scale)
-{
-  using namespace std;
-  viewport = _viewport;
-  proj_matrix = proj;
-  view_matrix = view;
-  object_scale = _object_scale;
-
-  Eigen::Vector2i mFBSize;
-  Eigen::Vector2i mSize;
-
-  GLFWwindow* mGLFWWindow = glfwGetCurrentContext();
-  glfwGetFramebufferSize(mGLFWWindow,&mFBSize[0],&mFBSize[1]);
-  glfwGetWindowSize(mGLFWWindow,&mSize[0],&mSize[1]);
-  glViewport(0,0,mFBSize[0],mFBSize[1]);
-
-  glClear(GL_STENCIL_BUFFER_BIT);
-
-  /* Calculate pixel ratio for hi-dpi devices. */
-  mPixelRatio = (float)mFBSize[0] / (float)mSize[0];
-  nvgBeginFrame(ctx,mSize[0],mSize[1],mPixelRatio);
-}
-
-IGL_INLINE void igl::opengl::glfw::TextRenderer::EndDraw()
-{
-  using namespace std;
-  nvgEndFrame(ctx);
-}
-
-IGL_INLINE void igl::opengl::glfw::TextRenderer::DrawText(
-  Eigen::Vector3d pos, Eigen::Vector3d normal, const std::string &text)
-{
-  using namespace std;
-  pos += normal * 0.005f * object_scale;
-  Eigen::Vector3f coord = igl::project(Eigen::Vector3f(pos(0), pos(1), pos(2)),
-      view_matrix, proj_matrix, viewport);
-
-  nvgFontSize(ctx, 16*mPixelRatio);
-  nvgFontFace(ctx, "sans");
-  nvgTextAlign(ctx, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
-  nvgFillColor(ctx, nvgRGBA(10,10,250,255));
-  nvgText(ctx, coord[0]/mPixelRatio, (viewport[3] - coord[1])/mPixelRatio, text.c_str(), NULL);
-}
-#endif

+ 0 - 59
include/igl/opengl/glfw/TextRenderer.h

@@ -1,59 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2014 Wenzel Jacob <wenzel@inf.ethz.ch>
-//
-// This Source Code Form is subject to the terms of the Mozilla Public License
-// v. 2.0. If a copy of the MPL was not distributed with this file, You can
-// obtain one at http://mozilla.org/MPL/2.0/.
-#ifndef IGL_OPENGL_GLFW_TEXT_RENDERER_H
-#define IGL_OPENGL_GLFW_TEXT_RENDERER_H
-#ifdef IGL_VIEWER_WITH_NANOGUI
-
-#include <Eigen/Dense>
-
-#include <igl/igl_inline.h>
-#include <map>
-
-struct NVGcontext;
-
-namespace igl
-{
-namespace opengl
-{
-namespace glfw
-{
-
-  class TextRenderer
-  {
-  public:
-    IGL_INLINE TextRenderer();
-
-    IGL_INLINE virtual int Init();
-    IGL_INLINE virtual int Shut();
-
-    IGL_INLINE void BeginDraw(const Eigen::Matrix4f &view,const Eigen::Matrix4f &proj,
-      const Eigen::Vector4f &_viewport,float _object_scale);
-
-    IGL_INLINE void EndDraw();
-
-    IGL_INLINE void DrawText(Eigen::Vector3d pos,Eigen::Vector3d normal,const std::string &text);
-
-  protected:
-    std::map<std::string,void *> m_textObjects;
-    Eigen::Matrix4f view_matrix,proj_matrix;
-    Eigen::Vector4f viewport;
-    float object_scale;
-    float mPixelRatio;
-    NVGcontext *ctx;
-  };
-
-}
-}
-}
-
-#ifndef IGL_STATIC_LIBRARY
-#  include "TextRenderer.cpp"
-#endif
-
-#endif
-#endif

+ 0 - 1
include/igl/opengl/glfw/TextRenderer_fonts.cpp.REMOVED.git-id

@@ -1 +0,0 @@
-36fdb5c0c44d1eebf7c30d970cf9577c01dfc509

+ 0 - 38
include/igl/opengl/glfw/TextRenderer_fonts.h

@@ -1,38 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2014 Wenzel Jacob <wenzel@inf.ethz.ch>
-//
-// This Source Code Form is subject to the terms of the Mozilla Public License
-// v. 2.0. If a copy of the MPL was not distributed with this file, You can
-// obtain one at http://mozilla.org/MPL/2.0/.
-
-#ifndef IGL_OPENGL_GLFW_TEXT_RENDERER_FONTS_H
-#define IGL_OPENGL_GLFW_TEXT_RENDERER_FONTS_H
-
-#include <stdint.h>
-
-#ifndef IGL_STATIC_LIBRARY
-namespace
-{
-#endif
-  extern uint8_t igl_entypo_ttf[];
-  extern uint32_t igl_entypo_ttf_size;
-
-  extern uint8_t igl_roboto_bold_ttf[];
-  extern uint32_t igl_roboto_bold_ttf_size;
-
-  extern uint8_t igl_roboto_regular_ttf[];
-  extern uint32_t igl_roboto_regular_ttf_size;
-
-#ifndef IGL_STATIC_LIBRARY
-}
-#endif
-
-#ifndef IGL_STATIC_LIBRARY
-namespace
-{
-  #include "TextRenderer_fonts.cpp"
-}
-#endif
-
-#endif

+ 12 - 6
include/igl/opengl/glfw/imgui/ImGuiMenu.cpp

@@ -143,6 +143,16 @@ IGL_INLINE void ImGuiMenu::draw_menu()
   draw_labels_window();
 
   // Viewer settings
+  if (callback_draw_viewer_window) { callback_draw_viewer_window(); }
+  else { draw_viewer_window(); }
+
+  // Other windows
+  if (callback_draw_custom_window) { callback_draw_custom_window(); }
+  else { draw_custom_window(); }
+}
+
+IGL_INLINE void ImGuiMenu::draw_viewer_window()
+{
   float menu_width = 180.f * menu_scaling();
   ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f), ImGuiSetCond_FirstUseEver);
   ImGui::SetNextWindowSize(ImVec2(0.0f, 0.0f), ImGuiSetCond_FirstUseEver);
@@ -154,14 +164,10 @@ IGL_INLINE void ImGuiMenu::draw_menu()
       | ImGuiWindowFlags_AlwaysAutoResize
   );
   ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.4f);
-  if (draw_viewer_menu_func) { draw_viewer_menu_func(); }
+  if (callback_draw_viewer_menu) { callback_draw_viewer_menu(); }
   else { draw_viewer_menu(); }
   ImGui::PopItemWidth();
   ImGui::End();
-
-  // Other windows
-  if (draw_custom_window_func) { draw_custom_window_func(); }
-  else { draw_custom_window(); }
 }
 
 IGL_INLINE void ImGuiMenu::draw_viewer_menu()
@@ -375,4 +381,4 @@ IGL_INLINE float ImGuiMenu::hidpi_scaling()
 } // end namespace
 } // end namespace
 } // end namespace
-} // end namespace
+} // end namespace

+ 8 - 2
include/igl/opengl/glfw/imgui/ImGuiMenu.h

@@ -71,13 +71,19 @@ public:
   // Draw menu
   IGL_INLINE virtual void draw_menu();
 
+  // Can be overwritten by `callback_draw_viewer_window`
+  IGL_INLINE virtual void draw_viewer_window();
+
+  // Can be overwritten by `callback_draw_viewer_menu`
   IGL_INLINE virtual void draw_viewer_menu();
 
+  // Can be overwritten by `callback_draw_custom_window`
   IGL_INLINE virtual void draw_custom_window() { }
 
   // Easy-to-customize callbacks
-  std::function<void(void)> draw_viewer_menu_func;
-  std::function<void(void)> draw_custom_window_func;
+  std::function<void(void)> callback_draw_viewer_window;
+  std::function<void(void)> callback_draw_viewer_menu;
+  std::function<void(void)> callback_draw_custom_window;
 
   IGL_INLINE void draw_labels_window();
 

+ 16 - 31
python/CMakeLists.txt

@@ -28,22 +28,22 @@ add_subdirectory(${PYBIND11_DIR} pybind11)
 
 ## include libigl
 option(LIBIGL_USE_STATIC_LIBRARY "Use LibIGL as static library" OFF)
-option(LIBIGL_WITH_OPENGL           "Use viewer"         ON)
-option(LIBIGL_WITH_OPENGL_GLFW      "Use GLFW"           ON)
-option(LIBIGL_WITH_NANOGUI          "Use Nanogui menu"   OFF)
-option(LIBIGL_WITH_CGAL             "Use CGAL"           OFF)
-option(LIBIGL_WITH_BOOLEAN          "Use Cork boolean"   OFF)
-option(LIBIGL_WITH_COMISO           "Use CoMiso"         ON)
-option(LIBIGL_WITH_EMBREE           "Use Embree"         ON)
-option(LIBIGL_WITH_LIM              "Use LIM"            ON)
-option(LIBIGL_WITH_MATLAB           "Use Matlab"         OFF)
-option(LIBIGL_WITH_MOSEK            "Use MOSEK"          OFF)
-option(LIBIGL_WITH_PNG              "Use PNG"            ON)
-option(LIBIGL_WITH_TETGEN           "Use Tetgen"         ON)
-option(LIBIGL_WITH_TRIANGLE         "Use Triangle"       ON)
-option(LIBIGL_WITH_XML              "Use XML"            ON)
-option(LIBIGL_WITH_PYTHON           "Use Python"         ON)
-option(LIBIGL_WITH_COPYLEFT         "Use Copyleft"       ON)
+option(LIBIGL_WITH_OPENGL            "Use viewer"         ON)
+option(LIBIGL_WITH_OPENGL_GLFW       "Use GLFW"           ON)
+option(LIBIGL_WITH_OPENGL_GLFW_IMGUI "Use ImGui"          OFF)
+option(LIBIGL_WITH_CGAL              "Use CGAL"           OFF)
+option(LIBIGL_WITH_BOOLEAN           "Use Cork boolean"   OFF)
+option(LIBIGL_WITH_COMISO            "Use CoMiso"         ON)
+option(LIBIGL_WITH_EMBREE            "Use Embree"         ON)
+option(LIBIGL_WITH_LIM               "Use LIM"            ON)
+option(LIBIGL_WITH_MATLAB            "Use Matlab"         OFF)
+option(LIBIGL_WITH_MOSEK             "Use MOSEK"          OFF)
+option(LIBIGL_WITH_PNG               "Use PNG"            ON)
+option(LIBIGL_WITH_TETGEN            "Use Tetgen"         ON)
+option(LIBIGL_WITH_TRIANGLE          "Use Triangle"       ON)
+option(LIBIGL_WITH_XML               "Use XML"            ON)
+option(LIBIGL_WITH_PYTHON            "Use Python"         ON)
+option(LIBIGL_WITH_COPYLEFT          "Use Copyleft"       ON)
 
 ## libigl
 if(NOT TARGET igl::core)
@@ -113,10 +113,6 @@ endif()
 set_target_properties(pyigl PROPERTIES PREFIX "")
 set_target_properties(pyigl PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR})
 
-# Copy the nanogui bindings
-#get_target_property(NANOGUI_LIB nanogui_python LOCATION)
-#file(COPY ${NANOGUI_LIB} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/../)
-
 if(WIN32)
   if(MSVC)
     # Enforce size-based optimization and link time code generation on MSVC (~30% smaller binaries in experiments)
@@ -175,14 +171,3 @@ elseif(UNIX)
   endif()
 endif()
 
-if(LIBIGL_WITH_PYTHON AND LIBIGL_WITH_NANOGUI)
-  # Copy the nanogui python lib after compilation
-  get_target_property(NANOGUI_LIB nanogui-python LOCATION)
-  add_custom_target(copy ALL)
-  add_custom_command(
-        TARGET copy
-        COMMAND ${CMAKE_COMMAND} -E copy ${NANOGUI_LIB} ${PROJECT_SOURCE_DIR}
-        )
-  add_dependencies(copy pyigl)
-
-endif()

+ 1 - 1
python/README.md

@@ -139,7 +139,7 @@ The python functions have exactly the same prototypes as their C++ counterpart.
 Docstrings for all available python functions are extracted from the C++ header files and compiled into the python module. To get help for a certain function, you can run `help(pyigl.<function_name>)` in the python console.
 
 In the scripts folder there is the script `generate_docstrings.py` that automatically generates python docstrings for a new function. You can run it with `generate_docstrings.py <path_to_cpp_header_files> <path_to_python_files>`. 
-The script depends on additional libraries (joblib, mako, clang), make sure to install them (e.g. through pip. python-clang is included in external/nanogui/ext/pybind11/tools/clang).
+The script depends on additional libraries (joblib, mako, clang), make sure to install them (e.g. through pip. python-clang is included in external/pybind11/tools/clang).
 
 
 ## Known Issues

+ 0 - 90
python/tutorial/106_ViewerMenu.py

@@ -1,90 +0,0 @@
-# This file is part of libigl, a simple c++ geometry processing library.
-#
-# Copyright (C) 2017 Sebastian Koch <s.koch@tu-berlin.de> and Daniele Panozzo <daniele.panozzo@gmail.com>
-#
-# This Source Code Form is subject to the terms of the Mozilla Public License
-# v. 2.0. If a copy of the MPL was not distributed with this file, You can
-# obtain one at http://mozilla.org/MPL/2.0/.
-# Add the igl library to the modules search path
-import sys, os
-sys.path.insert(0, os.getcwd() + "/../")
-
-import pyigl as igl
-import nanogui
-
-V1 = igl.eigen.MatrixXd()
-F1 = igl.eigen.MatrixXi()
-
-V2 = igl.eigen.MatrixXd()
-F2 = igl.eigen.MatrixXi()
-
-float_variable = 0.1
-bool_variable = True
-dir = 0
-
-
-def make_accessors(name):
-    def setter(value):
-        globals()[name] = value
-
-    def getter():
-        return globals()[name]
-    return setter, getter
-
-
-def viewer_init(viewer):
-    # add new group
-    viewer.ngui.addGroup("New Group")
-
-    # Expose the using general callback
-    viewer.ngui.addDoubleVariable("double", *make_accessors("float_variable"))
-
-    def setter(val):
-        global bool_variable
-        bool_variable = val
-
-    def getter():
-        global bool_variable
-        return bool_variable
-
-    # ... or using a custom callback
-    viewer.ngui.addBoolVariable("bool", setter, getter)
-
-    viewer.ngui.addEnumVariable("Direction", *make_accessors("dir")) \
-        .setItems(["Up", "Down", "Left", "Right"])
-
-    # Add a button
-    def cb():
-        print("Hello")
-    viewer.ngui.addButton("Print Hello", cb)
-
-    #Add an additional menu window
-    viewer.ngui.addWindow((220, 10), "New Window")
-
-    # add accessor
-    viewer.ngui.addDoubleVariable("double", *make_accessors("float_variable"))
-
-    #Generate menu
-    viewer.screen.performLayout()
-
-    return False
-
-
-
-def main():
-    # Load a mesh in OFF format
-    igl.readOFF("../../tutorial/shared/bunny.off", V1, F1)
-
-    # Init the viewer
-    viewer = igl.viewer.Viewer()
-
-    # Extend viewer menu
-    viewer.callback_init = viewer_init
-
-    # Plot the mesh
-    viewer.data.set_mesh(V1, F1)
-    viewer.launch()
-
-
-if __name__ == "__main__":
-    main()

+ 1 - 2
shared/cmake/libigl.cmake

@@ -22,10 +22,9 @@ option(LIBIGL_WITH_EMBREE            "Use Embree"         OFF)
 option(LIBIGL_WITH_LIM               "Use LIM"            ON)
 option(LIBIGL_WITH_MATLAB            "Use Matlab"         "${Matlab_FOUND}")
 option(LIBIGL_WITH_MOSEK             "Use MOSEK"          "${MOSEK_FOUND}")
-option(LIBIGL_WITH_NANOGUI           "Use Nanogui menu"   OFF)
 option(LIBIGL_WITH_OPENGL            "Use OpenGL"         "${OPENGL_FOUND}")
 option(LIBIGL_WITH_OPENGL_GLFW       "Use GLFW"           "${OPENGL_FOUND}")
-option(LIBIGL_WITH_OPENGL_GLFW_IMGUI "Use IMGUI"          OFF)
+option(LIBIGL_WITH_OPENGL_GLFW_IMGUI "Use ImGui"          OFF)
 option(LIBIGL_WITH_PNG               "Use PNG"            ON)
 option(LIBIGL_WITH_TETGEN            "Use Tetgen"         ON)
 option(LIBIGL_WITH_TRIANGLE          "Use Triangle"       ON)

+ 25 - 25
tutorial/106_ViewerMenu/main.cpp

@@ -6,14 +6,30 @@
 #include <iostream>
 #include "tutorial_shared_path.h"
 
-class CustomMenu : public igl::opengl::glfw::imgui::ImGuiMenu
+
+int main(int argc, char *argv[])
 {
+  Eigen::MatrixXd V;
+  Eigen::MatrixXi F;
+
+  // Load a mesh in OFF format
+  igl::readOFF(TUTORIAL_SHARED_PATH "/bunny.off", V, F);
+
+  // Init the viewer
+  igl::opengl::glfw::Viewer viewer;
+
+  // Attach a menu plugin
+  igl::opengl::glfw::imgui::ImGuiMenu menu;
+  viewer.plugins.push_back(&menu);
+
+  // Customize the menu
   float floatVariable = 0.1f; // Shared between two menus
 
-  virtual void draw_viewer_menu() override
+  // Add content to the default menu window
+  menu.callback_draw_viewer_menu = [&]()
   {
-    // Draw parent menu
-    ImGuiMenu::draw_viewer_menu();
+    // Draw parent menu content
+    menu.draw_viewer_menu();
 
     // Add new group
     if (ImGui::CollapsingHeader("New Group", ImGuiTreeNodeFlags_DefaultOpen))
@@ -58,12 +74,13 @@ class CustomMenu : public igl::opengl::glfw::imgui::ImGuiMenu
         std::cout << "Hello\n";
       }
     }
-  }
+  };
 
-  virtual void draw_custom_window() override
+  // Draw additional windows
+  menu.callback_draw_custom_window = [&]()
   {
     // Define next window position + size
-    ImGui::SetNextWindowPos(ImVec2(180.f * menu_scaling(), 10), ImGuiSetCond_FirstUseEver);
+    ImGui::SetNextWindowPos(ImVec2(180.f * menu.menu_scaling(), 10), ImGuiSetCond_FirstUseEver);
     ImGui::SetNextWindowSize(ImVec2(200, 160), ImGuiSetCond_FirstUseEver);
     ImGui::Begin(
         "New Window", nullptr,
@@ -79,24 +96,7 @@ class CustomMenu : public igl::opengl::glfw::imgui::ImGuiMenu
     ImGui::InputText("Name", str);
 
     ImGui::End();
-  }
-
-};
-
-int main(int argc, char *argv[])
-{
-  Eigen::MatrixXd V;
-  Eigen::MatrixXi F;
-
-  // Load a mesh in OFF format
-  igl::readOFF(TUTORIAL_SHARED_PATH "/bunny.off", V, F);
-
-  // Init the viewer
-  igl::opengl::glfw::Viewer viewer;
-
-  // Attach a custom menu
-  CustomMenu menu;
-  viewer.plugins.push_back(&menu);
+  };
 
   // Plot the mesh
   viewer.data().set_mesh(V, F);