Browse Source

Merge branch 'master' of github.com:libigl/libigl

Former-commit-id: c0430763a7f683509482608c37447508e8646d89
Alec Jacobson 11 years ago
parent
commit
dfaa9b42f9

+ 20 - 11
include/igl/viewer/Viewer.cpp

@@ -185,14 +185,14 @@ Eigen::Matrix4f translate(
 #include <igl/snap_to_canonical_view_quat.h>
 #include <TwOpenGLCore.h>
 
-// This is needed for glfw event handling
-
-// main.cpp
-igl::Viewer * __viewer;
+// Plugin manager (exported to other compilation units)
 igl::Plugin_manager igl_viewer_plugin_manager;
-double highdpi = 1;
-double scroll_x = 0;
-double scroll_y = 0;
+
+// Internal global variables used for glfw event handling
+static igl::Viewer * __viewer;
+static double highdpi = 1;
+static double scroll_x = 0;
+static double scroll_y = 0;
 
 /* This class extends the font rendering code in AntTweakBar
    so that it can be used to render text at arbitrary 3D positions */
@@ -700,6 +700,13 @@ namespace igl
   {
   }
 
+  void Viewer::shutdown_plugins()
+  {
+    if (plugin_manager)
+      for (unsigned int i = 0; i<plugin_manager->plugin_list.size(); ++i)
+        plugin_manager->plugin_list[i]->shutdown();
+  }
+
   bool Viewer::load_mesh_from_file(const char* mesh_file_name)
   {
     std::string mesh_file_name_string = std::string(mesh_file_name);
@@ -2264,9 +2271,10 @@ namespace igl
     // Initialize AntTweakBar
     TwInit(TW_OPENGL_CORE, NULL);
 
-    //      // Initialize IGL viewer
+    // Initialize IGL viewer
     init(&igl_viewer_plugin_manager);
     __viewer = this;
+
     // Register callbacks
     glfwSetKeyCallback(window, glfw_key_callback);
     glfwSetCursorPosCallback(window,glfw_mouse_move);
@@ -2290,19 +2298,20 @@ namespace igl
 
     // Load the mesh passed as input
     if (filename.size() > 0)
-      __viewer->load_mesh_from_file(filename.c_str());
+      load_mesh_from_file(filename.c_str());
 
     // Rendering loop
     while (!glfwWindowShouldClose(window))
     {
-      __viewer->draw();
+      draw();
 
       glfwSwapBuffers(window);
       //glfwPollEvents();
       glfwWaitEvents();
     }
 
-    __viewer->free_opengl();
+    free_opengl();
+    shutdown_plugins();
 
     glfwDestroyWindow(window);
     glfwTerminate();

+ 17 - 11
include/igl/viewer/Viewer.h

@@ -315,6 +315,7 @@ namespace igl
     // Pointer to the plugin_manager (usually it will be a global variable)
     Plugin_manager* plugin_manager;
     void init_plugins();
+    void shutdown_plugins();
 
     // Temporary data stored when the mouse button is pressed
     Eigen::Vector4f down_rotation;
@@ -454,19 +455,24 @@ namespace igl
 
     ~Viewer_plugin(){};
 
-    // It is called when the viewer is initialized (no mesh will be loaded at this stage)
+    // This function is called when the viewer is initialized (no mesh will be loaded at this stage)
     virtual void init(igl::Viewer *_viewer)
     {
       viewer = _viewer;
     }
 
-    // It is called before a mesh is loaded
+    // This function is called before shutdown
+    virtual void shutdown()
+    {
+    }
+
+    // This function is called before a mesh is loaded
     virtual bool load(std::string filename)
     {
       return false;
     }
 
-    // It is called before a mesh is saved
+    // This function is called before a mesh is saved
     virtual bool save(std::string filename)
     {
       return false;
@@ -478,19 +484,19 @@ namespace igl
       return false;
     }
 
-    // It is called before the draw procedure of Preview3D
+    // This function is called before the draw procedure of Preview3D
     virtual bool pre_draw()
     {
       return false;
     }
 
-    // It is called after the draw procedure of Preview3D
+    // This function is called after the draw procedure of Preview3D
     virtual bool post_draw()
     {
       return false;
     }
 
-    // It is called when the mouse button is pressed
+    // This function is called when the mouse button is pressed
     // - button can be GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON or GLUT_RIGHT_BUTTON
     // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
     virtual bool mouse_down(int button, int modifier)
@@ -498,7 +504,7 @@ namespace igl
       return false;
     }
 
-    // It is called when the mouse button is released
+    // This function is called when the mouse button is released
     // - button can be GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON or GLUT_RIGHT_BUTTON
     // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
     virtual bool mouse_up(int button, int modifier)
@@ -506,28 +512,28 @@ namespace igl
       return false;
     }
 
-    // It is called every time the mouse is moved
+    // This function is called every time the mouse is moved
     // - mouse_x and mouse_y are the new coordinates of the mouse pointer in screen coordinates
     virtual bool mouse_move(int mouse_x, int mouse_y)
     {
       return false;
     }
 
-    // It is called every time the scroll wheel is moved
+    // This function is called every time the scroll wheel is moved
     // Note: this callback is not working with every glut implementation
     virtual bool mouse_scroll(float delta_y)
     {
       return false;
     }
 
-    // It is called when a keyboard key is pressed
+    // This function is called when a keyboard key is pressed
     // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
     virtual bool key_down(unsigned char key, int modifiers)
     {
       return false;
     }
 
-    // It is called when a keyboard key is release
+    // This function is called when a keyboard key is release
     // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
     virtual bool key_up(unsigned char key, int modifiers)
     {

+ 0 - 14
tutorial/100_FileIO/cube.obj

@@ -1,14 +0,0 @@
-v 1 0 1
-v 0 1 1
-v -1 0 1
-v 0 -1 1
-v 1 0 -1
-v 0 1 -1
-v -1 0 -1
-v 0 -1 -1
-f 1 2 3
-f 8 5 1
-f 5 6 2
-f 6 7 3
-f 4 3 7
-f 7 6 5

+ 1 - 1
tutorial/100_FileIO/main.cpp

@@ -9,7 +9,7 @@ Eigen::MatrixXi F;
 int main(int argc, char *argv[])
 {
   // Load a mesh in OFF format
-  igl::readOFF("cube.off", V, F);
+  igl::readOFF("../shared/cube.off", V, F);
 
   // Plot the vertices and faces matrices
   std::cerr << "Vertices: " << std::endl << V << std::endl;

+ 0 - 1
tutorial/102_DrawMesh/bunny.off.REMOVED.git-id

@@ -1 +0,0 @@
-a9f6cb63faaebfecf28f1fe317cc9a3e0ee9b0de

+ 1 - 1
tutorial/102_DrawMesh/main.cpp

@@ -8,7 +8,7 @@ Eigen::MatrixXi F;
 int main(int argc, char *argv[])
 {
   // Load a mesh in OFF format
-  igl::readOFF("bunny.off", V, F);
+  igl::readOFF("../shared/bunny.off", V, F);
 
   // Plot the mesh
   igl::Viewer viewer;

+ 2 - 2
tutorial/103_Events/main.cpp

@@ -30,8 +30,8 @@ bool key_down(igl::Viewer& viewer, unsigned char key, int modifier)
 int main(int argc, char *argv[])
 {
   // Load two meshes
-  igl::readOFF("bumpy.off", V1, F1);
-  igl::readOFF("fertility.off", V2, F2);
+  igl::readOFF("../shared/bumpy.off", V1, F1);
+  igl::readOFF("../shared/fertility.off", V2, F2);
 
   igl::Viewer viewer;
   // Register a keyboard callback that allows to switch between

+ 0 - 1
tutorial/104_Overlays/bunny.off.REMOVED.git-id

@@ -1 +0,0 @@
-a9f6cb63faaebfecf28f1fe317cc9a3e0ee9b0de

+ 2 - 2
tutorial/104_Overlays/main.cpp

@@ -9,7 +9,7 @@ Eigen::MatrixXi F;
 int main(int argc, char *argv[])
 {
   // Load a mesh in OFF format
-  igl::readOFF("bunny.off", V, F);
+  igl::readOFF("../shared/bunny.off", V, F);
 
   // Find the bounding box
   Eigen::Vector3d m = V.colwise().minCoeff();
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
   std::stringstream l2;
   l2 << M(0) << ", " << M(1) << ", " << M(2);
   viewer.draw_label(M,l2.str());
-  
+
   // Launch the viewer
   viewer.launch();
 }

+ 11 - 0
tutorial/105_Colors/CMakeLists.txt

@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 2.6)
+project(105_Colors)
+
+include("../CMakeLists.shared")
+
+set(SOURCES
+${PROJECT_SOURCE_DIR}/main.cpp
+)
+
+add_executable(105_Colors ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(105_Colors ${SHARED_LIBRARIES})

+ 37 - 0
tutorial/105_Colors/main.cpp

@@ -0,0 +1,37 @@
+#define IGL_HEADER_ONLY
+#include <igl/readOFF.h>
+#include <igl/viewer/Viewer.h>
+#include <igl/jet.h>
+
+Eigen::MatrixXd V;
+Eigen::MatrixXi F;
+
+int main(int argc, char *argv[])
+{
+  // Load a mesh in OFF format
+  igl::readOFF("../shared/screwdriver.off", V, F);
+
+  // Plot the mesh
+  igl::Viewer viewer;
+  viewer.draw_mesh(V, F);
+
+
+  // Normalize x coordinate between 0 and 1
+  Eigen::VectorXd value = V.col(0).array() - V.col(0).minCoeff();
+  value = value.array() / value.maxCoeff();
+
+  // Map to colors using jet colorramp
+  Eigen::MatrixXd C(V.rows(),3);
+  for (unsigned i=0; i<V.rows(); ++i)
+  {
+    double r,g,b;
+    igl::jet(value(i),r,g,b);
+    C.row(i) << r,g,b;
+  }
+
+  // Add per-vertex colors
+  viewer.draw_colors(C);
+
+  // Launch the viewer
+  viewer.launch();
+}

+ 3 - 14
tutorial/cmake/FindGLEW.cmake

@@ -3,11 +3,7 @@
 #
 #  GLEW_FOUND - system has GLEW
 #  GLEW_INCLUDE_DIR - the GLEW include directory
-#  GLEW_LIBRARIES - The libraries needed to use GLEW
-
-if(GLEW_INCLUDE_DIR AND GLEW_LIBRARIES)
-   set(GLEW_FOUND TRUE)
-else(GLEW_INCLUDE_DIR AND GLEW_LIBRARIES)
+#  GLEW_SOURCES - the GLEW source file list
 
 FIND_PATH(GLEW_INCLUDE_DIR GL/glew.h
    ${PROJECT_SOURCE_DIR}/../../external/glew/include
@@ -25,18 +21,11 @@ if(GLEW_INCLUDE_DIR)
    set(GLEW_FOUND TRUE)
 endif(GLEW_INCLUDE_DIR)
 
-
 if(GLEW_FOUND)
   set(GLEW_SOURCES ${GLEW_INCLUDE_DIR}/../src/glew.c)
-   if(NOT GLEW_FIND_QUIETLY)
-      message(STATUS "Found GLEW: ${GLEW_LIBRARIES}")
-   endif(NOT GLEW_FIND_QUIETLY)
+  message(STATUS "Found GLEW: ${GLEW_INCLUDE_DIR}")
 else(GLEW_FOUND)
-   if(GLEW_FIND_REQUIRED)
-      message(FATAL_ERROR "could NOT find glew")
-   endif(GLEW_FIND_REQUIRED)
+  message(FATAL_ERROR "could NOT find glew")
 endif(GLEW_FOUND)
 
 MARK_AS_ADVANCED(GLEW_INCLUDE_DIR)
-
-endif(GLEW_INCLUDE_DIR)

+ 0 - 0
tutorial/103_Events/bumpy.off → tutorial/shared/bumpy.off


+ 0 - 0
tutorial/100_FileIO/bunny.off.REMOVED.git-id → tutorial/shared/bunny.off.REMOVED.git-id


+ 0 - 0
tutorial/100_FileIO/cube.off → tutorial/shared/cube.off


+ 0 - 0
tutorial/103_Events/fertility.off.REMOVED.git-id → tutorial/shared/fertility.off.REMOVED.git-id


+ 1 - 0
tutorial/shared/screwdriver.off.REMOVED.git-id

@@ -0,0 +1 @@
+ae29a221ba0744eee76d2bb697226eb86bcdf563