Эх сурвалжийг харах

fixed many issues with Viewer, compiles statically

Former-commit-id: 5fa63230e7682c48f0245a00381044931a78395c
Alec Jacobson 11 жил өмнө
parent
commit
659cb932ed

+ 4 - 0
.gitignore

@@ -57,3 +57,7 @@ external/tetgen/tetgen
 external/tinyxml2/test
 external/tinyxml2/tinyxml2.pc
 external/yimg/showpng
+README.html
+tutorial/readme.html
+tutorial/*/build/*
+tutorial/*/Makefile

+ 4 - 0
Makefile

@@ -54,6 +54,10 @@ ifeq ($(IGL_WITH_TETGEN),1)
 	EXTRA_DIRS+=include/igl/tetgen
 	EXTRAS += tetgen
 endif
+ifeq ($(IGL_WITH_VIEWER),1)
+	EXTRA_DIRS+=include/igl/viewer
+	EXTRAS += viewer
+endif
 ifeq ($(IGL_WITH_XML),1)
 	EXTRA_DIRS+=include/igl/xml
 	EXTRAS += xml

+ 1 - 0
Makefile.conf

@@ -47,6 +47,7 @@ endif
 ifeq ($(IGL_USERNAME),ajx)
 	MOSEKPLATFORM=osx64x86
 	MOSEKVERSION=7
+	IGL_WITH_VIEWER=1
 	IGL_WITH_TETGEN=1
 	IGL_WITH_EMBREE=1
 	IGL_WITH_MATLAB=1

+ 49 - 0
include/igl/viewer/Makefile

@@ -0,0 +1,49 @@
+include ../../../Makefile.conf
+all: CFLAGS += -O3 -DNDEBUG -fopenmp
+debug: CFLAGS += -g -Wall -Werror -fopenmp
+
+.PHONY: all
+all: libiglviewer
+debug: libiglviewer
+
+.PHONY: libviewer
+libiglviewer: obj ../../../lib/libiglviewer.a
+
+CPP_FILES=$(wildcard *.cpp)
+OBJ_FILES=$(addprefix obj/,$(notdir $(CPP_FILES:.cpp=.o)))
+
+# include igl headers
+INC+=-I../../../include/
+
+# EXPECTS THAT CFLAGS IS ALREADY SET APPROPRIATELY 
+
+# Eigen dependency
+EIGEN3_INC=-I$(DEFAULT_PREFIX)/include/eigen3 -I$(DEFAULT_PREFIX)/include/eigen3/unsupported
+INC+=$(EIGEN3_INC)
+
+# GLFW dependency
+ifndef GLFW
+	GLFW=../../../external/glfw/
+endif
+GLFW_INC=-I$(GLFW)/include
+INC+=$(GLFW_INC)
+ifndef ANTTWEAKBAR
+	ANTTWEAKBAR=../../../external/AntTweakBar/
+endif
+# Viewer also uses source files from AntTweakBar for font rendering
+ANTTWEAKBAR_INC=-I$(ANTTWEAKBAR)/include -I$(ANTTWEAKBAR)/src
+INC+=$(ANTTWEAKBAR_INC)
+
+obj: 
+	mkdir -p obj
+
+../../../lib/libiglviewer.a: $(OBJ_FILES)
+	rm -f $@
+	ar cqs $@ $(OBJ_FILES)
+
+obj/%.o: %.cpp %.h
+	g++ $(AFLAGS) $(CFLAGS) -c -o $@ $< $(INC)
+
+clean:
+	rm -f obj/*.o
+	rm -f ../../../lib/libiglmatlab.a

+ 8 - 0
include/igl/viewer/TODOs.txt

@@ -2,3 +2,11 @@
 - zoom with pan rather than scaling
 - don't zoom on horizontal scale
 - trackball mouseup captured by tweakbar
++ remove global `using namespace std`
++ remove `#define IGL_HEADER_ONLY`
++ guard `#undef max`
++ fix all -Wsign-compare
++ missing `#include <iostream>`
++ missing `#include <fstream>`
++ fix all -Wunused-but-set-variable
++ makefile for libiglviewer.a

+ 27 - 22
include/igl/viewer/Viewer.cpp

@@ -16,20 +16,21 @@
 #include <GLFW/glfw3.h>
 
 #ifdef _WIN32
-#include <windows.h>
-#include <GL/glew.h>
+#  include <windows.h>
+#  undef max
+#  undef min
+#  include <GL/glew.h>
 #endif
 
 #include <cmath>
 #include <cstdio>
-#include <string>
 #include <sstream>
 #include <iomanip>
+#include <iostream>
+#include <fstream>
 
 #include <algorithm>
 
-using namespace std;
-
 //OK NV
 Eigen::Vector3f project(const Eigen::Vector3f&  obj,
                         const Eigen::Matrix4f& model,
@@ -154,15 +155,9 @@ Eigen::Matrix4f translate(
 }
 
 
-// Undef Visual Studio macros...
-#undef max
-#undef min
-
 #include <limits>
 #include <cassert>
 
-#define IGL_HEADER_ONLY
-
 #ifdef ENABLE_XML_SERIALIZATION
   #include "igl/xml/XMLSerializer.h"
 #endif
@@ -519,8 +514,10 @@ static void glfw_mouse_move(GLFWwindow* window, double x, double y)
 
 static void glfw_mouse_scroll(GLFWwindow* window, double x, double y)
 {
+  using namespace std;
   scroll_x += x;
   scroll_y += y;
+  cout<<"scroll: "<<x<<","<<y<<endl;
 
   if (!TwEventMouseWheelGLFW(scroll_y))
     __viewer->mouse_scroll(y);
@@ -814,8 +811,8 @@ namespace igl
       data.dirty |= DIRTY_TEXTURE;
     }
 
-    int size = 128;
-    int size2 = size/2;
+    unsigned size = 128;
+    unsigned size2 = size/2;
     data.texture_R.resize(size, size);
     for (unsigned i=0; i<size; ++i)
     {
@@ -1039,7 +1036,7 @@ namespace igl
                          mouse_x,
                          mouse_y,
                          options.trackball_angle.data());
-          Eigen::Vector4f snapq = options.trackball_angle;
+          //Eigen::Vector4f snapq = options.trackball_angle;
 
           break;
         }
@@ -1057,6 +1054,7 @@ namespace igl
         }
         case ZOOM:
         {
+          //float delta = 0.001f * (mouse_x - down_mouse_x + mouse_y - down_mouse_y);
           float delta = 0.001f * (mouse_x - down_mouse_x + mouse_y - down_mouse_y);
           options.camera_zoom *= 1 + delta;
           down_mouse_x = mouse_x;
@@ -1084,13 +1082,15 @@ namespace igl
         if (plugin_manager->plugin_list[i]->mouse_scroll(delta_y))
           return true;
 
-    float mult = (delta_y>0)?1.1:0.9;
-    options.camera_zoom = (options.camera_zoom * mult > 0.1f ? options.camera_zoom * mult : 0.1f);
+    float mult = (1.0+((delta_y>0)?1.:-1.)*0.05);
+    const float min_zoom = 0.1f;
+    options.camera_zoom = (options.camera_zoom * mult > min_zoom ? options.camera_zoom * mult : min_zoom);
     return true;
   }
 
   static GLuint create_shader_helper(GLint type, const std::string &shader_string)
   {
+    using namespace std;
     if (shader_string.empty())
       return (GLuint) 0;
 
@@ -1150,6 +1150,7 @@ namespace igl
     const std::string &geometry_shader_string,
     int geometry_shader_max_vertices)
   {
+    using namespace std;
     vertex_shader = create_shader_helper(GL_VERTEX_SHADER, vertex_shader_string);
     geometry_shader = create_shader_helper(GL_GEOMETRY_SHADER, geometry_shader_string);
     fragment_shader = create_shader_helper(GL_FRAGMENT_SHADER, fragment_shader_string);
@@ -1722,6 +1723,7 @@ namespace igl
 
   void Viewer::draw()
   {
+    using namespace std;
     glClearColor(options.background_color[0],
                  options.background_color[1],
                  options.background_color[2],
@@ -2107,6 +2109,7 @@ namespace igl
   // Helpers that draws the most common meshes
   void Viewer::draw_mesh(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F)
   {
+    using namespace std;
     if (data.V.rows() == 0 && data.F.rows() == 0)
     {
       clear_mesh();
@@ -2137,6 +2140,7 @@ namespace igl
 
   void Viewer::draw_normals(const Eigen::MatrixXd& N)
   {
+    using namespace std;
     if (N.rows() == data.V.rows())
     {
       options.face_based = false;
@@ -2154,6 +2158,7 @@ namespace igl
 
   void Viewer::draw_colors(Eigen::MatrixXd C)
   {
+    using namespace std;
     if (C.rows() == 1)
     {
       for (unsigned i=0;i<data.V_material_diffuse.rows();++i)
@@ -2179,6 +2184,7 @@ namespace igl
 
   void Viewer::draw_UV(const Eigen::MatrixXd& UV)
   {
+    using namespace std;
     if (UV.rows() == data.V.rows())
     {
       options.face_based = false;
@@ -2233,7 +2239,7 @@ namespace igl
     data.labels_strings.push_back(str);
   }
 
-  void Viewer::launch(string filename)
+  void Viewer::launch(std::string filename)
   {
     GLFWwindow* window;
 
@@ -2255,12 +2261,11 @@ namespace igl
     }
     glfwMakeContextCurrent(window);
 
-    int major, minor, rev;
-    major = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
-    minor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR);
-    rev = glfwGetWindowAttrib(window, GLFW_CONTEXT_REVISION);
-
     #ifdef DEBUG
+      int major, minor, rev;
+      major = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
+      minor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR);
+      rev = glfwGetWindowAttrib(window, GLFW_CONTEXT_REVISION);
       printf("OpenGL version recieved: %d.%d.%d\n", major, minor, rev);
       printf("Supported OpenGL is %s\n", (const char*)glGetString(GL_VERSION));
       printf("Supported GLSL is %s\n", (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION));

+ 1 - 0
tutorial/readme.md

@@ -1,4 +1,5 @@
 xhtml header:   <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
+css: default.css
 
 # Introduction