瀏覽代碼

- the viewer now compiles again as a static library

Former-commit-id: 9a491e16bc0e1f99e9d8f8e2afde45e0ee707865
Daniele Panozzo 11 年之前
父節點
當前提交
85a4eccda3

+ 3 - 3
build/Makefile_viewer

@@ -16,7 +16,7 @@ OBJ_FILES=$(addprefix obj/,$(notdir $(CPP_FILES:.cpp=.o)))
 # include igl headers
 INC+=-I../include/
 
-# EXPECTS THAT CFLAGS IS ALREADY SET APPROPRIATELY 
+# EXPECTS THAT CFLAGS IS ALREADY SET APPROPRIATELY
 
 # Eigen dependency
 EIGEN3_INC=-I$(DEFAULT_PREFIX)/include/eigen3 -I$(DEFAULT_PREFIX)/include/eigen3/unsupported
@@ -35,7 +35,7 @@ endif
 ANTTWEAKBAR_INC=-I$(ANTTWEAKBAR)/include -I$(ANTTWEAKBAR)/src
 INC+=$(ANTTWEAKBAR_INC)
 
-obj: 
+obj:
 	mkdir -p obj
 
 ../lib/libiglviewer.a: $(OBJ_FILES)
@@ -43,7 +43,7 @@ obj:
 	ar cqs $@ $(OBJ_FILES)
 
 obj/%.o: $(SRC_DIR)/%.cpp $(SRC_DIR)/%.h
-	g++ $(AFLAGS) $(CFLAGS) -c -o $@ $< $(INC)
+	$(GG) $(AFLAGS) $(CFLAGS) -c -o $@ $< $(INC)
 
 clean:
 	rm -f obj/*.o

+ 33 - 4
include/igl/project.cpp

@@ -1,12 +1,13 @@
 // This file is part of libigl, a simple c++ geometry processing library.
-// 
+//
 // Copyright (C) 2013 Alec Jacobson <alecjacobson@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 
+//
+// 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/.
 #include "project.h"
 #ifndef IGL_NO_OPENGL
+#ifndef IGL_OPENGL_4
 #include <iostream>
 #include "report_gl_error.h"
 
@@ -110,7 +111,34 @@ IGL_INLINE Eigen::PlainObjectBase<Derivedobj> igl::project(
   return win;
 }
 
+#endif
+#endif
+
+Eigen::Vector3f igl::project(const Eigen::Vector3f&  obj,
+                        const Eigen::Matrix4f& model,
+                        const Eigen::Matrix4f& proj,
+                        const Eigen::Vector4f&  viewport)
+{
+  Eigen::Vector4f tmp;
+  tmp << obj,1;
+
+  tmp = model * tmp;
+
+  tmp = proj * tmp;
+
+  tmp = tmp.array() / tmp(3);
+  tmp = tmp.array() * 0.5f + 0.5f;
+  tmp(0) = tmp(0) * viewport(2) + viewport(0);
+  tmp(1) = tmp(1) * viewport(3) + viewport(1);
+
+  return tmp.head(3);
+}
+
+
 #ifdef IGL_STATIC_LIBRARY
+
+#ifndef IGL_NO_OPENGL
+#ifndef IGL_OPENGL_4
 // Explicit template instanciations
 template int igl::project<Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> >&);
 template Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > igl::project<Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&);
@@ -119,5 +147,6 @@ template Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > igl::proje
 template Eigen::PlainObjectBase<Eigen::Matrix<double, 1, -1, 1, 1, -1> > igl::project<Eigen::Matrix<double, 1, -1, 1, 1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 1, -1, 1, 1, -1> > const&);
 template int igl::project<Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, 1, 3, 1, 1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> >&);
 #endif
+#endif
 
 #endif

+ 19 - 4
include/igl/project.h

@@ -1,9 +1,9 @@
 // This file is part of libigl, a simple c++ geometry processing library.
-// 
+//
 // Copyright (C) 2013 Alec Jacobson <alecjacobson@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 
+//
+// 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_PROJECT_H
 #define IGL_PROJECT_H
@@ -34,6 +34,21 @@ namespace igl
   template <typename Derivedobj>
   IGL_INLINE Eigen::PlainObjectBase<Derivedobj> project(
     const Eigen::PlainObjectBase<Derivedobj> & obj);
+
+  // Eigen reimplementation of gluProject
+// Inputs:
+//   obj*  3D objects' x, y, and z coordinates respectively
+// model        model matrix
+// proj         projection matrix
+// viewport     viewport vector
+// Returns:
+//   screen space x, y, and z coordinates respectively
+// Returns return value of gluProject call
+  Eigen::Vector3f project(const Eigen::Vector3f&  obj,
+                          const Eigen::Matrix4f& model,
+                          const Eigen::Matrix4f& proj,
+                          const Eigen::Vector4f&  viewport);
+
 }
 
 #ifndef IGL_STATIC_LIBRARY

+ 1 - 0
include/igl/unproject.h

@@ -44,6 +44,7 @@ namespace igl
     const Eigen::Matrix4f& model,
     const Eigen::Matrix4f& proj,
     const Eigen::Vector4f& viewport);
+    
   template <typename Derivedwin, typename Derivedobj>
   IGL_INLINE int unproject(
     const Eigen::PlainObjectBase<Derivedwin> & win,

+ 12 - 0
include/igl/viewer/OpenGL_shader.h

@@ -2,6 +2,18 @@
 #define IGL_OPENGL_SHADER_H
 
 #include <igl/igl_inline.h>
+#include <string>
+#include <Eigen/Core>
+
+#ifdef __APPLE__
+#   include <OpenGL/gl3.h>
+#   define __gl_h_ /* Prevent inclusion of the old gl.h */
+#else
+#   ifdef _WIN32
+#       include <windows.h>
+#   endif
+#   include <GL/gl.h>
+#endif
 
 namespace igl
 {

+ 1 - 0
include/igl/viewer/OpenGL_state.h

@@ -6,6 +6,7 @@
 
 #include <igl/igl_inline.h>
 #include <igl/viewer/OpenGL_shader.h>
+#include <igl/viewer/ViewerData.h>
 
 namespace igl
 {

+ 2 - 1
include/igl/viewer/TextRenderer.cpp

@@ -1,4 +1,5 @@
 #include "TextRenderer.h"
+#include <igl/project.h>
 
   IGL_INLINE igl::TextRenderer::TextRenderer() : m_shaderHandleBackup(0) { }
 
@@ -92,7 +93,7 @@
   IGL_INLINE void igl::TextRenderer::DrawText(Eigen::Vector3d pos, Eigen::Vector3d normal, const std::string &text)
   {
     pos += normal * 0.005f * object_scale;
-    Eigen::Vector3f coord = project(Eigen::Vector3f(pos(0), pos(1), pos(2)),
+    Eigen::Vector3f coord = igl::project(Eigen::Vector3f(pos(0), pos(1), pos(2)),
         view_matrix, proj_matrix, viewport);
     auto it = m_textObjects.find(text);
     void *text_obj = nullptr;

+ 3 - 0
include/igl/viewer/TextRenderer.h

@@ -6,6 +6,9 @@
 
 #include <igl/igl_inline.h>
 #include <igl/viewer/OpenGL_shader.h>
+#include <TwOpenGLCore.h>
+#include <map>
+
 
 namespace igl
 {

+ 3 - 24
include/igl/viewer/Viewer.cpp

@@ -38,27 +38,7 @@
 #include <fstream>
 
 #include <algorithm>
-
-//OK NV
-Eigen::Vector3f project(const Eigen::Vector3f&  obj,
-                        const Eigen::Matrix4f& model,
-                        const Eigen::Matrix4f& proj,
-                        const Eigen::Vector4f&  viewport)
-{
-  Eigen::Vector4f tmp;
-  tmp << obj,1;
-
-  tmp = model * tmp;
-
-  tmp = proj * tmp;
-
-  tmp = tmp.array() / tmp(3);
-  tmp = tmp.array() * 0.5f + 0.5f;
-  tmp(0) = tmp(0) * viewport(2) + viewport(0);
-  tmp(1) = tmp(1) * viewport(3) + viewport(1);
-
-  return tmp.head(3);
-}
+#include <igl/project.h>
 
 Eigen::Matrix4f lookAt (
                         const Eigen::Vector3f& eye,
@@ -168,7 +148,6 @@ Eigen::Matrix4f translate(
 #include <igl/trackball.h>
 #include <igl/snap_to_canonical_view_quat.h>
 #include <igl/unproject.h>
-#include <TwOpenGLCore.h>
 #include <igl/viewer/TextRenderer.h>
 
 // Internal global variables used for glfw event handling
@@ -858,7 +837,7 @@ namespace igl
     else
       center = data.V.colwise().sum()/data.V.rows();
 
-    Eigen::Vector3f coord = project(Eigen::Vector3f(center(0),center(1),center(2)), view * model, proj, viewport);
+    Eigen::Vector3f coord = igl::project(Eigen::Vector3f(center(0),center(1),center(2)), view * model, proj, viewport);
     down_mouse_z = coord[2];
     down_rotation = options.trackball_angle;
 
@@ -1704,7 +1683,7 @@ namespace igl
 
     opengl.free();
     __font_renderer.Shut();
-    
+
     shutdown_plugins();
 
     glfwDestroyWindow(window);

+ 1 - 0
include/igl/viewer/ViewerData.h

@@ -2,6 +2,7 @@
 #define IGL_VIEWER_DATA_H
 
 #include <igl/igl_inline.h>
+#include <Eigen/Core>
 
 namespace igl
 {