diff --git a/include/igl/opengl/Shader.cpp b/include/igl/opengl/Shader.cpp deleted file mode 100644 index c9e2f15a0..000000000 --- a/include/igl/opengl/Shader.cpp +++ /dev/null @@ -1,173 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2014 Wenzel Jacob -// -// 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 "Shader.h" - -#include -#include - -IGL_INLINE bool igl::opengl::Shader::init_from_files( - const std::string &vertex_shader_filename, - const std::string &fragment_shader_filename, - const std::string &fragment_data_name, - const std::string &geometry_shader_filename, - int geometry_shader_max_vertices) -{ - auto file_to_string = [](const std::string &filename)->std::string - { - std::ifstream t(filename); - return std::string((std::istreambuf_iterator(t)), - std::istreambuf_iterator()); - }; - - return init( - file_to_string(vertex_shader_filename), - file_to_string(fragment_shader_filename), - fragment_data_name, - file_to_string(geometry_shader_filename), - geometry_shader_max_vertices - ); -} - -IGL_INLINE bool igl::opengl::Shader::init( - const std::string &vertex_shader_string, - const std::string &fragment_shader_string, - const std::string &fragment_data_name, - 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); - - if (!vertex_shader || !fragment_shader) - return false; - - program_shader = glCreateProgram(); - - glAttachShader(program_shader, vertex_shader); - glAttachShader(program_shader, fragment_shader); - - if (geometry_shader) - { - glAttachShader(program_shader, geometry_shader); - - /* This covers only basic cases and may need to be modified */ - glProgramParameteri(program_shader, GL_GEOMETRY_INPUT_TYPE, GL_TRIANGLES); - glProgramParameteri(program_shader, GL_GEOMETRY_OUTPUT_TYPE, GL_TRIANGLES); - glProgramParameteri(program_shader, GL_GEOMETRY_VERTICES_OUT, geometry_shader_max_vertices); - } - - glBindFragDataLocation(program_shader, 0, fragment_data_name.c_str()); - glLinkProgram(program_shader); - - GLint status; - glGetProgramiv(program_shader, GL_LINK_STATUS, &status); - - if (status != GL_TRUE) - { - char buffer[512]; - glGetProgramInfoLog(program_shader, 512, NULL, buffer); - cerr << "Linker error: " << endl << buffer << endl; - program_shader = 0; - return false; - } - - return true; -} - -IGL_INLINE void igl::opengl::Shader::bind() -{ - glUseProgram(program_shader); -} - -IGL_INLINE GLint igl::opengl::Shader::attrib(const std::string &name) const -{ - return glGetAttribLocation(program_shader, name.c_str()); -} - -IGL_INLINE GLint igl::opengl::Shader::uniform(const std::string &name) const -{ - return glGetUniformLocation(program_shader, name.c_str()); -} - -IGL_INLINE GLint igl::opengl::Shader::bindVertexAttribArray( - const std::string &name, GLuint bufferID, const Eigen::MatrixXf &M, bool refresh) const -{ - GLint id = attrib(name); - if (id < 0) - return id; - if (M.size() == 0) - { - glDisableVertexAttribArray(id); - return id; - } - glBindBuffer(GL_ARRAY_BUFFER, bufferID); - if (refresh) - glBufferData(GL_ARRAY_BUFFER, sizeof(float)*M.size(), M.data(), GL_DYNAMIC_DRAW); - glVertexAttribPointer(id, M.rows(), GL_FLOAT, GL_FALSE, 0, 0); - glEnableVertexAttribArray(id); - return id; -} - -IGL_INLINE void igl::opengl::Shader::free() -{ - if (program_shader) - { - glDeleteProgram(program_shader); - program_shader = 0; - } - if (vertex_shader) - { - glDeleteShader(vertex_shader); - vertex_shader = 0; - } - if (fragment_shader) - { - glDeleteShader(fragment_shader); - fragment_shader = 0; - } - if (geometry_shader) - { - glDeleteShader(geometry_shader); - geometry_shader = 0; - } -} - -IGL_INLINE GLuint igl::opengl::Shader::create_shader_helper(GLint type, const std::string &shader_string) -{ - using namespace std; - if (shader_string.empty()) - return (GLuint) 0; - - GLuint id = glCreateShader(type); - const char *shader_string_const = shader_string.c_str(); - glShaderSource(id, 1, &shader_string_const, NULL); - glCompileShader(id); - - GLint status; - glGetShaderiv(id, GL_COMPILE_STATUS, &status); - - if (status != GL_TRUE) - { - char buffer[512]; - if (type == GL_VERTEX_SHADER) - cerr << "Vertex shader:" << endl; - else if (type == GL_FRAGMENT_SHADER) - cerr << "Fragment shader:" << endl; - else if (type == GL_GEOMETRY_SHADER) - cerr << "Geometry shader:" << endl; - cerr << shader_string << endl << endl; - glGetShaderInfoLog(id, 512, NULL, buffer); - cerr << "Error: " << endl << buffer << endl; - return (GLuint) 0; - } - - return id; -} diff --git a/include/igl/opengl/Shader.h b/include/igl/opengl/Shader.h deleted file mode 100644 index d39645129..000000000 --- a/include/igl/opengl/Shader.h +++ /dev/null @@ -1,98 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2014 Wenzel Jacob -// -// 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_SHADER_H -#define IGL_OPENGL_SHADER_H - -#include -#include -#include - -#ifdef _WIN32 -# include -# undef max -# undef min -# undef DrawText -#endif - -#ifndef __APPLE__ -# define GLEW_STATIC -# include -#endif - -#ifdef __APPLE__ -# include -# define __gl_h_ /* Prevent inclusion of the old gl.h */ -#else -# include -#endif - -namespace igl -{ -namespace opengl -{ - -// This class wraps an OpenGL program composed of three shaders -// TODO: write documentation - -class Shader -{ -public: - typedef unsigned int GLuint; - typedef int GLint; - - GLuint vertex_shader; - GLuint fragment_shader; - GLuint geometry_shader; - GLuint program_shader; - - IGL_INLINE Shader() : vertex_shader(0), fragment_shader(0), - geometry_shader(0), program_shader(0) { } - - // Create a new shader from the specified source strings - IGL_INLINE bool init(const std::string &vertex_shader_string, - const std::string &fragment_shader_string, - const std::string &fragment_data_name, - const std::string &geometry_shader_string = "", - int geometry_shader_max_vertices = 3); - - // Create a new shader from the specified files on disk - IGL_INLINE bool init_from_files(const std::string &vertex_shader_filename, - const std::string &fragment_shader_filename, - const std::string &fragment_data_name, - const std::string &geometry_shader_filename = "", - int geometry_shader_max_vertices = 3); - - // Select this shader for subsequent draw calls - IGL_INLINE void bind(); - - // Release all OpenGL objects - IGL_INLINE void free(); - - // Return the OpenGL handle of a named shader attribute (-1 if it does not exist) - IGL_INLINE GLint attrib(const std::string &name) const; - - // Return the OpenGL handle of a uniform attribute (-1 if it does not exist) - IGL_INLINE GLint uniform(const std::string &name) const; - - // Bind a per-vertex array attribute and refresh its contents from an Eigen amtrix - IGL_INLINE GLint bindVertexAttribArray(const std::string &name, GLuint bufferID, - const Eigen::MatrixXf &M, bool refresh) const; - - IGL_INLINE GLuint create_shader_helper(GLint type, const std::string &shader_string); - -}; - -} -} - -#ifndef IGL_STATIC_LIBRARY -# include "Shader.cpp" -#endif - -#endif diff --git a/include/igl/opengl/State.cpp b/include/igl/opengl/State.cpp index c5248c208..105b2c546 100644 --- a/include/igl/opengl/State.cpp +++ b/include/igl/opengl/State.cpp @@ -7,7 +7,10 @@ // obtain one at http://mozilla.org/MPL/2.0/. #include "State.h" +#include "bind_vertex_attrib_array.h" #include "../ViewerData.h" +#include "create_shader_program.h" +#include "destroy_shader_program.h" IGL_INLINE void igl::opengl::State::init_buffers() { @@ -275,13 +278,13 @@ IGL_INLINE void igl::opengl::State::set_data(const igl::ViewerData &data, bool i IGL_INLINE void igl::opengl::State::bind_mesh() { glBindVertexArray(vao_mesh); - shader_mesh.bind(); - shader_mesh.bindVertexAttribArray("position", vbo_V, V_vbo, dirty & ViewerData::DIRTY_POSITION); - shader_mesh.bindVertexAttribArray("normal", vbo_V_normals, V_normals_vbo, dirty & ViewerData::DIRTY_NORMAL); - shader_mesh.bindVertexAttribArray("Ka", vbo_V_ambient, V_ambient_vbo, dirty & ViewerData::DIRTY_AMBIENT); - shader_mesh.bindVertexAttribArray("Kd", vbo_V_diffuse, V_diffuse_vbo, dirty & ViewerData::DIRTY_DIFFUSE); - shader_mesh.bindVertexAttribArray("Ks", vbo_V_specular, V_specular_vbo, dirty & ViewerData::DIRTY_SPECULAR); - shader_mesh.bindVertexAttribArray("texcoord", vbo_V_uv, V_uv_vbo, dirty & ViewerData::DIRTY_UV); + glUseProgram(shader_mesh); + bind_vertex_attrib_array(shader_mesh,"position", vbo_V, V_vbo, dirty & ViewerData::DIRTY_POSITION); + bind_vertex_attrib_array(shader_mesh,"normal", vbo_V_normals, V_normals_vbo, dirty & ViewerData::DIRTY_NORMAL); + bind_vertex_attrib_array(shader_mesh,"Ka", vbo_V_ambient, V_ambient_vbo, dirty & ViewerData::DIRTY_AMBIENT); + bind_vertex_attrib_array(shader_mesh,"Kd", vbo_V_diffuse, V_diffuse_vbo, dirty & ViewerData::DIRTY_DIFFUSE); + bind_vertex_attrib_array(shader_mesh,"Ks", vbo_V_specular, V_specular_vbo, dirty & ViewerData::DIRTY_SPECULAR); + bind_vertex_attrib_array(shader_mesh,"texcoord", vbo_V_uv, V_uv_vbo, dirty & ViewerData::DIRTY_UV); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_F); if (dirty & ViewerData::DIRTY_FACE) @@ -298,7 +301,7 @@ IGL_INLINE void igl::opengl::State::bind_mesh() glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_u, tex_v, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.data()); } - glUniform1i(shader_mesh.uniform("tex"), 0); + glUniform1i(glGetUniformLocation(shader_mesh,"tex"), 0); dirty &= ~ViewerData::DIRTY_MESH; } @@ -307,9 +310,9 @@ IGL_INLINE void igl::opengl::State::bind_overlay_lines() bool is_dirty = dirty & ViewerData::DIRTY_OVERLAY_LINES; glBindVertexArray(vao_overlay_lines); - shader_overlay_lines.bind(); - shader_overlay_lines.bindVertexAttribArray("position", vbo_lines_V, lines_V_vbo, is_dirty); - shader_overlay_lines.bindVertexAttribArray("color", vbo_lines_V_colors, lines_V_colors_vbo, is_dirty); + glUseProgram(shader_overlay_lines); + bind_vertex_attrib_array(shader_overlay_lines,"position", vbo_lines_V, lines_V_vbo, is_dirty); + bind_vertex_attrib_array(shader_overlay_lines,"color", vbo_lines_V_colors, lines_V_colors_vbo, is_dirty); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_lines_F); if (is_dirty) @@ -323,9 +326,9 @@ IGL_INLINE void igl::opengl::State::bind_overlay_points() bool is_dirty = dirty & ViewerData::DIRTY_OVERLAY_POINTS; glBindVertexArray(vao_overlay_points); - shader_overlay_points.bind(); - shader_overlay_points.bindVertexAttribArray("position", vbo_points_V, points_V_vbo, is_dirty); - shader_overlay_points.bindVertexAttribArray("color", vbo_points_V_colors, points_V_colors_vbo, is_dirty); + glUseProgram(shader_overlay_points); + bind_vertex_attrib_array(shader_overlay_points,"position", vbo_points_V, points_V_vbo, is_dirty); + bind_vertex_attrib_array(shader_overlay_points,"color", vbo_points_V_colors, points_V_colors_vbo, is_dirty); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_points_F); if (is_dirty) @@ -471,18 +474,35 @@ IGL_INLINE void igl::opengl::State::init() "}"; init_buffers(); - shader_mesh.init(mesh_vertex_shader_string, - mesh_fragment_shader_string, "outColor"); - shader_overlay_lines.init(overlay_vertex_shader_string, - overlay_fragment_shader_string, "outColor"); - shader_overlay_points.init(overlay_vertex_shader_string, - overlay_point_fragment_shader_string, "outColor"); + create_shader_program( + mesh_vertex_shader_string, + mesh_fragment_shader_string, + {}, + shader_mesh); + create_shader_program( + overlay_vertex_shader_string, + overlay_fragment_shader_string, + {}, + shader_overlay_lines); + create_shader_program( + overlay_vertex_shader_string, + overlay_point_fragment_shader_string, + {}, + shader_overlay_points); } IGL_INLINE void igl::opengl::State::free() { - shader_mesh.free(); - shader_overlay_lines.free(); - shader_overlay_points.free(); + const auto free = [](GLuint & id) + { + if(id) + { + destroy_shader_program(id); + id = 0; + } + }; + free(shader_mesh); + free(shader_overlay_lines); + free(shader_overlay_points); free_buffers(); } diff --git a/include/igl/opengl/State.h b/include/igl/opengl/State.h index b9bd239bc..99e126b33 100644 --- a/include/igl/opengl/State.h +++ b/include/igl/opengl/State.h @@ -17,7 +17,6 @@ // appropriate. #include -#include "Shader.h" #include "../ViewerData.h" namespace igl @@ -33,9 +32,9 @@ public: GLuint vao_mesh; GLuint vao_overlay_lines; GLuint vao_overlay_points; - Shader shader_mesh; - Shader shader_overlay_lines; - Shader shader_overlay_points; + GLuint shader_mesh; + GLuint shader_overlay_lines; + GLuint shader_overlay_points; GLuint vbo_V; // Vertices of the current mesh (#V x 3) GLuint vbo_V_uv; // UV coordinates for the current mesh (#V x 2) diff --git a/include/igl/opengl/ViewerCore.cpp b/include/igl/opengl/ViewerCore.cpp index de14adbb1..ecfa56c83 100644 --- a/include/igl/opengl/ViewerCore.cpp +++ b/include/igl/opengl/ViewerCore.cpp @@ -7,13 +7,14 @@ // obtain one at http://mozilla.org/MPL/2.0/. #include "ViewerCore.h" -#include -#include -#include -#include -#include -#include -#include +#include "gl.h" +#include "../quat_to_mat.h" +#include "../snap_to_fixed_up.h" +#include "../look_at.h" +#include "../frustum.h" +#include "../ortho.h" +#include "../massmatrix.h" +#include "../barycenter.h" #include #include @@ -161,19 +162,19 @@ IGL_INLINE void igl::opengl::ViewerCore::draw( } // Send transformations to the GPU - GLint modeli = opengl.shader_mesh.uniform("model"); - GLint viewi = opengl.shader_mesh.uniform("view"); - GLint proji = opengl.shader_mesh.uniform("proj"); + GLint modeli = glGetUniformLocation(opengl.shader_mesh,"model"); + GLint viewi = glGetUniformLocation(opengl.shader_mesh,"view"); + GLint proji = glGetUniformLocation(opengl.shader_mesh,"proj"); glUniformMatrix4fv(modeli, 1, GL_FALSE, model.data()); glUniformMatrix4fv(viewi, 1, GL_FALSE, view.data()); glUniformMatrix4fv(proji, 1, GL_FALSE, proj.data()); // Light parameters - GLint specular_exponenti = opengl.shader_mesh.uniform("specular_exponent"); - GLint light_position_worldi = opengl.shader_mesh.uniform("light_position_world"); - GLint lighting_factori = opengl.shader_mesh.uniform("lighting_factor"); - GLint fixed_colori = opengl.shader_mesh.uniform("fixed_color"); - GLint texture_factori = opengl.shader_mesh.uniform("texture_factor"); + GLint specular_exponenti = glGetUniformLocation(opengl.shader_mesh,"specular_exponent"); + GLint light_position_worldi = glGetUniformLocation(opengl.shader_mesh,"light_position_world"); + GLint lighting_factori = glGetUniformLocation(opengl.shader_mesh,"lighting_factor"); + GLint fixed_colori = glGetUniformLocation(opengl.shader_mesh,"fixed_color"); + GLint texture_factori = glGetUniformLocation(opengl.shader_mesh,"texture_factor"); glUniform1f(specular_exponenti, shininess); Vector3f rev_light = -1.*light_position; @@ -239,9 +240,9 @@ IGL_INLINE void igl::opengl::ViewerCore::draw( if (data.lines.rows() > 0) { opengl.bind_overlay_lines(); - modeli = opengl.shader_overlay_lines.uniform("model"); - viewi = opengl.shader_overlay_lines.uniform("view"); - proji = opengl.shader_overlay_lines.uniform("proj"); + modeli = glGetUniformLocation(opengl.shader_overlay_lines,"model"); + viewi = glGetUniformLocation(opengl.shader_overlay_lines,"view"); + proji = glGetUniformLocation(opengl.shader_overlay_lines,"proj"); glUniformMatrix4fv(modeli, 1, GL_FALSE, model.data()); glUniformMatrix4fv(viewi, 1, GL_FALSE, view.data()); @@ -256,9 +257,9 @@ IGL_INLINE void igl::opengl::ViewerCore::draw( if (data.points.rows() > 0) { opengl.bind_overlay_points(); - modeli = opengl.shader_overlay_points.uniform("model"); - viewi = opengl.shader_overlay_points.uniform("view"); - proji = opengl.shader_overlay_points.uniform("proj"); + modeli = glGetUniformLocation(opengl.shader_overlay_points,"model"); + viewi = glGetUniformLocation(opengl.shader_overlay_points,"view"); + proji = glGetUniformLocation(opengl.shader_overlay_points,"proj"); glUniformMatrix4fv(modeli, 1, GL_FALSE, model.data()); glUniformMatrix4fv(viewi, 1, GL_FALSE, view.data()); diff --git a/include/igl/opengl/bind_vertex_attrib_array.cpp b/include/igl/opengl/bind_vertex_attrib_array.cpp new file mode 100644 index 000000000..26de3a273 --- /dev/null +++ b/include/igl/opengl/bind_vertex_attrib_array.cpp @@ -0,0 +1,24 @@ +#include "bind_vertex_attrib_array.h" + +IGL_INLINE GLint igl::opengl::bind_vertex_attrib_array( + const GLuint program_shader, + const std::string &name, + GLuint bufferID, + const Eigen::MatrixXf &M, + bool refresh) +{ + GLint id = glGetAttribLocation(program_shader, name.c_str()); + if (id < 0) + return id; + if (M.size() == 0) + { + glDisableVertexAttribArray(id); + return id; + } + glBindBuffer(GL_ARRAY_BUFFER, bufferID); + if (refresh) + glBufferData(GL_ARRAY_BUFFER, sizeof(float)*M.size(), M.data(), GL_DYNAMIC_DRAW); + glVertexAttribPointer(id, M.rows(), GL_FLOAT, GL_FALSE, 0, 0); + glEnableVertexAttribArray(id); + return id; +} diff --git a/include/igl/opengl/bind_vertex_attrib_array.h b/include/igl/opengl/bind_vertex_attrib_array.h new file mode 100644 index 000000000..7a013b986 --- /dev/null +++ b/include/igl/opengl/bind_vertex_attrib_array.h @@ -0,0 +1,32 @@ +#ifndef IGL_OPENGL_BIND_VERTEX_ATTRIB_ARRAY_H +#define IGL_OPENGL_BIND_VERTEX_ATTRIB_ARRAY_H +#include "gl.h" +#include "../igl_inline.h" +#include +#include +namespace igl +{ + namespace opengl + { + // Bind a per-vertex array attribute and refresh its contents from an Eigen + // matrix + // + // Inputs: + // program_shader id of shader program + // name name of attribute in vertex shader + // bufferID id of buffer to bind to + // M #V by dim matrix of per-vertex data + // refresh whether to actually call glBufferData or just bind the buffer + // Returns id of named attribute in shader + IGL_INLINE GLint bind_vertex_attrib_array( + const GLuint program_shader, + const std::string &name, + GLuint bufferID, + const Eigen::MatrixXf &M, + bool refresh); + } +} +#ifndef IGL_STATIC_LIBRARY +#include "bind_vertex_attrib_array.cpp" +#endif +#endif diff --git a/include/igl/viewer/TextRenderer_fonts.cpp b/include/igl/opengl/glfw/TextRenderer_fonts.cpp similarity index 100% rename from include/igl/viewer/TextRenderer_fonts.cpp rename to include/igl/opengl/glfw/TextRenderer_fonts.cpp diff --git a/include/igl/opengl/glfw/Viewer.h b/include/igl/opengl/glfw/Viewer.h index b27838e0a..130563ca7 100644 --- a/include/igl/opengl/glfw/Viewer.h +++ b/include/igl/opengl/glfw/Viewer.h @@ -21,7 +21,6 @@ #include -#include "../Shader.h" #include "../State.h" #include "../ViewerCore.h" #include "../../ViewerData.h" diff --git a/include/igl/opengl/load_shader.cpp b/include/igl/opengl/load_shader.cpp index 446f723e6..0ee0a978f 100644 --- a/include/igl/opengl/load_shader.cpp +++ b/include/igl/opengl/load_shader.cpp @@ -10,8 +10,14 @@ // Copyright Denis Kovacs 4/10/08 #include "print_shader_info_log.h" #include -IGL_INLINE GLuint igl::opengl::load_shader(const char *src,const GLenum type) +IGL_INLINE GLuint igl::opengl::load_shader( + const std::string & src,const GLenum type) { + if(src.empty()) + { + return (GLuint) 0; + } + GLuint s = glCreateShader(type); if(s == 0) { @@ -19,7 +25,8 @@ IGL_INLINE GLuint igl::opengl::load_shader(const char *src,const GLenum type) return 0; } // Pass shader source string - glShaderSource(s, 1, &src, NULL); + const char *c = src.c_str(); + glShaderSource(s, 1, &c, NULL); glCompileShader(s); // Print info log (if any) igl::opengl::print_shader_info_log(s); diff --git a/include/igl/opengl/load_shader.h b/include/igl/opengl/load_shader.h index 49b3b5242..6c234d8fc 100644 --- a/include/igl/opengl/load_shader.h +++ b/include/igl/opengl/load_shader.h @@ -9,12 +9,14 @@ #define IGL_OPENGL_LOAD_SHADER_H #include "../igl_inline.h" #include "gl.h" +#include namespace igl { namespace opengl { // Creates and compiles a shader from a given string + // // Inputs: // src string containing GLSL shader code // type GLSL type of shader, one of: @@ -22,7 +24,10 @@ namespace igl // GL_FRAGMENT_SHADER // GL_GEOMETRY_SHADER // Returns index id of the newly created shader, 0 on error - IGL_INLINE GLuint load_shader(const char *src,const GLenum type); + // + // Will immediately return 0 if src is empty. + IGL_INLINE GLuint load_shader( + const std::string & src,const GLenum type); } } diff --git a/include/igl/viewer/OpenGL_shader.cpp b/include/igl/viewer/OpenGL_shader.cpp deleted file mode 100644 index a898d5d3f..000000000 --- a/include/igl/viewer/OpenGL_shader.cpp +++ /dev/null @@ -1,173 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2014 Wenzel Jacob -// -// 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 "OpenGL_shader.h" - -#include -#include - -IGL_INLINE bool igl::viewer::OpenGL_shader::init_from_files( - const std::string &vertex_shader_filename, - const std::string &fragment_shader_filename, - const std::string &fragment_data_name, - const std::string &geometry_shader_filename, - int geometry_shader_max_vertices) -{ - auto file_to_string = [](const std::string &filename)->std::string - { - std::ifstream t(filename); - return std::string((std::istreambuf_iterator(t)), - std::istreambuf_iterator()); - }; - - return init( - file_to_string(vertex_shader_filename), - file_to_string(fragment_shader_filename), - fragment_data_name, - file_to_string(geometry_shader_filename), - geometry_shader_max_vertices - ); -} - -IGL_INLINE bool igl::viewer::OpenGL_shader::init( - const std::string &vertex_shader_string, - const std::string &fragment_shader_string, - const std::string &fragment_data_name, - 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); - - if (!vertex_shader || !fragment_shader) - return false; - - program_shader = glCreateProgram(); - - glAttachShader(program_shader, vertex_shader); - glAttachShader(program_shader, fragment_shader); - - if (geometry_shader) - { - glAttachShader(program_shader, geometry_shader); - - /* This covers only basic cases and may need to be modified */ - glProgramParameteri(program_shader, GL_GEOMETRY_INPUT_TYPE, GL_TRIANGLES); - glProgramParameteri(program_shader, GL_GEOMETRY_OUTPUT_TYPE, GL_TRIANGLES); - glProgramParameteri(program_shader, GL_GEOMETRY_VERTICES_OUT, geometry_shader_max_vertices); - } - - glBindFragDataLocation(program_shader, 0, fragment_data_name.c_str()); - glLinkProgram(program_shader); - - GLint status; - glGetProgramiv(program_shader, GL_LINK_STATUS, &status); - - if (status != GL_TRUE) - { - char buffer[512]; - glGetProgramInfoLog(program_shader, 512, NULL, buffer); - cerr << "Linker error: " << endl << buffer << endl; - program_shader = 0; - return false; - } - - return true; -} - -IGL_INLINE void igl::viewer::OpenGL_shader::bind() -{ - glUseProgram(program_shader); -} - -IGL_INLINE GLint igl::viewer::OpenGL_shader::attrib(const std::string &name) const -{ - return glGetAttribLocation(program_shader, name.c_str()); -} - -IGL_INLINE GLint igl::viewer::OpenGL_shader::uniform(const std::string &name) const -{ - return glGetUniformLocation(program_shader, name.c_str()); -} - -IGL_INLINE GLint igl::viewer::OpenGL_shader::bindVertexAttribArray( - const std::string &name, GLuint bufferID, const Eigen::MatrixXf &M, bool refresh) const -{ - GLint id = attrib(name); - if (id < 0) - return id; - if (M.size() == 0) - { - glDisableVertexAttribArray(id); - return id; - } - glBindBuffer(GL_ARRAY_BUFFER, bufferID); - if (refresh) - glBufferData(GL_ARRAY_BUFFER, sizeof(float)*M.size(), M.data(), GL_DYNAMIC_DRAW); - glVertexAttribPointer(id, M.rows(), GL_FLOAT, GL_FALSE, 0, 0); - glEnableVertexAttribArray(id); - return id; -} - -IGL_INLINE void igl::viewer::OpenGL_shader::free() -{ - if (program_shader) - { - glDeleteProgram(program_shader); - program_shader = 0; - } - if (vertex_shader) - { - glDeleteShader(vertex_shader); - vertex_shader = 0; - } - if (fragment_shader) - { - glDeleteShader(fragment_shader); - fragment_shader = 0; - } - if (geometry_shader) - { - glDeleteShader(geometry_shader); - geometry_shader = 0; - } -} - -IGL_INLINE GLuint igl::viewer::OpenGL_shader::create_shader_helper(GLint type, const std::string &shader_string) -{ - using namespace std; - if (shader_string.empty()) - return (GLuint) 0; - - GLuint id = glCreateShader(type); - const char *shader_string_const = shader_string.c_str(); - glShaderSource(id, 1, &shader_string_const, NULL); - glCompileShader(id); - - GLint status; - glGetShaderiv(id, GL_COMPILE_STATUS, &status); - - if (status != GL_TRUE) - { - char buffer[512]; - if (type == GL_VERTEX_SHADER) - cerr << "Vertex shader:" << endl; - else if (type == GL_FRAGMENT_SHADER) - cerr << "Fragment shader:" << endl; - else if (type == GL_GEOMETRY_SHADER) - cerr << "Geometry shader:" << endl; - cerr << shader_string << endl << endl; - glGetShaderInfoLog(id, 512, NULL, buffer); - cerr << "Error: " << endl << buffer << endl; - return (GLuint) 0; - } - - return id; -} diff --git a/include/igl/viewer/OpenGL_shader.h b/include/igl/viewer/OpenGL_shader.h deleted file mode 100644 index 75cddb5c5..000000000 --- a/include/igl/viewer/OpenGL_shader.h +++ /dev/null @@ -1,98 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2014 Wenzel Jacob -// -// 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_VIEWER_OPENGL_SHADER_H -#define IGL_VIEWER_OPENGL_SHADER_H - -#include -#include -#include - -#ifdef _WIN32 -# include -# undef max -# undef min -# undef DrawText -#endif - -#ifndef __APPLE__ -# define GLEW_STATIC -# include -#endif - -#ifdef __APPLE__ -# include -# define __gl_h_ /* Prevent inclusion of the old gl.h */ -#else -# include -#endif - -namespace igl -{ -namespace viewer -{ - -// This class wraps an OpenGL program composed of three shaders -// TODO: write documentation - -class OpenGL_shader -{ -public: - typedef unsigned int GLuint; - typedef int GLint; - - GLuint vertex_shader; - GLuint fragment_shader; - GLuint geometry_shader; - GLuint program_shader; - - IGL_INLINE OpenGL_shader() : vertex_shader(0), fragment_shader(0), - geometry_shader(0), program_shader(0) { } - - // Create a new shader from the specified source strings - IGL_INLINE bool init(const std::string &vertex_shader_string, - const std::string &fragment_shader_string, - const std::string &fragment_data_name, - const std::string &geometry_shader_string = "", - int geometry_shader_max_vertices = 3); - - // Create a new shader from the specified files on disk - IGL_INLINE bool init_from_files(const std::string &vertex_shader_filename, - const std::string &fragment_shader_filename, - const std::string &fragment_data_name, - const std::string &geometry_shader_filename = "", - int geometry_shader_max_vertices = 3); - - // Select this shader for subsequent draw calls - IGL_INLINE void bind(); - - // Release all OpenGL objects - IGL_INLINE void free(); - - // Return the OpenGL handle of a named shader attribute (-1 if it does not exist) - IGL_INLINE GLint attrib(const std::string &name) const; - - // Return the OpenGL handle of a uniform attribute (-1 if it does not exist) - IGL_INLINE GLint uniform(const std::string &name) const; - - // Bind a per-vertex array attribute and refresh its contents from an Eigen amtrix - IGL_INLINE GLint bindVertexAttribArray(const std::string &name, GLuint bufferID, - const Eigen::MatrixXf &M, bool refresh) const; - - IGL_INLINE GLuint create_shader_helper(GLint type, const std::string &shader_string); - -}; - -} -} - -#ifndef IGL_STATIC_LIBRARY -# include "OpenGL_shader.cpp" -#endif - -#endif diff --git a/include/igl/viewer/OpenGL_state.cpp b/include/igl/viewer/OpenGL_state.cpp deleted file mode 100644 index 0aab28fa5..000000000 --- a/include/igl/viewer/OpenGL_state.cpp +++ /dev/null @@ -1,488 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2014 Daniele Panozzo -// -// 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 "OpenGL_state.h" -#include "ViewerData.h" - -IGL_INLINE void igl::viewer::OpenGL_state::init_buffers() -{ - // Mesh: Vertex Array Object & Buffer objects - glGenVertexArrays(1, &vao_mesh); - glBindVertexArray(vao_mesh); - glGenBuffers(1, &vbo_V); - glGenBuffers(1, &vbo_V_normals); - glGenBuffers(1, &vbo_V_ambient); - glGenBuffers(1, &vbo_V_diffuse); - glGenBuffers(1, &vbo_V_specular); - glGenBuffers(1, &vbo_V_uv); - glGenBuffers(1, &vbo_F); - glGenTextures(1, &vbo_tex); - - // Line overlay - glGenVertexArrays(1, &vao_overlay_lines); - glBindVertexArray(vao_overlay_lines); - glGenBuffers(1, &vbo_lines_F); - glGenBuffers(1, &vbo_lines_V); - glGenBuffers(1, &vbo_lines_V_colors); - - // Point overlay - glGenVertexArrays(1, &vao_overlay_points); - glBindVertexArray(vao_overlay_points); - glGenBuffers(1, &vbo_points_F); - glGenBuffers(1, &vbo_points_V); - glGenBuffers(1, &vbo_points_V_colors); - - dirty = ViewerData::DIRTY_ALL; -} - -IGL_INLINE void igl::viewer::OpenGL_state::free_buffers() -{ - glDeleteVertexArrays(1, &vao_mesh); - glDeleteVertexArrays(1, &vao_overlay_lines); - glDeleteVertexArrays(1, &vao_overlay_points); - - glDeleteBuffers(1, &vbo_V); - glDeleteBuffers(1, &vbo_V_normals); - glDeleteBuffers(1, &vbo_V_ambient); - glDeleteBuffers(1, &vbo_V_diffuse); - glDeleteBuffers(1, &vbo_V_specular); - glDeleteBuffers(1, &vbo_V_uv); - glDeleteBuffers(1, &vbo_F); - glDeleteBuffers(1, &vbo_lines_F); - glDeleteBuffers(1, &vbo_lines_V); - glDeleteBuffers(1, &vbo_lines_V_colors); - glDeleteBuffers(1, &vbo_points_F); - glDeleteBuffers(1, &vbo_points_V); - glDeleteBuffers(1, &vbo_points_V_colors); - - glDeleteTextures(1, &vbo_tex); -} - -IGL_INLINE void igl::viewer::OpenGL_state::set_data(const igl::viewer::ViewerData &data, bool invert_normals) -{ - bool per_corner_uv = (data.F_uv.rows() == data.F.rows()); - bool per_corner_normals = (data.F_normals.rows() == 3 * data.F.rows()); - - dirty |= data.dirty; - - if (!data.face_based) - { - if (!per_corner_uv) - { - // Vertex positions - if (dirty & ViewerData::DIRTY_POSITION) - V_vbo = (data.V.transpose()).cast(); - - // Vertex normals - if (dirty & ViewerData::DIRTY_NORMAL) - { - V_normals_vbo = (data.V_normals.transpose()).cast(); - if (invert_normals) - V_normals_vbo = -V_normals_vbo; - } - - // Per-vertex material settings - if (dirty & ViewerData::DIRTY_AMBIENT) - V_ambient_vbo = (data.V_material_ambient.transpose()).cast(); - if (dirty & ViewerData::DIRTY_DIFFUSE) - V_diffuse_vbo = (data.V_material_diffuse.transpose()).cast(); - if (dirty & ViewerData::DIRTY_SPECULAR) - V_specular_vbo = (data.V_material_specular.transpose()).cast(); - - // Face indices - if (dirty & ViewerData::DIRTY_FACE) - F_vbo = (data.F.transpose()).cast(); - - // Texture coordinates - if (dirty & ViewerData::DIRTY_UV) - V_uv_vbo = (data.V_uv.transpose()).cast(); - } - else - { - // Per vertex properties with per corner UVs - if (dirty & ViewerData::DIRTY_POSITION) - { - V_vbo.resize(3,data.F.rows()*3); - for (unsigned i=0; i(); - } - - if (dirty & ViewerData::DIRTY_AMBIENT) - { - V_ambient_vbo.resize(3,data.F.rows()*3); - for (unsigned i=0; i(); - } - - if (dirty & ViewerData::DIRTY_DIFFUSE) - { - V_diffuse_vbo.resize(3,data.F.rows()*3); - for (unsigned i=0; i(); - } - - if (dirty & ViewerData::DIRTY_SPECULAR) - { - V_specular_vbo.resize(3,data.F.rows()*3); - for (unsigned i=0; i(); - } - - if (dirty & ViewerData::DIRTY_NORMAL) - { - V_normals_vbo.resize(3,data.F.rows()*3); - for (unsigned i=0; i(); - - if (invert_normals) - V_normals_vbo = -V_normals_vbo; - } - - if (dirty & ViewerData::DIRTY_FACE) - { - F_vbo.resize(3,data.F.rows()); - for (unsigned i=0; i(); - } - } - } - else - { - if (dirty & ViewerData::DIRTY_POSITION) - { - V_vbo.resize(3,data.F.rows()*3); - for (unsigned i=0; i(); - } - - if (dirty & ViewerData::DIRTY_AMBIENT) - { - V_ambient_vbo.resize(4,data.F.rows()*3); - for (unsigned i=0; i(); - } - - if (dirty & ViewerData::DIRTY_DIFFUSE) - { - V_diffuse_vbo.resize(4,data.F.rows()*3); - for (unsigned i=0; i(); - } - - if (dirty & ViewerData::DIRTY_SPECULAR) - { - V_specular_vbo.resize(4,data.F.rows()*3); - for (unsigned i=0; i(); - } - - if (dirty & ViewerData::DIRTY_NORMAL) - { - V_normals_vbo.resize(3,data.F.rows()*3); - for (unsigned i=0; i() : - data.F_normals.row(i).transpose().cast(); - - if (invert_normals) - V_normals_vbo = -V_normals_vbo; - } - - if (dirty & ViewerData::DIRTY_FACE) - { - F_vbo.resize(3,data.F.rows()); - for (unsigned i=0; i(); - } - } - - if (dirty & ViewerData::DIRTY_TEXTURE) - { - tex_u = data.texture_R.rows(); - tex_v = data.texture_R.cols(); - tex.resize(data.texture_R.size()*4); - for (unsigned i=0;i(i, 0).transpose().cast(); - lines_V_vbo.col(2*i+1) = data.lines.block<1, 3>(i, 3).transpose().cast(); - lines_V_colors_vbo.col(2*i+0) = data.lines.block<1, 3>(i, 6).transpose().cast(); - lines_V_colors_vbo.col(2*i+1) = data.lines.block<1, 3>(i, 6).transpose().cast(); - lines_F_vbo(2*i+0) = 2*i+0; - lines_F_vbo(2*i+1) = 2*i+1; - } - } - - if (dirty & ViewerData::DIRTY_OVERLAY_POINTS) - { - points_V_vbo.resize(3, data.points.rows()); - points_V_colors_vbo.resize(3, data.points.rows()); - points_F_vbo.resize(1, data.points.rows()); - for (unsigned i=0; i(i, 0).transpose().cast(); - points_V_colors_vbo.col(i) = data.points.block<1, 3>(i, 3).transpose().cast(); - points_F_vbo(i) = i; - } - } -} - -IGL_INLINE void igl::viewer::OpenGL_state::bind_mesh() -{ - glBindVertexArray(vao_mesh); - shader_mesh.bind(); - shader_mesh.bindVertexAttribArray("position", vbo_V, V_vbo, dirty & ViewerData::DIRTY_POSITION); - shader_mesh.bindVertexAttribArray("normal", vbo_V_normals, V_normals_vbo, dirty & ViewerData::DIRTY_NORMAL); - shader_mesh.bindVertexAttribArray("Ka", vbo_V_ambient, V_ambient_vbo, dirty & ViewerData::DIRTY_AMBIENT); - shader_mesh.bindVertexAttribArray("Kd", vbo_V_diffuse, V_diffuse_vbo, dirty & ViewerData::DIRTY_DIFFUSE); - shader_mesh.bindVertexAttribArray("Ks", vbo_V_specular, V_specular_vbo, dirty & ViewerData::DIRTY_SPECULAR); - shader_mesh.bindVertexAttribArray("texcoord", vbo_V_uv, V_uv_vbo, dirty & ViewerData::DIRTY_UV); - - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_F); - if (dirty & ViewerData::DIRTY_FACE) - glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned)*F_vbo.size(), F_vbo.data(), GL_DYNAMIC_DRAW); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, vbo_tex); - if (dirty & ViewerData::DIRTY_TEXTURE) - { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_u, tex_v, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.data()); - } - glUniform1i(shader_mesh.uniform("tex"), 0); - dirty &= ~ViewerData::DIRTY_MESH; -} - -IGL_INLINE void igl::viewer::OpenGL_state::bind_overlay_lines() -{ - bool is_dirty = dirty & ViewerData::DIRTY_OVERLAY_LINES; - - glBindVertexArray(vao_overlay_lines); - shader_overlay_lines.bind(); - shader_overlay_lines.bindVertexAttribArray("position", vbo_lines_V, lines_V_vbo, is_dirty); - shader_overlay_lines.bindVertexAttribArray("color", vbo_lines_V_colors, lines_V_colors_vbo, is_dirty); - - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_lines_F); - if (is_dirty) - glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned)*lines_F_vbo.size(), lines_F_vbo.data(), GL_DYNAMIC_DRAW); - - dirty &= ~ViewerData::DIRTY_OVERLAY_LINES; -} - -IGL_INLINE void igl::viewer::OpenGL_state::bind_overlay_points() -{ - bool is_dirty = dirty & ViewerData::DIRTY_OVERLAY_POINTS; - - glBindVertexArray(vao_overlay_points); - shader_overlay_points.bind(); - shader_overlay_points.bindVertexAttribArray("position", vbo_points_V, points_V_vbo, is_dirty); - shader_overlay_points.bindVertexAttribArray("color", vbo_points_V_colors, points_V_colors_vbo, is_dirty); - - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_points_F); - if (is_dirty) - glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned)*points_F_vbo.size(), points_F_vbo.data(), GL_DYNAMIC_DRAW); - - dirty &= ~ViewerData::DIRTY_OVERLAY_POINTS; -} - -IGL_INLINE void igl::viewer::OpenGL_state::draw_mesh(bool solid) -{ - glPolygonMode(GL_FRONT_AND_BACK, solid ? GL_FILL : GL_LINE); - - /* Avoid Z-buffer fighting between filled triangles & wireframe lines */ - if (solid) - { - glEnable(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(1.0, 1.0); - } - glDrawElements(GL_TRIANGLES, 3*F_vbo.cols(), GL_UNSIGNED_INT, 0); - - glDisable(GL_POLYGON_OFFSET_FILL); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); -} - -IGL_INLINE void igl::viewer::OpenGL_state::draw_overlay_lines() -{ - glDrawElements(GL_LINES, lines_F_vbo.cols(), GL_UNSIGNED_INT, 0); -} - -IGL_INLINE void igl::viewer::OpenGL_state::draw_overlay_points() -{ - glDrawElements(GL_POINTS, points_F_vbo.cols(), GL_UNSIGNED_INT, 0); -} - -IGL_INLINE void igl::viewer::OpenGL_state::init() -{ - std::string mesh_vertex_shader_string = - "#version 150\n" - "uniform mat4 model;" - "uniform mat4 view;" - "uniform mat4 proj;" - "in vec3 position;" - "in vec3 normal;" - "out vec3 position_eye;" - "out vec3 normal_eye;" - "in vec4 Ka;" - "in vec4 Kd;" - "in vec4 Ks;" - "in vec2 texcoord;" - "out vec2 texcoordi;" - "out vec4 Kai;" - "out vec4 Kdi;" - "out vec4 Ksi;" - - "void main()" - "{" - " position_eye = vec3 (view * model * vec4 (position, 1.0));" - " normal_eye = vec3 (view * model * vec4 (normal, 0.0));" - " normal_eye = normalize(normal_eye);" - " gl_Position = proj * vec4 (position_eye, 1.0);" //proj * view * model * vec4(position, 1.0);" - " Kai = Ka;" - " Kdi = Kd;" - " Ksi = Ks;" - " texcoordi = texcoord;" - "}"; - - std::string mesh_fragment_shader_string = - "#version 150\n" - "uniform mat4 model;" - "uniform mat4 view;" - "uniform mat4 proj;" - "uniform vec4 fixed_color;" - "in vec3 position_eye;" - "in vec3 normal_eye;" - "uniform vec3 light_position_world;" - "vec3 Ls = vec3 (1, 1, 1);" - "vec3 Ld = vec3 (1, 1, 1);" - "vec3 La = vec3 (1, 1, 1);" - "in vec4 Ksi;" - "in vec4 Kdi;" - "in vec4 Kai;" - "in vec2 texcoordi;" - "uniform sampler2D tex;" - "uniform float specular_exponent;" - "uniform float lighting_factor;" - "uniform float texture_factor;" - "out vec4 outColor;" - "void main()" - "{" - "vec3 Ia = La * vec3(Kai);" // ambient intensity - - "vec3 light_position_eye = vec3 (view * vec4 (light_position_world, 1.0));" - "vec3 vector_to_light_eye = light_position_eye - position_eye;" - "vec3 direction_to_light_eye = normalize (vector_to_light_eye);" - "float dot_prod = dot (direction_to_light_eye, normal_eye);" - "float clamped_dot_prod = max (dot_prod, 0.0);" - "vec3 Id = Ld * vec3(Kdi) * clamped_dot_prod;" // Diffuse intensity - - "vec3 reflection_eye = reflect (-direction_to_light_eye, normal_eye);" - "vec3 surface_to_viewer_eye = normalize (-position_eye);" - "float dot_prod_specular = dot (reflection_eye, surface_to_viewer_eye);" - "dot_prod_specular = float(abs(dot_prod)==dot_prod) * max (dot_prod_specular, 0.0);" - "float specular_factor = pow (dot_prod_specular, specular_exponent);" - "vec3 Is = Ls * vec3(Ksi) * specular_factor;" // specular intensity - "vec4 color = vec4(lighting_factor * (Is + Id) + Ia + (1.0-lighting_factor) * vec3(Kdi),(Kai.a+Ksi.a+Kdi.a)/3);" - "outColor = mix(vec4(1,1,1,1), texture(tex, texcoordi), texture_factor) * color;" - "if (fixed_color != vec4(0.0)) outColor = fixed_color;" - "}"; - - std::string overlay_vertex_shader_string = - "#version 150\n" - "uniform mat4 model;" - "uniform mat4 view;" - "uniform mat4 proj;" - "in vec3 position;" - "in vec3 color;" - "out vec3 color_frag;" - - "void main()" - "{" - " gl_Position = proj * view * model * vec4 (position, 1.0);" - " color_frag = color;" - "}"; - - std::string overlay_fragment_shader_string = - "#version 150\n" - "in vec3 color_frag;" - "out vec4 outColor;" - "void main()" - "{" - " outColor = vec4(color_frag, 1.0);" - "}"; - - std::string overlay_point_fragment_shader_string = - "#version 150\n" - "in vec3 color_frag;" - "out vec4 outColor;" - "void main()" - "{" - " if (length(gl_PointCoord - vec2(0.5)) > 0.5)" - " discard;" - " outColor = vec4(color_frag, 1.0);" - "}"; - - init_buffers(); - shader_mesh.init(mesh_vertex_shader_string, - mesh_fragment_shader_string, "outColor"); - shader_overlay_lines.init(overlay_vertex_shader_string, - overlay_fragment_shader_string, "outColor"); - shader_overlay_points.init(overlay_vertex_shader_string, - overlay_point_fragment_shader_string, "outColor"); -} - -IGL_INLINE void igl::viewer::OpenGL_state::free() -{ - shader_mesh.free(); - shader_overlay_lines.free(); - shader_overlay_points.free(); - free_buffers(); -} diff --git a/include/igl/viewer/OpenGL_state.h b/include/igl/viewer/OpenGL_state.h deleted file mode 100644 index 03cf5cb60..000000000 --- a/include/igl/viewer/OpenGL_state.h +++ /dev/null @@ -1,117 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2014 Daniele Panozzo -// -// 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_VIEWER_OPENGL_STATE_H -#define IGL_VIEWER_OPENGL_STATE_H - -// Coverts mesh data inside a igl::viewer::ViewerData class in an OpenGL compatible format -// The class includes a shader and the opengl calls to plot the data - -#include -#include -#include - -namespace igl -{ -namespace viewer -{ - -class OpenGL_state -{ -public: - typedef unsigned int GLuint; - - GLuint vao_mesh; - GLuint vao_overlay_lines; - GLuint vao_overlay_points; - OpenGL_shader shader_mesh; - OpenGL_shader shader_overlay_lines; - OpenGL_shader shader_overlay_points; - - GLuint vbo_V; // Vertices of the current mesh (#V x 3) - GLuint vbo_V_uv; // UV coordinates for the current mesh (#V x 2) - GLuint vbo_V_normals; // Vertices of the current mesh (#V x 3) - GLuint vbo_V_ambient; // Ambient material (#V x 3) - GLuint vbo_V_diffuse; // Diffuse material (#V x 3) - GLuint vbo_V_specular; // Specular material (#V x 3) - - GLuint vbo_F; // Faces of the mesh (#F x 3) - GLuint vbo_tex; // Texture - - GLuint vbo_lines_F; // Indices of the line overlay - GLuint vbo_lines_V; // Vertices of the line overlay - GLuint vbo_lines_V_colors; // Color values of the line overlay - GLuint vbo_points_F; // Indices of the point overlay - GLuint vbo_points_V; // Vertices of the point overlay - GLuint vbo_points_V_colors; // Color values of the point overlay - - // Temporary copy of the content of each VBO - Eigen::MatrixXf V_vbo; - Eigen::MatrixXf V_normals_vbo; - Eigen::MatrixXf V_ambient_vbo; - Eigen::MatrixXf V_diffuse_vbo; - Eigen::MatrixXf V_specular_vbo; - Eigen::MatrixXf V_uv_vbo; - Eigen::MatrixXf lines_V_vbo; - Eigen::MatrixXf lines_V_colors_vbo; - Eigen::MatrixXf points_V_vbo; - Eigen::MatrixXf points_V_colors_vbo; - - int tex_u; - int tex_v; - Eigen::Matrix tex; - - Eigen::Matrix F_vbo; - Eigen::Matrix lines_F_vbo; - Eigen::Matrix points_F_vbo; - - // Marks dirty buffers that need to be uploaded to OpenGL - uint32_t dirty; - - // Initialize shaders and buffers - IGL_INLINE void init(); - - // Release all resources - IGL_INLINE void free(); - - // Create a new set of OpenGL buffer objects - IGL_INLINE void init_buffers(); - - // Update contents from a 'Data' instance - IGL_INLINE void set_data(const igl::viewer::ViewerData &data, bool invert_normals); - - // Bind the underlying OpenGL buffer objects for subsequent mesh draw calls - IGL_INLINE void bind_mesh(); - - /// Draw the currently buffered mesh (either solid or wireframe) - IGL_INLINE void draw_mesh(bool solid); - - // Bind the underlying OpenGL buffer objects for subsequent line overlay draw calls - IGL_INLINE void bind_overlay_lines(); - - /// Draw the currently buffered line overlay - IGL_INLINE void draw_overlay_lines(); - - // Bind the underlying OpenGL buffer objects for subsequent point overlay draw calls - IGL_INLINE void bind_overlay_points(); - - /// Draw the currently buffered point overlay - IGL_INLINE void draw_overlay_points(); - - // Release the OpenGL buffer objects - IGL_INLINE void free_buffers(); - -}; - -} -} - -#ifndef IGL_STATIC_LIBRARY -# include "OpenGL_state.cpp" -#endif - -#endif diff --git a/include/igl/viewer/TODOs.txt b/include/igl/viewer/TODOs.txt deleted file mode 100644 index f74861f3a..000000000 --- a/include/igl/viewer/TODOs.txt +++ /dev/null @@ -1,33 +0,0 @@ -- `align_and_center_object` continues to zoom out on repeated calls -- trackball_angle should be a quaternion -- data.lines, data.points should not concatenate colors with coordinates -- snap to canonical recenters origin but trackball does not -- rewrite in libigl style -- separate various class into their own .h/.cpp pairs -- remove use of double underscores (http://stackoverflow.com/a/224420/148668) -- document inputs and outputs to all functions -- document all member fields -- document all classes -- light direction is backwards -- remove global variables (not threadsafe) -- encapsulate (in igl namespace) and move static/global functions, use lambdas? -- preface macros with "IGL_" -- trackball mouseup captured by tweakbar -- zoom with pan rather than scaling -- refresh draw while resizing -- use constructor initializer list rather than complicated constructor -- support per-element alpha values -+ snap to canonical view key shortcut is not working -+ resize TwBar with window -+ trackball should be able to drag over TwBar -+ don't zoom on horizontal scale -+ remove global `using namespace std` -+ remove `#define IGL_HEADER_ONLY` -+ guard `#undef max` -+ fix all -Wsign-compare -+ missing `#include ` -+ missing `#include ` -+ fix all -Wunused-but-set-variable -+ makefile for libiglviewer.a -+ Viewer.h should include Viewer.cpp -+ depth test for overlays cannot be disabled diff --git a/include/igl/viewer/TextRenderer.cpp b/include/igl/viewer/TextRenderer.cpp deleted file mode 100644 index e3010b542..000000000 --- a/include/igl/viewer/TextRenderer.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2014 Wenzel Jacob -// -// 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 - -#include -#include - -#include - -#define NANOVG_GL3 -#include - - -IGL_INLINE igl::viewer::TextRenderer::TextRenderer(): ctx(nullptr) {} - -IGL_INLINE int igl::viewer::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::viewer::TextRenderer::Shut() -{ - using namespace std; - if(ctx) - nvgDeleteGL3(ctx); - return 0; -} - -IGL_INLINE void igl::viewer::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::viewer::TextRenderer::EndDraw() -{ - using namespace std; - nvgEndFrame(ctx); -} - -IGL_INLINE void igl::viewer::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 diff --git a/include/igl/viewer/TextRenderer.h b/include/igl/viewer/TextRenderer.h deleted file mode 100644 index 1fe992e9c..000000000 --- a/include/igl/viewer/TextRenderer.h +++ /dev/null @@ -1,56 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2014 Wenzel Jacob -// -// 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_VIEWER_TEXT_RENDERER_H -#define IGL_VIEWER_TEXT_RENDERER_H -#ifdef IGL_VIEWER_WITH_NANOGUI - -#include - -#include -#include - -struct NVGcontext; - -namespace igl -{ -namespace viewer -{ - - 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 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 diff --git a/include/igl/viewer/TextRenderer_fonts.h b/include/igl/viewer/TextRenderer_fonts.h deleted file mode 100644 index cd0ace788..000000000 --- a/include/igl/viewer/TextRenderer_fonts.h +++ /dev/null @@ -1,38 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2014 Wenzel Jacob -// -// 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_TEXT_RENDERER_FONTS_H -#define IGL_TEXT_RENDERER_FONTS_H - -#include - -#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 diff --git a/include/igl/viewer/Viewer.cpp b/include/igl/viewer/Viewer.cpp deleted file mode 100644 index 516ef0cdb..000000000 --- a/include/igl/viewer/Viewer.cpp +++ /dev/null @@ -1,1031 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2014 Daniele Panozzo -// -// 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/. - -// Must defined this before including Viewer.h -#define IGL_VIEWER_VIEWER_CPP -#include "Viewer.h" - -#ifdef _WIN32 -# include -# undef max -# undef min -#endif - -#include -#include - -#ifndef __APPLE__ -# define GLEW_STATIC -# include -#endif - -#ifdef __APPLE__ -# include -# define __gl_h_ /* Prevent inclusion of the old gl.h */ -#else -# include -#endif - -#include - -//#define GLFW_INCLUDE_GLU -#if defined(__APPLE__) -#define GLFW_INCLUDE_GLCOREARB -#else -#define GL_GLEXT_PROTOTYPES -#endif - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef IGL_VIEWER_WITH_NANOGUI -# include -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef ENABLE_SERIALIZATION -#include -#endif - -// Internal global variables used for glfw event handling -static igl::viewer::Viewer * __viewer; -static double highdpi = 1; -static double scroll_x = 0; -static double scroll_y = 0; - -static void glfw_mouse_press(GLFWwindow* window, int button, int action, int modifier) -{ - bool tw_used = -#ifdef IGL_VIEWER_WITH_NANOGUI - __viewer->screen->mouseButtonCallbackEvent(button,action,modifier); -#else - false; -#endif - - igl::viewer::Viewer::MouseButton mb; - - if (button == GLFW_MOUSE_BUTTON_1) - mb = igl::viewer::Viewer::MouseButton::Left; - else if (button == GLFW_MOUSE_BUTTON_2) - mb = igl::viewer::Viewer::MouseButton::Right; - else //if (button == GLFW_MOUSE_BUTTON_3) - mb = igl::viewer::Viewer::MouseButton::Middle; - - if (action == GLFW_PRESS) - { - if(!tw_used) - { - __viewer->mouse_down(mb,modifier); - } - } else - { - // Always call mouse_up on up - __viewer->mouse_up(mb,modifier); - } - -} - -static void glfw_error_callback(int error, const char* description) -{ - fputs(description, stderr); -} - -static void glfw_char_mods_callback(GLFWwindow* window, unsigned int codepoint, int modifier) -{ - // TODO: pass to nanogui (although it's also using physical key down/up - // rather than character codes... -#ifdef IGL_VIEWER_WITH_NANOGUI - if(! __viewer->screen->charCallbackEvent(codepoint) ) -#endif - { - __viewer->key_pressed(codepoint, modifier); - } -} - -static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int modifier) -{ - if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) - glfwSetWindowShouldClose(window, GL_TRUE); - -#ifdef IGL_VIEWER_WITH_NANOGUI - if (__viewer->screen->keyCallbackEvent(key,scancode,action,modifier) == false) -#endif - { - if (action == GLFW_PRESS) - __viewer->key_down(key, modifier); - else if(action == GLFW_RELEASE) - __viewer->key_up(key, modifier); - } -} - -static void glfw_window_size(GLFWwindow* window, int width, int height) -{ - int w = width*highdpi; - int h = height*highdpi; - - __viewer->resize(w, h); - - // TODO: repositioning of the nanogui -} - -static void glfw_mouse_move(GLFWwindow* window, double x, double y) -{ - if( -#ifdef IGL_VIEWER_WITH_NANOGUI - __viewer->screen->cursorPosCallbackEvent(x,y) == false && -#endif - true - ) - { - __viewer->mouse_move(x*highdpi, y*highdpi); - } -} - -static void glfw_mouse_scroll(GLFWwindow* window, double x, double y) -{ - using namespace std; - scroll_x += x; - scroll_y += y; - -#ifdef IGL_VIEWER_WITH_NANOGUI - if (__viewer->screen->scrollCallbackEvent(x,y) == false) -#endif - { - __viewer->mouse_scroll(y); - } -} - -static void glfw_drop_callback(GLFWwindow *window,int count,const char **filenames) -{ -#ifdef IGL_VIEWER_WITH_NANOGUI - __viewer->screen->dropCallbackEvent(count,filenames); -#endif -} - -namespace igl -{ -namespace viewer -{ - IGL_INLINE void Viewer::init() - { -#ifdef IGL_VIEWER_WITH_NANOGUI - using namespace nanogui; - - ngui->setFixedSize(Eigen::Vector2i(60,20)); - - // Create nanogui widgets - nanogui::Window *window = ngui->addWindow(Eigen::Vector2i(10,10),"libIGL-Viewer"); - - // ---------------------- LOADING ---------------------- - - #ifdef ENABLE_SERIALIZATION - ngui->addGroup("Workspace"); - ngui->addButton("Load",[&](){this->load_scene();}); - ngui->addButton("Save",[&](){this->save_scene();}); - #endif - - #ifdef ENABLE_IO - ngui->addGroup("Mesh"); - ngui->addButton("Load",[&](){this->open_dialog_load_mesh();}); - ngui->addButton("Save",[&](){this->open_dialog_save_mesh();}); - #endif - - ngui->addGroup("Viewing Options"); - ngui->addButton("Center object",[&](){this->core.align_camera_center(this->data.V,this->data.F);}); - ngui->addButton("Snap canonical view",[&]() - { - this->snap_to_canonical_quaternion(); - }); - ngui->addVariable("Zoom", core.camera_zoom); - ngui->addVariable("Orthographic view", core.orthographic); - - ngui->addGroup("Draw options"); - - ngui->addVariable("Face-based", [&](bool checked) - { - this->data.set_face_based(checked); - },[&]() - { - return this->data.face_based; - }); - - ngui->addVariable("Show texture",core.show_texture); - - ngui->addVariable("Invert normals",[&](bool checked) - { - this->data.dirty |= ViewerData::DIRTY_NORMAL; - this->core.invert_normals = checked; - },[&]() - { - return this->core.invert_normals; - }); - - ngui->addVariable("Show overlay", core.show_overlay); - ngui->addVariable("Show overlay depth", core.show_overlay_depth); - ngui->addVariable("Background", (nanogui::Color &) core.background_color); - ngui->addVariable("Line color", (nanogui::Color &) core.line_color); - ngui->addVariable("Shininess", core.shininess); - - ngui->addGroup("Overlays"); - ngui->addVariable("Wireframe", core.show_lines); - ngui->addVariable("Fill", core.show_faces); - ngui->addVariable("Show vertex labels", core.show_vertid); - ngui->addVariable("Show faces labels", core.show_faceid); - - screen->setVisible(true); - screen->performLayout(); -#endif - - core.init(); - - if (callback_init) - if (callback_init(*this)) - return; - - init_plugins(); - } - - IGL_INLINE Viewer::Viewer() - { -#ifdef IGL_VIEWER_WITH_NANOGUI - ngui = nullptr; - screen = nullptr; -#endif - - // Temporary variables initialization - down = false; - hack_never_moved = true; - scroll_position = 0.0f; - - // Per face - data.set_face_based(false); - - // C-style callbacks - callback_init = nullptr; - callback_pre_draw = nullptr; - callback_post_draw = nullptr; - callback_mouse_down = nullptr; - callback_mouse_up = nullptr; - callback_mouse_move = nullptr; - callback_mouse_scroll = nullptr; - callback_key_down = nullptr; - callback_key_up = nullptr; - - callback_init_data = nullptr; - callback_pre_draw_data = nullptr; - callback_post_draw_data = nullptr; - callback_mouse_down_data = nullptr; - callback_mouse_up_data = nullptr; - callback_mouse_move_data = nullptr; - callback_mouse_scroll_data = nullptr; - callback_key_down_data = nullptr; - callback_key_up_data = nullptr; - -#ifndef IGL_VIEWER_VIEWER_QUIET - const std::string usage(R"(igl::viewer::Viewer usage: - [drag] Rotate scene - A,a Toggle animation (tight draw loop) - F,f Toggle face based - I,i Toggle invert normals - L,l Toggle wireframe - O,o Toggle orthographic/perspective projection - T,t Toggle filled faces - Z Snap to canonical view - [,] Toggle between rotation control types (e.g. trackball, two-axis - valuator with fixed up))" -#ifdef IGL_VIEWER_WITH_NANOGUI - R"( - ; Toggle vertex labels - : Toggle face labels)" -#endif -); - std::cout<init(this); - } - } - - IGL_INLINE Viewer::~Viewer() - { - } - - IGL_INLINE void Viewer::shutdown_plugins() - { - for (unsigned int i = 0; ishutdown(); - } - } - - IGL_INLINE bool Viewer::load_mesh_from_file(const char* mesh_file_name) - { - std::string mesh_file_name_string = std::string(mesh_file_name); - - // first try to load it with a plugin - for (unsigned int i = 0; iload(mesh_file_name_string)) - { - return true; - } - } - - data.clear(); - - size_t last_dot = mesh_file_name_string.rfind('.'); - if (last_dot == std::string::npos) - { - printf("Error: No file extension found in %s\n",mesh_file_name); - return false; - } - - std::string extension = mesh_file_name_string.substr(last_dot+1); - - if (extension == "off" || extension =="OFF") - { - Eigen::MatrixXd V; - Eigen::MatrixXi F; - if (!igl::readOFF(mesh_file_name_string, V, F)) - return false; - data.set_mesh(V,F); - } - else if (extension == "obj" || extension =="OBJ") - { - Eigen::MatrixXd corner_normals; - Eigen::MatrixXi fNormIndices; - - Eigen::MatrixXd UV_V; - Eigen::MatrixXi UV_F; - Eigen::MatrixXd V; - Eigen::MatrixXi F; - - if (!( - igl::readOBJ( - mesh_file_name_string, - V, UV_V, corner_normals, F, UV_F, fNormIndices))) - { - return false; - } - - data.set_mesh(V,F); - data.set_uv(UV_V,UV_F); - - } - else - { - // unrecognized file type - printf("Error: %s is not a recognized file type.\n",extension.c_str()); - return false; - } - - data.compute_normals(); - data.uniform_colors(Eigen::Vector3d(51.0/255.0,43.0/255.0,33.3/255.0), - Eigen::Vector3d(255.0/255.0,228.0/255.0,58.0/255.0), - Eigen::Vector3d(255.0/255.0,235.0/255.0,80.0/255.0)); - if (data.V_uv.rows() == 0) - { - data.grid_texture(); - } - - core.align_camera_center(data.V,data.F); - - for (unsigned int i = 0; ipost_load()) - return true; - - return true; - } - - IGL_INLINE bool Viewer::save_mesh_to_file(const char* mesh_file_name) - { - std::string mesh_file_name_string(mesh_file_name); - - // first try to load it with a plugin - for (unsigned int i = 0; isave(mesh_file_name_string)) - return true; - - size_t last_dot = mesh_file_name_string.rfind('.'); - if (last_dot == std::string::npos) - { - // No file type determined - printf("Error: No file extension found in %s\n",mesh_file_name); - return false; - } - std::string extension = mesh_file_name_string.substr(last_dot+1); - if (extension == "off" || extension =="OFF") - { - return igl::writeOFF(mesh_file_name_string,data.V,data.F); - } - else if (extension == "obj" || extension =="OBJ") - { - Eigen::MatrixXd corner_normals; - Eigen::MatrixXi fNormIndices; - - Eigen::MatrixXd UV_V; - Eigen::MatrixXi UV_F; - - return igl::writeOBJ(mesh_file_name_string, data.V, - data.F, corner_normals, fNormIndices, UV_V, UV_F); - } - else - { - // unrecognized file type - printf("Error: %s is not a recognized file type.\n",extension.c_str()); - return false; - } - return true; - } - - IGL_INLINE bool Viewer::key_pressed(unsigned int unicode_key,int modifiers) - { - if (callback_key_pressed) - if (callback_key_pressed(*this,unicode_key,modifiers)) - return true; - - for (unsigned int i = 0; ikey_pressed(unicode_key, modifiers)) - { - return true; - } - } - - switch(unicode_key) - { - case 'A': - case 'a': - { - core.is_animating = !core.is_animating; - return true; - } - case 'F': - case 'f': - { - data.set_face_based(!data.face_based); - return true; - } - case 'I': - case 'i': - { - data.dirty |= ViewerData::DIRTY_NORMAL; - core.invert_normals = !core.invert_normals; - return true; - } - case 'L': - case 'l': - { - core.show_lines = !core.show_lines; - return true; - } - case 'O': - case 'o': - { - core.orthographic = !core.orthographic; - return true; - } - case 'T': - case 't': - { - core.show_faces = !core.show_faces; - return true; - } - case 'Z': - { - snap_to_canonical_quaternion(); - return true; - } - case '[': - case ']': - { - if(core.rotation_type == ViewerCore::ROTATION_TYPE_TRACKBALL) - { - core.set_rotation_type( - ViewerCore::ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP); - }else - { - core.set_rotation_type(ViewerCore::ROTATION_TYPE_TRACKBALL); - } - return true; - } -#ifdef IGL_VIEWER_WITH_NANOGUI - case ';': - core.show_vertid = !core.show_vertid; - return true; - case ':': - core.show_faceid = !core.show_faceid; - return true; -#endif - default: break;//do nothing - } - return false; - } - - IGL_INLINE bool Viewer::key_down(int key,int modifiers) - { - if (callback_key_down) - if (callback_key_down(*this,key,modifiers)) - return true; - for (unsigned int i = 0; ikey_down(key, modifiers)) - return true; - return false; - } - - IGL_INLINE bool Viewer::key_up(int key,int modifiers) - { - if (callback_key_up) - if (callback_key_up(*this,key,modifiers)) - return true; - - for (unsigned int i = 0; ikey_up(key, modifiers)) - return true; - - return false; - } - - IGL_INLINE bool Viewer::mouse_down(MouseButton button,int modifier) - { - // Remember mouse location at down even if used by callback/plugin - down_mouse_x = current_mouse_x; - down_mouse_y = current_mouse_y; - - if (callback_mouse_down) - if (callback_mouse_down(*this,static_cast(button),modifier)) - return true; - - for (unsigned int i = 0; imouse_down(static_cast(button),modifier)) - return true; - - down = true; - - down_translation = core.model_translation; - - - // Initialization code for the trackball - Eigen::RowVector3d center; - if (data.V.rows() == 0) - { - center << 0,0,0; - }else - { - center = data.V.colwise().sum()/data.V.rows(); - } - - Eigen::Vector3f coord = - igl::project( - Eigen::Vector3f(center(0),center(1),center(2)), - (core.view * core.model).eval(), - core.proj, - core.viewport); - down_mouse_z = coord[2]; - down_rotation = core.trackball_angle; - - mouse_mode = MouseMode::Rotation; - - switch (button) - { - case MouseButton::Left: - mouse_mode = MouseMode::Rotation; - break; - - case MouseButton::Right: - mouse_mode = MouseMode::Translation; - break; - - default: - mouse_mode = MouseMode::None; - break; - } - - return true; - } - - IGL_INLINE bool Viewer::mouse_up(MouseButton button,int modifier) - { - down = false; - - if (callback_mouse_up) - if (callback_mouse_up(*this,static_cast(button),modifier)) - return true; - - for (unsigned int i = 0; imouse_up(static_cast(button),modifier)) - return true; - - mouse_mode = MouseMode::None; - - return true; - } - - IGL_INLINE bool Viewer::mouse_move(int mouse_x,int mouse_y) - { - if(hack_never_moved) - { - down_mouse_x = mouse_x; - down_mouse_y = mouse_y; - hack_never_moved = false; - } - current_mouse_x = mouse_x; - current_mouse_y = mouse_y; - - if (callback_mouse_move) - if (callback_mouse_move(*this,mouse_x,mouse_y)) - return true; - - for (unsigned int i = 0; imouse_move(mouse_x, mouse_y)) - return true; - - if (down) - { - switch (mouse_mode) - { - case MouseMode::Rotation: - { - switch(core.rotation_type) - { - default: - assert(false && "Unknown rotation type"); - case ViewerCore::ROTATION_TYPE_TRACKBALL: - igl::trackball( - core.viewport(2), - core.viewport(3), - 2.0f, - down_rotation, - down_mouse_x, - down_mouse_y, - mouse_x, - mouse_y, - core.trackball_angle); - break; - case ViewerCore::ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP: - igl::two_axis_valuator_fixed_up( - core.viewport(2),core.viewport(3), - 2.0, - down_rotation, - down_mouse_x, down_mouse_y, mouse_x, mouse_y, - core.trackball_angle); - break; - } - //Eigen::Vector4f snapq = core.trackball_angle; - - break; - } - - case MouseMode::Translation: - { - //translation - Eigen::Vector3f pos1 = igl::unproject(Eigen::Vector3f(mouse_x, core.viewport[3] - mouse_y, down_mouse_z), (core.view * core.model).eval(), core.proj, core.viewport); - Eigen::Vector3f pos0 = igl::unproject(Eigen::Vector3f(down_mouse_x, core.viewport[3] - down_mouse_y, down_mouse_z), (core.view * core.model).eval(), core.proj, core.viewport); - - Eigen::Vector3f diff = pos1 - pos0; - core.model_translation = down_translation + Eigen::Vector3f(diff[0],diff[1],diff[2]); - - break; - } - case MouseMode::Zoom: - { - float delta = 0.001f * (mouse_x - down_mouse_x + mouse_y - down_mouse_y); - core.camera_zoom *= 1 + delta; - down_mouse_x = mouse_x; - down_mouse_y = mouse_y; - break; - } - - default: - break; - } - } - return true; - } - - IGL_INLINE bool Viewer::mouse_scroll(float delta_y) - { - scroll_position += delta_y; - - if (callback_mouse_scroll) - if (callback_mouse_scroll(*this,delta_y)) - return true; - - for (unsigned int i = 0; imouse_scroll(delta_y)) - return true; - - // Only zoom if there's actually a change - if(delta_y != 0) - { - float mult = (1.0+((delta_y>0)?1.:-1.)*0.05); - const float min_zoom = 0.1f; - core.camera_zoom = (core.camera_zoom * mult > min_zoom ? core.camera_zoom * mult : min_zoom); - } - return true; - } - - IGL_INLINE void Viewer::draw() - { - using namespace std; - using namespace Eigen; - - core.clear_framebuffers(); - - if (callback_pre_draw) - if (callback_pre_draw(*this)) - return; - - for (unsigned int i = 0; ipre_draw()) - return; - - core.draw(data,opengl); - - if (callback_post_draw) - if (callback_post_draw(*this)) - return; - - for (unsigned int i = 0; ipost_draw()) - break; - -#ifdef IGL_VIEWER_WITH_NANOGUI - screen->drawContents(); - screen->drawWidgets(); -#endif - } - - IGL_INLINE bool Viewer::save_scene() - { - std::string fname = igl::file_dialog_save(); - if (fname.length() == 0) - return false; - -#ifdef ENABLE_SERIALIZATION - - igl::serialize(core,"Core",fname.c_str(),true); - -#ifndef ENABLE_SERIALIZATION_CORE_ONLY - igl::serialize(data,"Data",fname.c_str()); - for(unsigned int i = 0; i plugin_name,fname.c_str()); -#endif - -#endif - - return true; - } - - IGL_INLINE bool Viewer::load_scene() - { - std::string fname = igl::file_dialog_open(); - if(fname.length() == 0) - return false; - - return load_scene(fname); - } - - IGL_INLINE bool Viewer::load_scene(std::string fname) - { -#ifdef ENABLE_SERIALIZATION - - igl::deserialize(core,"Core",fname.c_str()); - -#ifndef ENABLE_SERIALIZATION_CORE_ONLY - igl::deserialize(data,"Data",fname.c_str()); - for(unsigned int i = 0; i plugin_name,fname.c_str()); -#endif - -#endif - - return true; - } - - IGL_INLINE void Viewer::resize(int w,int h) - { - core.viewport = Eigen::Vector4f(0,0,w,h); - } - - IGL_INLINE void Viewer::snap_to_canonical_quaternion() - { - Eigen::Quaternionf snapq = this->core.trackball_angle; - igl::snap_to_canonical_view_quat(snapq,1.0f,this->core.trackball_angle); - } - - IGL_INLINE void Viewer::open_dialog_load_mesh() - { - std::string fname = igl::file_dialog_open(); - - if (fname.length() == 0) - return; - - this->load_mesh_from_file(fname.c_str()); - } - - IGL_INLINE void Viewer::open_dialog_save_mesh() - { - std::string fname = igl::file_dialog_save(); - - if(fname.length() == 0) - return; - - this->save_mesh_to_file(fname.c_str()); - } - - - IGL_INLINE int Viewer::launch_init(bool resizable,bool fullscreen) - { - glfwSetErrorCallback(glfw_error_callback); - if (!glfwInit()) - return EXIT_FAILURE; - - glfwWindowHint(GLFW_SAMPLES, 8); - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); - - #ifdef __APPLE__ - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); - #endif - - if(fullscreen) - { - GLFWmonitor *monitor = glfwGetPrimaryMonitor(); - const GLFWvidmode *mode = glfwGetVideoMode(monitor); - window = glfwCreateWindow(mode->width,mode->height,"libigl viewer",monitor,nullptr); - } - else - { - window = glfwCreateWindow(1280,800,"libigl viewer",nullptr,nullptr); - } - - if (!window) - { - glfwTerminate(); - return EXIT_FAILURE; - } - - glfwMakeContextCurrent(window); - - #ifndef __APPLE__ - glewExperimental = true; - GLenum err = glewInit(); - if(GLEW_OK != err) - { - /* Problem: glewInit failed, something is seriously wrong. */ - fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); - } - glGetError(); // pull and savely ignonre unhandled errors like GL_INVALID_ENUM - fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); - #endif - - #if defined(DEBUG) || defined(_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)); - #endif - - glfwSetInputMode(window,GLFW_CURSOR,GLFW_CURSOR_NORMAL); - - // Initialize FormScreen -#ifdef IGL_VIEWER_WITH_NANOGUI - screen = new nanogui::Screen(); - screen->initialize(window, false); - ngui = new nanogui::FormHelper(screen); -#endif - - __viewer = this; - - // Register callbacks - glfwSetKeyCallback(window, glfw_key_callback); - glfwSetCursorPosCallback(window,glfw_mouse_move); - glfwSetWindowSizeCallback(window,glfw_window_size); - glfwSetMouseButtonCallback(window,glfw_mouse_press); - glfwSetScrollCallback(window,glfw_mouse_scroll); - glfwSetCharModsCallback(window,glfw_char_mods_callback); - glfwSetDropCallback(window,glfw_drop_callback); - - // Handle retina displays (windows and mac) - int width, height; - glfwGetFramebufferSize(window, &width, &height); - - int width_window, height_window; - glfwGetWindowSize(window, &width_window, &height_window); - - highdpi = width/width_window; - - glfw_window_size(window,width_window,height_window); - - opengl.init(); - - core.align_camera_center(data.V,data.F); - - // Initialize IGL viewer - init(); - return EXIT_SUCCESS; - } - - IGL_INLINE bool Viewer::launch_rendering(bool loop) - { - // glfwMakeContextCurrent(window); - - // Rendering loop - while (!glfwWindowShouldClose(window)) - { - double tic = get_seconds(); - draw(); - - glfwSwapBuffers(window); - if(core.is_animating) - { - glfwPollEvents(); - // In microseconds - double duration = 1000000.*(get_seconds()-tic); - const double min_duration = 1000000./core.animation_max_fps; - if(duration -// -// 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_VIEWER_VIEWER_H -#define IGL_VIEWER_VIEWER_H - -#ifndef IGL_OPENGL_4 -#define IGL_OPENGL_4 -#endif - -#include -#include -#include - -#include -#include - -#include - -#include "OpenGL_shader.h" -#include "OpenGL_state.h" -#include "ViewerCore.h" -#include "ViewerData.h" -#include "ViewerPlugin.h" - -#define IGL_MOD_SHIFT 0x0001 -#define IGL_MOD_CONTROL 0x0002 -#define IGL_MOD_ALT 0x0004 -#define IGL_MOD_SUPER 0x0008 - -#ifdef IGL_VIEWER_WITH_NANOGUI -namespace nanogui { class FormHelper; class Screen; } -#endif - -class GLFWwindow; - -namespace igl -{ -namespace viewer -{ - // GLFW-based mesh viewer - class Viewer - { - public: - GLFWwindow* window; - - IGL_INLINE int launch(bool resizable = true,bool fullscreen = false); - IGL_INLINE int launch_init(bool resizable = true,bool fullscreen = false); - IGL_INLINE bool launch_rendering(bool loop = true); - IGL_INLINE void launch_shut(); - - IGL_INLINE void init(); - - // Stores all the viewing options - ViewerCore core; - - // Stores all the data that should be visualized - ViewerData data; - - // Stores the vbos indices and opengl related settings - OpenGL_state opengl; - - // List of registered plugins - std::vector plugins; - IGL_INLINE void init_plugins(); - IGL_INLINE void shutdown_plugins(); - - // Temporary data stored when the mouse button is pressed - Eigen::Quaternionf down_rotation; - int current_mouse_x; - int current_mouse_y; - int down_mouse_x; - int down_mouse_y; - float down_mouse_z; - Eigen::Vector3f down_translation; - bool down; - bool hack_never_moved; - -#ifdef IGL_VIEWER_WITH_NANOGUI - nanogui::FormHelper* ngui; - nanogui::Screen* screen; -#endif - - // Keep track of the global position of the scrollwheel - float scroll_position; - - // UI Enumerations - enum class MouseButton {Left, Middle, Right}; - enum class MouseMode { None, Rotation, Zoom, Pan, Translation} mouse_mode; - - Viewer(); - ~Viewer(); - - // Mesh IO - IGL_INLINE bool load_mesh_from_file(const char* mesh_file_name); - IGL_INLINE bool save_mesh_to_file(const char* mesh_file_name); - - // Callbacks - IGL_INLINE bool key_pressed(unsigned int unicode_key,int modifier); - IGL_INLINE bool key_down(int key,int modifier); - IGL_INLINE bool key_up(int key,int modifier); - - IGL_INLINE bool mouse_down(MouseButton button,int modifier); - IGL_INLINE bool mouse_up(MouseButton button,int modifier); - - IGL_INLINE bool mouse_move(int mouse_x,int mouse_y); - IGL_INLINE bool mouse_scroll(float delta_y); - - // Scene IO - IGL_INLINE bool load_scene(); - IGL_INLINE bool load_scene(std::string fname); - IGL_INLINE bool save_scene(); - - // Draw everything - IGL_INLINE void draw(); - - // OpenGL context resize - IGL_INLINE void resize(int w,int h); - - // Helper functions - IGL_INLINE void snap_to_canonical_quaternion(); - IGL_INLINE void open_dialog_load_mesh(); - IGL_INLINE void open_dialog_save_mesh(); - - // C++-style functions - // - // Returns **true** if action should be cancelled. - std::function callback_init; - std::function callback_pre_draw; - std::function callback_post_draw; - std::function callback_mouse_down; - std::function callback_mouse_up; - std::function callback_mouse_move; - std::function callback_mouse_scroll; - std::function callback_key_pressed; - // THESE SHOULD BE DEPRECATED: - std::function callback_key_down; - std::function callback_key_up; - - // Pointers to per-callback data - void* callback_init_data; - void* callback_pre_draw_data; - void* callback_post_draw_data; - void* callback_mouse_down_data; - void* callback_mouse_up_data; - void* callback_mouse_move_data; - void* callback_mouse_scroll_data; - void* callback_key_pressed_data; - void* callback_key_down_data; - void* callback_key_up_data; - - public: - EIGEN_MAKE_ALIGNED_OPERATOR_NEW - }; - -} // end namespace -} // end namespace - -#ifndef IGL_STATIC_LIBRARY -# include "Viewer.cpp" -#endif - -#endif diff --git a/include/igl/viewer/ViewerCore.cpp b/include/igl/viewer/ViewerCore.cpp deleted file mode 100644 index 91946b8a9..000000000 --- a/include/igl/viewer/ViewerCore.cpp +++ /dev/null @@ -1,449 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2014 Daniele Panozzo -// -// 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 "ViewerCore.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -IGL_INLINE void igl::viewer::ViewerCore::align_camera_center( - const Eigen::MatrixXd& V, - const Eigen::MatrixXi& F) -{ - if(V.rows() == 0) - return; - - get_scale_and_shift_to_fit_mesh(V,F,model_zoom,model_translation); - // Rather than crash on empty mesh... - if(V.size() > 0) - { - object_scale = (V.colwise().maxCoeff() - V.colwise().minCoeff()).norm(); - } -} - -IGL_INLINE void igl::viewer::ViewerCore::get_scale_and_shift_to_fit_mesh( - const Eigen::MatrixXd& V, - const Eigen::MatrixXi& F, - float& zoom, - Eigen::Vector3f& shift) -{ - if (V.rows() == 0) - return; - - Eigen::MatrixXd BC; - if (F.rows() <= 1) - { - BC = V; - } else - { - igl::barycenter(V,F,BC); - } - return get_scale_and_shift_to_fit_mesh(BC,zoom,shift); -} - -IGL_INLINE void igl::viewer::ViewerCore::align_camera_center( - const Eigen::MatrixXd& V) -{ - if(V.rows() == 0) - return; - - get_scale_and_shift_to_fit_mesh(V,model_zoom,model_translation); - // Rather than crash on empty mesh... - if(V.size() > 0) - { - object_scale = (V.colwise().maxCoeff() - V.colwise().minCoeff()).norm(); - } -} - -IGL_INLINE void igl::viewer::ViewerCore::get_scale_and_shift_to_fit_mesh( - const Eigen::MatrixXd& V, - float& zoom, - Eigen::Vector3f& shift) -{ - if (V.rows() == 0) - return; - - auto min_point = V.colwise().minCoeff(); - auto max_point = V.colwise().maxCoeff(); - auto centroid = (0.5*(min_point + max_point)).eval(); - shift.setConstant(0); - shift.head(centroid.size()) = -centroid.cast(); - zoom = 2.0 / (max_point-min_point).array().abs().maxCoeff(); -} - - -IGL_INLINE void igl::viewer::ViewerCore::clear_framebuffers() -{ - glClearColor(background_color[0], - background_color[1], - background_color[2], - 1.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); -} - -IGL_INLINE void igl::viewer::ViewerCore::draw( - ViewerData& data, - OpenGL_state& opengl, - bool update_matrices) -{ - using namespace std; - using namespace Eigen; - - if (depth_test) - glEnable(GL_DEPTH_TEST); - else - glDisable(GL_DEPTH_TEST); - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - /* Bind and potentially refresh mesh/line/point data */ - if (data.dirty) - { - opengl.set_data(data, invert_normals); - data.dirty = ViewerData::DIRTY_NONE; - } - opengl.bind_mesh(); - - // Initialize uniform - glViewport(viewport(0), viewport(1), viewport(2), viewport(3)); - - if(update_matrices) - { - model = Eigen::Matrix4f::Identity(); - view = Eigen::Matrix4f::Identity(); - proj = Eigen::Matrix4f::Identity(); - - // Set view - look_at( camera_eye, camera_center, camera_up, view); - - float width = viewport(2); - float height = viewport(3); - - // Set projection - if (orthographic) - { - float length = (camera_eye - camera_center).norm(); - float h = tan(camera_view_angle/360.0 * M_PI) * (length); - ortho(-h*width/height, h*width/height, -h, h, camera_dnear, camera_dfar,proj); - } - else - { - float fH = tan(camera_view_angle / 360.0 * M_PI) * camera_dnear; - float fW = fH * (double)width/(double)height; - frustum(-fW, fW, -fH, fH, camera_dnear, camera_dfar,proj); - } - // end projection - - // Set model transformation - float mat[16]; - igl::quat_to_mat(trackball_angle.coeffs().data(), mat); - - for (unsigned i=0;i<4;++i) - for (unsigned j=0;j<4;++j) - model(i,j) = mat[i+4*j]; - - // Why not just use Eigen::Transform for model...? - model.topLeftCorner(3,3)*=camera_zoom; - model.topLeftCorner(3,3)*=model_zoom; - model.col(3).head(3) += model.topLeftCorner(3,3)*model_translation; - } - - // Send transformations to the GPU - GLint modeli = opengl.shader_mesh.uniform("model"); - GLint viewi = opengl.shader_mesh.uniform("view"); - GLint proji = opengl.shader_mesh.uniform("proj"); - glUniformMatrix4fv(modeli, 1, GL_FALSE, model.data()); - glUniformMatrix4fv(viewi, 1, GL_FALSE, view.data()); - glUniformMatrix4fv(proji, 1, GL_FALSE, proj.data()); - - // Light parameters - GLint specular_exponenti = opengl.shader_mesh.uniform("specular_exponent"); - GLint light_position_worldi = opengl.shader_mesh.uniform("light_position_world"); - GLint lighting_factori = opengl.shader_mesh.uniform("lighting_factor"); - GLint fixed_colori = opengl.shader_mesh.uniform("fixed_color"); - GLint texture_factori = opengl.shader_mesh.uniform("texture_factor"); - - glUniform1f(specular_exponenti, shininess); - Vector3f rev_light = -1.*light_position; - glUniform3fv(light_position_worldi, 1, rev_light.data()); - glUniform1f(lighting_factori, lighting_factor); // enables lighting - glUniform4f(fixed_colori, 0.0, 0.0, 0.0, 0.0); - - if (data.V.rows()>0) - { - // Render fill - if (show_faces) - { - // Texture - glUniform1f(texture_factori, show_texture ? 1.0f : 0.0f); - opengl.draw_mesh(true); - glUniform1f(texture_factori, 0.0f); - } - - // Render wireframe - if (show_lines) - { - glLineWidth(line_width); - glUniform4f(fixed_colori, line_color[0], line_color[1], - line_color[2], 1.0f); - opengl.draw_mesh(false); - glUniform4f(fixed_colori, 0.0f, 0.0f, 0.0f, 0.0f); - } - -#ifdef IGL_VIEWER_WITH_NANOGUI - if (show_vertid) - { - textrenderer.BeginDraw(view*model, proj, viewport, object_scale); - for (int i=0; i 0) - { - opengl.bind_overlay_lines(); - modeli = opengl.shader_overlay_lines.uniform("model"); - viewi = opengl.shader_overlay_lines.uniform("view"); - proji = opengl.shader_overlay_lines.uniform("proj"); - - glUniformMatrix4fv(modeli, 1, GL_FALSE, model.data()); - glUniformMatrix4fv(viewi, 1, GL_FALSE, view.data()); - glUniformMatrix4fv(proji, 1, GL_FALSE, proj.data()); - // This must be enabled, otherwise glLineWidth has no effect - glEnable(GL_LINE_SMOOTH); - glLineWidth(line_width); - - opengl.draw_overlay_lines(); - } - - if (data.points.rows() > 0) - { - opengl.bind_overlay_points(); - modeli = opengl.shader_overlay_points.uniform("model"); - viewi = opengl.shader_overlay_points.uniform("view"); - proji = opengl.shader_overlay_points.uniform("proj"); - - glUniformMatrix4fv(modeli, 1, GL_FALSE, model.data()); - glUniformMatrix4fv(viewi, 1, GL_FALSE, view.data()); - glUniformMatrix4fv(proji, 1, GL_FALSE, proj.data()); - glPointSize(point_size); - - opengl.draw_overlay_points(); - } - -#ifdef IGL_VIEWER_WITH_NANOGUI - if (data.labels_positions.rows() > 0) - { - textrenderer.BeginDraw(view*model, proj, viewport, object_scale); - for (int i=0; i& R, - Eigen::Matrix& G, - Eigen::Matrix& B, - Eigen::Matrix& A) -{ - assert(R.rows() == G.rows() && G.rows() == B.rows() && B.rows() == A.rows()); - assert(R.cols() == G.cols() && G.cols() == B.cols() && B.cols() == A.cols()); - - unsigned x = R.rows(); - unsigned y = R.cols(); - - // Create frame buffer - GLuint frameBuffer; - glGenFramebuffers(1, &frameBuffer); - glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer); - - // Create texture to hold color buffer - GLuint texColorBuffer; - glGenTextures(1, &texColorBuffer); - glBindTexture(GL_TEXTURE_2D, texColorBuffer); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texColorBuffer, 0); - - // Create Renderbuffer Object to hold depth and stencil buffers - GLuint rboDepthStencil; - glGenRenderbuffers(1, &rboDepthStencil); - glBindRenderbuffer(GL_RENDERBUFFER, rboDepthStencil); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, x, y); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rboDepthStencil); - - assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); - - glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer); - - // Clear the buffer - glClearColor(background_color(0), background_color(1), background_color(2), 0.f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - // Save old viewport - Eigen::Vector4f viewport_ori = viewport; - viewport << 0,0,x,y; - - // Draw - draw(data,opengl,update_matrices); - - // Restore viewport - viewport = viewport_ori; - - // Copy back in the given Eigen matrices - GLubyte* pixels = (GLubyte*)calloc(x*y*4,sizeof(GLubyte)); - glReadPixels - ( - 0, 0, - x, y, - GL_RGBA, GL_UNSIGNED_BYTE, pixels - ); - - int count = 0; - for (unsigned j=0; j -// -// 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_VIEWER_VIEWER_CORE_H -#define IGL_VIEWER_VIEWER_CORE_H - -#ifdef IGL_VIEWER_WITH_NANOGUI -#include -#endif -#include -#include - -#include -#include -#include - -namespace igl -{ -namespace viewer -{ - -// Basic class of the 3D mesh viewer -// TODO: write documentation - -class ViewerCore -{ -public: - IGL_INLINE ViewerCore(); - - // Initialization - IGL_INLINE void init(); - - // Shutdown - IGL_INLINE void shut(); - - // Serialization code - IGL_INLINE void InitSerialization(); - - - // ------------------- Camera control functions - - // Adjust the view to see the entire model - IGL_INLINE void align_camera_center( - const Eigen::MatrixXd& V, - const Eigen::MatrixXi& F); - - // Determines how much to zoom and shift such that the mesh fills the unit - // box (centered at the origin) - IGL_INLINE void get_scale_and_shift_to_fit_mesh( - const Eigen::MatrixXd& V, - const Eigen::MatrixXi& F, - float & zoom, - Eigen::Vector3f& shift); - - // Adjust the view to see the entire model - IGL_INLINE void align_camera_center( - const Eigen::MatrixXd& V); - - // Determines how much to zoom and shift such that the mesh fills the unit - // box (centered at the origin) - IGL_INLINE void get_scale_and_shift_to_fit_mesh( - const Eigen::MatrixXd& V, - float & zoom, - Eigen::Vector3f& shift); - - // ------------------- Drawing functions - - // Clear the frame buffers - IGL_INLINE void clear_framebuffers(); - - // Draw everything - IGL_INLINE void draw(ViewerData& data, OpenGL_state& opengl, bool update_matrices = true); - IGL_INLINE void draw_buffer( - ViewerData& data, - OpenGL_state& opengl, - bool update_matrices, - Eigen::Matrix& R, - Eigen::Matrix& G, - Eigen::Matrix& B, - Eigen::Matrix& A); - - // Trackball angle (quaternion) - enum RotationType - { - ROTATION_TYPE_TRACKBALL = 0, - ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP = 1, - NUM_ROTATION_TYPES = 2 - }; - IGL_INLINE void set_rotation_type(const RotationType & value); - - // ------------------- Properties - -#ifdef IGL_VIEWER_WITH_NANOGUI - // Text rendering helper - TextRenderer textrenderer; -#endif - - // Shape material - float shininess; - - // Colors - Eigen::Vector4f background_color; - Eigen::Vector4f line_color; - - // Lighting - Eigen::Vector3f light_position; - float lighting_factor; - - RotationType rotation_type; - - Eigen::Quaternionf trackball_angle; - - // Model viewing parameters - float model_zoom; - Eigen::Vector3f model_translation; - - // Model viewing paramters (uv coordinates) - float model_zoom_uv; - Eigen::Vector3f model_translation_uv; - - // Camera parameters - float camera_zoom; - bool orthographic; - Eigen::Vector3f camera_eye; - Eigen::Vector3f camera_up; - Eigen::Vector3f camera_center; - float camera_view_angle; - float camera_dnear; - float camera_dfar; - - // Visualization options - bool show_overlay; - bool show_overlay_depth; - bool show_texture; - bool show_faces; - bool show_lines; - bool show_vertid; - bool show_faceid; - bool invert_normals; - bool depth_test; - - // Point size / line width - float point_size; - float line_width; - - // Animation - bool is_animating; - double animation_max_fps; - - // Caches the two-norm between the min/max point of the bounding box - float object_scale; - - // Viewport size - Eigen::Vector4f viewport; - - // Save the OpenGL transformation matrices used for the previous rendering pass - Eigen::Matrix4f view; - Eigen::Matrix4f model; - Eigen::Matrix4f proj; - public: - EIGEN_MAKE_ALIGNED_OPERATOR_NEW -}; - -} -} - -#ifdef ENABLE_SERIALIZATION -#include -namespace igl { - namespace serialization { - - inline void serialization(bool s, igl::viewer::ViewerCore& obj, std::vector& buffer) - { - SERIALIZE_MEMBER(shininess); - - SERIALIZE_MEMBER(background_color); - SERIALIZE_MEMBER(line_color); - - SERIALIZE_MEMBER(light_position); - SERIALIZE_MEMBER(lighting_factor); - - SERIALIZE_MEMBER(trackball_angle); - SERIALIZE_MEMBER(rotation_type); - - SERIALIZE_MEMBER(model_zoom); - SERIALIZE_MEMBER(model_translation); - - SERIALIZE_MEMBER(model_zoom_uv); - SERIALIZE_MEMBER(model_translation_uv); - - SERIALIZE_MEMBER(camera_zoom); - SERIALIZE_MEMBER(orthographic); - SERIALIZE_MEMBER(camera_view_angle); - SERIALIZE_MEMBER(camera_dnear); - SERIALIZE_MEMBER(camera_dfar); - SERIALIZE_MEMBER(camera_eye); - SERIALIZE_MEMBER(camera_center); - SERIALIZE_MEMBER(camera_up); - - SERIALIZE_MEMBER(show_faces); - SERIALIZE_MEMBER(show_lines); - SERIALIZE_MEMBER(invert_normals); - SERIALIZE_MEMBER(show_overlay); - SERIALIZE_MEMBER(show_overlay_depth); - SERIALIZE_MEMBER(show_vertid); - SERIALIZE_MEMBER(show_faceid); - SERIALIZE_MEMBER(show_texture); - SERIALIZE_MEMBER(depth_test); - - SERIALIZE_MEMBER(point_size); - SERIALIZE_MEMBER(line_width); - SERIALIZE_MEMBER(is_animating); - SERIALIZE_MEMBER(animation_max_fps); - - SERIALIZE_MEMBER(object_scale); - - SERIALIZE_MEMBER(viewport); - SERIALIZE_MEMBER(view); - SERIALIZE_MEMBER(model); - SERIALIZE_MEMBER(proj); - } - - template<> - inline void serialize(const igl::viewer::ViewerCore& obj, std::vector& buffer) - { - serialization(true, const_cast(obj), buffer); - } - - template<> - inline void deserialize(igl::viewer::ViewerCore& obj, const std::vector& buffer) - { - serialization(false, obj, const_cast&>(buffer)); - } - } -} -#endif - -#ifndef IGL_STATIC_LIBRARY -# include "ViewerCore.cpp" -#endif - -#endif diff --git a/include/igl/viewer/ViewerData.cpp b/include/igl/viewer/ViewerData.cpp deleted file mode 100644 index ead5c5edd..000000000 --- a/include/igl/viewer/ViewerData.cpp +++ /dev/null @@ -1,422 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2014 Daniele Panozzo -// -// 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 "ViewerData.h" - -#include - -#include -#include -#include -#include - -IGL_INLINE igl::viewer::ViewerData::ViewerData() -: dirty(DIRTY_ALL) -{ - clear(); -}; - -IGL_INLINE void igl::viewer::ViewerData::set_face_based(bool newvalue) -{ - if (face_based != newvalue) - { - face_based = newvalue; - dirty = DIRTY_ALL; - } -} - -// Helpers that draws the most common meshes -IGL_INLINE void igl::viewer::ViewerData::set_mesh(const Eigen::MatrixXd& _V, const Eigen::MatrixXi& _F) -{ - using namespace std; - - Eigen::MatrixXd V_temp; - - // If V only has two columns, pad with a column of zeros - if (_V.cols() == 2) - { - V_temp = Eigen::MatrixXd::Zero(_V.rows(),3); - V_temp.block(0,0,_V.rows(),2) = _V; - } - else - V_temp = _V; - - if (V.rows() == 0 && F.rows() == 0) - { - V = V_temp; - F = _F; - - compute_normals(); - uniform_colors( - Eigen::Vector3d(GOLD_AMBIENT[0], GOLD_AMBIENT[1], GOLD_AMBIENT[2]), - Eigen::Vector3d(GOLD_DIFFUSE[0], GOLD_DIFFUSE[1], GOLD_DIFFUSE[2]), - Eigen::Vector3d(GOLD_SPECULAR[0], GOLD_SPECULAR[1], GOLD_SPECULAR[2])); - - grid_texture(); - } - else - { - if (_V.rows() == V.rows() && _F.rows() == F.rows()) - { - V = V_temp; - F = _F; - } - else - cerr << "ERROR (set_mesh): The new mesh has a different number of vertices/faces. Please clear the mesh before plotting."<0 && C.cols() == 1) - { - Eigen::MatrixXd C3; - igl::parula(C,true,C3); - return set_colors(C3); - } - // Ambient color should be darker color - const auto ambient = [](const MatrixXd & C)->MatrixXd - { - MatrixXd T = 0.1*C; - T.col(3) = C.col(3); - return T; - }; - // Specular color should be a less saturated and darker color: dampened - // highlights - const auto specular = [](const MatrixXd & C)->MatrixXd - { - const double grey = 0.3; - MatrixXd T = grey+0.1*(C.array()-grey); - T.col(3) = C.col(3); - return T; - }; - if (C.rows() == 1) - { - for (unsigned i=0;i& R, - const Eigen::Matrix& G, - const Eigen::Matrix& B) -{ - texture_R = R; - texture_G = G; - texture_B = B; - texture_A = Eigen::Matrix::Constant(R.rows(),R.cols(),255); - dirty |= DIRTY_TEXTURE; -} - -IGL_INLINE void igl::viewer::ViewerData::set_texture( - const Eigen::Matrix& R, - const Eigen::Matrix& G, - const Eigen::Matrix& B, - const Eigen::Matrix& A) -{ - texture_R = R; - texture_G = G; - texture_B = B; - texture_A = A; - dirty |= DIRTY_TEXTURE; -} - -IGL_INLINE void igl::viewer::ViewerData::set_points( - const Eigen::MatrixXd& P, - const Eigen::MatrixXd& C) -{ - // clear existing points - points.resize(0,0); - add_points(P,C); -} - -IGL_INLINE void igl::viewer::ViewerData::add_points(const Eigen::MatrixXd& P, const Eigen::MatrixXd& C) -{ - Eigen::MatrixXd P_temp; - - // If P only has two columns, pad with a column of zeros - if (P.cols() == 2) - { - P_temp = Eigen::MatrixXd::Zero(P.rows(),3); - P_temp.block(0,0,P.rows(),2) = P; - } - else - P_temp = P; - - int lastid = points.rows(); - points.conservativeResize(points.rows() + P_temp.rows(),6); - for (unsigned i=0; i=size2 && j>=size2)) - texture_R(i,j) = 255; - } - } - - texture_G = texture_R; - texture_B = texture_R; - texture_A = Eigen::Matrix::Constant(texture_R.rows(),texture_R.cols(),255); - dirty |= DIRTY_TEXTURE; -} diff --git a/include/igl/viewer/ViewerData.h b/include/igl/viewer/ViewerData.h deleted file mode 100644 index 76743f198..000000000 --- a/include/igl/viewer/ViewerData.h +++ /dev/null @@ -1,254 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2014 Daniele Panozzo -// -// 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_VIEWER_VIEWER_DATA_H -#define IGL_VIEWER_VIEWER_DATA_H - -#include -#include - -#include - -#include - -namespace igl -{ -namespace viewer -{ - -// TODO: write documentation - -class ViewerData -{ -public: - ViewerData(); - - enum DirtyFlags - { - DIRTY_NONE = 0x0000, - DIRTY_POSITION = 0x0001, - DIRTY_UV = 0x0002, - DIRTY_NORMAL = 0x0004, - DIRTY_AMBIENT = 0x0008, - DIRTY_DIFFUSE = 0x0010, - DIRTY_SPECULAR = 0x0020, - DIRTY_TEXTURE = 0x0040, - DIRTY_FACE = 0x0080, - DIRTY_MESH = 0x00FF, - DIRTY_OVERLAY_LINES = 0x0100, - DIRTY_OVERLAY_POINTS = 0x0200, - DIRTY_ALL = 0x03FF - }; - - // Empy all fields - IGL_INLINE void clear(); - - // Change the visualization mode, invalidating the cache if necessary - IGL_INLINE void set_face_based(bool newvalue); - - // Helpers that can draw the most common meshes - IGL_INLINE void set_mesh(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F); - IGL_INLINE void set_vertices(const Eigen::MatrixXd& V); - IGL_INLINE void set_normals(const Eigen::MatrixXd& N); - - // Set the color of the mesh - // - // Inputs: - // C #V|#F|1 by 3 list of colors - IGL_INLINE void set_colors(const Eigen::MatrixXd &C); - // Set per-vertex UV coordinates - // - // Inputs: - // UV #V by 2 list of UV coordinates (indexed by F) - IGL_INLINE void set_uv(const Eigen::MatrixXd& UV); - // Set per-corner UV coordinates - // - // Inputs: - // UV_V #UV by 2 list of UV coordinates - // UV_F #F by 3 list of UV indices into UV_V - IGL_INLINE void set_uv(const Eigen::MatrixXd& UV_V, const Eigen::MatrixXi& UV_F); - // Set the texture associated with the mesh. - // - // Inputs: - // R width by height image matrix of red channel - // G width by height image matrix of green channel - // B width by height image matrix of blue channel - // - IGL_INLINE void set_texture( - const Eigen::Matrix& R, - const Eigen::Matrix& G, - const Eigen::Matrix& B); - - // Set the texture associated with the mesh. - // - // Inputs: - // R width by height image matrix of red channel - // G width by height image matrix of green channel - // B width by height image matrix of blue channel - // A width by height image matrix of alpha channel - // - IGL_INLINE void set_texture( - const Eigen::Matrix& R, - const Eigen::Matrix& G, - const Eigen::Matrix& B, - const Eigen::Matrix& A); - - // Sets points given a list of point vertices. In constrast to `set_points` - // this will (purposefully) clober existing points. - // - // Inputs: - // P #P by 3 list of vertex positions - // C #P|1 by 3 color(s) - IGL_INLINE void set_points( - const Eigen::MatrixXd& P, - const Eigen::MatrixXd& C); - IGL_INLINE void add_points(const Eigen::MatrixXd& P, const Eigen::MatrixXd& C); - // Sets edges given a list of edge vertices and edge indices. In constrast - // to `add_edges` this will (purposefully) clober existing edges. - // - // Inputs: - // P #P by 3 list of vertex positions - // E #E by 2 list of edge indices into P - // C #E|1 by 3 color(s) - IGL_INLINE void set_edges (const Eigen::MatrixXd& P, const Eigen::MatrixXi& E, const Eigen::MatrixXd& C); - IGL_INLINE void add_edges (const Eigen::MatrixXd& P1, const Eigen::MatrixXd& P2, const Eigen::MatrixXd& C); - IGL_INLINE void add_label (const Eigen::VectorXd& P, const std::string& str); - - // Computes the normals of the mesh - IGL_INLINE void compute_normals(); - - // Assigns uniform colors to all faces/vertices - IGL_INLINE void uniform_colors( - Eigen::Vector3d ambient, - Eigen::Vector3d diffuse, - Eigen::Vector3d specular); - - // Assigns uniform colors to all faces/vertices - IGL_INLINE void uniform_colors( - Eigen::Vector4d ambient, - Eigen::Vector4d diffuse, - Eigen::Vector4d specular); - - // Generates a default grid texture - IGL_INLINE void grid_texture(); - - Eigen::MatrixXd V; // Vertices of the current mesh (#V x 3) - Eigen::MatrixXi F; // Faces of the mesh (#F x 3) - - // Per face attributes - Eigen::MatrixXd F_normals; // One normal per face - - Eigen::MatrixXd F_material_ambient; // Per face ambient color - Eigen::MatrixXd F_material_diffuse; // Per face diffuse color - Eigen::MatrixXd F_material_specular; // Per face specular color - - // Per vertex attributes - Eigen::MatrixXd V_normals; // One normal per vertex - - Eigen::MatrixXd V_material_ambient; // Per vertex ambient color - Eigen::MatrixXd V_material_diffuse; // Per vertex diffuse color - Eigen::MatrixXd V_material_specular; // Per vertex specular color - - // UV parametrization - Eigen::MatrixXd V_uv; // UV vertices - Eigen::MatrixXi F_uv; // optional faces for UVs - - // Texture - Eigen::Matrix texture_R; - Eigen::Matrix texture_G; - Eigen::Matrix texture_B; - Eigen::Matrix texture_A; - - // Overlays - - // Lines plotted over the scene - // (Every row contains 9 doubles in the following format S_x, S_y, S_z, T_x, T_y, T_z, C_r, C_g, C_b), - // with S and T the coordinates of the two vertices of the line in global coordinates, and C the color in floating point rgb format - Eigen::MatrixXd lines; - - // Points plotted over the scene - // (Every row contains 6 doubles in the following format P_x, P_y, P_z, C_r, C_g, C_b), - // with P the position in global coordinates of the center of the point, and C the color in floating point rgb format - Eigen::MatrixXd points; - - // Text labels plotted over the scene - // Textp contains, in the i-th row, the position in global coordinates where the i-th label should be anchored - // Texts contains in the i-th position the text of the i-th label - Eigen::MatrixXd labels_positions; - std::vector labels_strings; - - // Marks dirty buffers that need to be uploaded to OpenGL - uint32_t dirty; - - // Enable per-face or per-vertex properties - bool face_based; - /*********************************/ -}; - -} -} - -#ifdef ENABLE_SERIALIZATION -#include -namespace igl { - namespace serialization { - - inline void serialization(bool s, igl::viewer::ViewerData& obj, std::vector& buffer) - { - SERIALIZE_MEMBER(V); - SERIALIZE_MEMBER(F); - - SERIALIZE_MEMBER(F_normals); - SERIALIZE_MEMBER(F_material_ambient); - SERIALIZE_MEMBER(F_material_diffuse); - SERIALIZE_MEMBER(F_material_specular); - - SERIALIZE_MEMBER(V_normals); - SERIALIZE_MEMBER(V_material_ambient); - SERIALIZE_MEMBER(V_material_diffuse); - SERIALIZE_MEMBER(V_material_specular); - - SERIALIZE_MEMBER(V_uv); - SERIALIZE_MEMBER(F_uv); - - SERIALIZE_MEMBER(texture_R); - SERIALIZE_MEMBER(texture_G); - SERIALIZE_MEMBER(texture_B); - SERIALIZE_MEMBER(texture_A); - - SERIALIZE_MEMBER(lines); - SERIALIZE_MEMBER(points); - - SERIALIZE_MEMBER(labels_positions); - SERIALIZE_MEMBER(labels_strings); - - SERIALIZE_MEMBER(dirty); - - SERIALIZE_MEMBER(face_based); - } - - template<> - inline void serialize(const igl::viewer::ViewerData& obj, std::vector& buffer) - { - serialization(true, const_cast(obj), buffer); - } - - template<> - inline void deserialize(igl::viewer::ViewerData& obj, const std::vector& buffer) - { - serialization(false, obj, const_cast&>(buffer)); - obj.dirty = igl::viewer::ViewerData::DIRTY_ALL; - } - } -} -#endif - -#ifndef IGL_STATIC_LIBRARY -# include "ViewerData.cpp" -#endif - -#endif diff --git a/include/igl/viewer/ViewerPlugin.h b/include/igl/viewer/ViewerPlugin.h deleted file mode 100644 index 316ea6b60..000000000 --- a/include/igl/viewer/ViewerPlugin.h +++ /dev/null @@ -1,176 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2014 Daniele Panozzo -// -// 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_VIEWER_VIEWER_PLUGIN_H -#define IGL_VIEWER_VIEWER_PLUGIN_H - -// TODO: -// * create plugins/skeleton.h -// * pass time in draw function -// * remove Preview3D from comments -// * clean comments -#include -#include -#include - -namespace igl -{ -namespace viewer -{ - -// Abstract class for plugins -// All plugins MUST have this class as their parent and may implement any/all -// the callbacks marked `virtual` here. -// -// /////For an example of a basic plugins see plugins/skeleton.h -// -// Return value of callbacks: returning true to any of the callbacks tells -// Viewer that the event has been handled and that it should not be passed to -// other plugins or to other internal functions of Viewer - -// Forward declaration of the viewer -class Viewer; - -class ViewerPlugin -{ -public: - IGL_INLINE ViewerPlugin() - {plugin_name = "dummy";} - - virtual ~ViewerPlugin(){} - - // This function is called when the viewer is initialized (no mesh will be loaded at this stage) - IGL_INLINE virtual void init(Viewer *_viewer) - { - viewer = _viewer; - } - - // This function is called before shutdown - IGL_INLINE virtual void shutdown() - { - } - - // This function is called before a mesh is loaded - IGL_INLINE virtual bool load(std::string filename) - { - return false; - } - - // This function is called before a mesh is saved - IGL_INLINE virtual bool save(std::string filename) - { - return false; - } - - // This function is called when the scene is serialized - IGL_INLINE virtual bool serialize(std::vector& buffer) const - { - return false; - } - - // This function is called when the scene is deserialized - IGL_INLINE virtual bool deserialize(const std::vector& buffer) - { - return false; - } - - // Runs immediately after a new mesh has been loaded. - IGL_INLINE virtual bool post_load() - { - return false; - } - - // This function is called before the draw procedure of Preview3D - IGL_INLINE virtual bool pre_draw() - { - return false; - } - - // This function is called after the draw procedure of Preview3D - IGL_INLINE virtual bool post_draw() - { - return false; - } - - // 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; - IGL_INLINE virtual bool mouse_down(int button, int modifier) - { - return false; - } - - // 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; - IGL_INLINE virtual bool mouse_up(int button, int modifier) - { - return false; - } - - // 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 - IGL_INLINE virtual bool mouse_move(int mouse_x, int mouse_y) - { - return false; - } - - // This function is called every time the scroll wheel is moved - // Note: this callback is not working with every glut implementation - IGL_INLINE virtual bool mouse_scroll(float delta_y) - { - return false; - } - - // This function is called when a keyboard key is pressed. Unlike key_down - // this will reveal the actual character being sent (not just the physical - // key) - // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT; - IGL_INLINE virtual bool key_pressed(unsigned int key, int modifiers) - { - return false; - } - - // This function is called when a keyboard key is down - // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT; - IGL_INLINE virtual bool key_down(int key, int modifiers) - { - return false; - } - - // 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; - IGL_INLINE virtual bool key_up(int key, int modifiers) - { - return false; - } - - std::string plugin_name; -protected: - // Pointer to the main Viewer class - Viewer *viewer; -}; - -#ifdef ENABLE_SERIALIZATION -namespace serialization -{ - inline void serialize(const ViewerPlugin& obj,std::vector& buffer) - { - obj.serialize(buffer); - } - - inline void deserialize(ViewerPlugin& obj,const std::vector& buffer) - { - obj.deserialize(buffer); - } -} -#endif - -} -} - -#endif diff --git a/tutorial/102_DrawMesh/main.cpp b/tutorial/102_DrawMesh/main.cpp index fe5355e8d..0ec952c80 100755 --- a/tutorial/102_DrawMesh/main.cpp +++ b/tutorial/102_DrawMesh/main.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include "tutorial_shared_path.h" Eigen::MatrixXd V; @@ -11,7 +11,7 @@ int main(int argc, char *argv[]) igl::readOFF(TUTORIAL_SHARED_PATH "/bunny.off", V, F); // Plot the mesh - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V, F); viewer.launch(); } diff --git a/tutorial/103_Events/main.cpp b/tutorial/103_Events/main.cpp index fdcf62708..047e211af 100755 --- a/tutorial/103_Events/main.cpp +++ b/tutorial/103_Events/main.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include "tutorial_shared_path.h" @@ -7,7 +7,7 @@ Eigen::MatrixXd V1,V2; Eigen::MatrixXi F1,F2; // This function is called every time a keyboard button is pressed -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier) +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier) { std::cout<<"Key: "< -#include +#include #include #include "tutorial_shared_path.h" @@ -13,7 +13,7 @@ int main(int argc, char *argv[]) igl::readOFF(TUTORIAL_SHARED_PATH "/screwdriver.off", V, F); // Plot the mesh - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V, F); // Use the z coordinate as a scalar field over the surface diff --git a/tutorial/105_Overlays/main.cpp b/tutorial/105_Overlays/main.cpp index 2f0644ab5..5ea27b01a 100755 --- a/tutorial/105_Overlays/main.cpp +++ b/tutorial/105_Overlays/main.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include "tutorial_shared_path.h" @@ -44,7 +44,7 @@ int main(int argc, char *argv[]) 7 ,3; // Plot the mesh - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V, F); // Plot the corners of the bounding box as points diff --git a/tutorial/106_ViewerMenu/main.cpp b/tutorial/106_ViewerMenu/main.cpp index 56219caef..81c3896ad 100755 --- a/tutorial/106_ViewerMenu/main.cpp +++ b/tutorial/106_ViewerMenu/main.cpp @@ -9,7 +9,7 @@ int main() #else #include -#include +#include #include #include #include @@ -28,10 +28,10 @@ int main(int argc, char *argv[]) igl::readOFF(TUTORIAL_SHARED_PATH "/bunny.off", V, F); // Init the viewer - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; // Extend viewer menu - viewer.callback_init = [&](igl::viewer::Viewer& viewer) + viewer.callback_init = [&](igl::opengl::glfw::Viewer& viewer) { // Add new group viewer.ngui->addGroup("New Group"); diff --git a/tutorial/201_Normals/main.cpp b/tutorial/201_Normals/main.cpp index 8c0e0fdb8..2d7c88e6c 100755 --- a/tutorial/201_Normals/main.cpp +++ b/tutorial/201_Normals/main.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -15,7 +15,7 @@ Eigen::MatrixXd N_corners; // This function is called every time a keyboard button is pressed -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier) +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier) { switch(key) { @@ -48,7 +48,7 @@ int main(int argc, char *argv[]) igl::per_corner_normals(V,F,20,N_corners); // Plot the mesh - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.callback_key_down = &key_down; viewer.core.show_lines = false; viewer.data.set_mesh(V, F); diff --git a/tutorial/202_GaussianCurvature/main.cpp b/tutorial/202_GaussianCurvature/main.cpp index a2a9a4f4f..cc193453f 100644 --- a/tutorial/202_GaussianCurvature/main.cpp +++ b/tutorial/202_GaussianCurvature/main.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include "tutorial_shared_path.h" @@ -29,7 +29,7 @@ int main(int argc, char *argv[]) igl::jet(K,true,C); // Plot the mesh with pseudocolors - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V, F); viewer.data.set_colors(C); viewer.launch(); diff --git a/tutorial/203_CurvatureDirections/main.cpp b/tutorial/203_CurvatureDirections/main.cpp index 8c24e4c48..603ea2cf1 100755 --- a/tutorial/203_CurvatureDirections/main.cpp +++ b/tutorial/203_CurvatureDirections/main.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include "tutorial_shared_path.h" Eigen::MatrixXd V; @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) // mean curvature H = 0.5*(PV1+PV2); - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V, F); diff --git a/tutorial/204_Gradient/main.cpp b/tutorial/204_Gradient/main.cpp index 799260b0c..5ead97293 100755 --- a/tutorial/204_Gradient/main.cpp +++ b/tutorial/204_Gradient/main.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include "tutorial_shared_path.h" @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) // Compute gradient magnitude const VectorXd GU_mag = GU.rowwise().norm(); - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V, F); // Compute pseudocolor for original function diff --git a/tutorial/205_Laplacian/main.cpp b/tutorial/205_Laplacian/main.cpp index a9609387d..90e8dbd2c 100755 --- a/tutorial/205_Laplacian/main.cpp +++ b/tutorial/205_Laplacian/main.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include "tutorial_shared_path.h" @@ -16,7 +16,7 @@ Eigen::MatrixXd V,U; Eigen::MatrixXi F; Eigen::SparseMatrix L; -igl::viewer::Viewer viewer; +igl::opengl::glfw::Viewer viewer; int main(int argc, char *argv[]) { @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) K = -G.transpose() * T * G; cout<<"|K-L|: "<<(K-L).norm()<bool + const auto &key_down = [](igl::opengl::glfw::Viewer &viewer,unsigned char key,int mod)->bool { switch(key) { diff --git a/tutorial/301_Slice/main.cpp b/tutorial/301_Slice/main.cpp index 1852504cf..3c57c169b 100644 --- a/tutorial/301_Slice/main.cpp +++ b/tutorial/301_Slice/main.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include "tutorial_shared_path.h" @@ -34,7 +34,7 @@ int main(int argc, char *argv[]) igl::slice_into(R,K,1,C); // Plot the mesh with pseudocolors - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V, F); viewer.data.set_colors(C); viewer.launch(); diff --git a/tutorial/302_Sort/main.cpp b/tutorial/302_Sort/main.cpp index 04e65c23a..c6502e3ae 100644 --- a/tutorial/302_Sort/main.cpp +++ b/tutorial/302_Sort/main.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include "tutorial_shared_path.h" @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) igl::jet(J,true,C); // Plot the mesh with pseudocolors - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V, F); viewer.data.set_colors(C); viewer.launch(); diff --git a/tutorial/303_LaplaceEquation/main.cpp b/tutorial/303_LaplaceEquation/main.cpp index d219704de..d4c160c17 100644 --- a/tutorial/303_LaplaceEquation/main.cpp +++ b/tutorial/303_LaplaceEquation/main.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include "tutorial_shared_path.h" @@ -65,7 +65,7 @@ int main(int argc, char *argv[]) igl::jet(Z,true,C); // Plot the mesh with pseudocolors - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V, F); viewer.core.show_lines = false; viewer.data.set_colors(C); diff --git a/tutorial/304_LinearEqualityConstraints/main.cpp b/tutorial/304_LinearEqualityConstraints/main.cpp index 8fcb84922..fa71c747c 100644 --- a/tutorial/304_LinearEqualityConstraints/main.cpp +++ b/tutorial/304_LinearEqualityConstraints/main.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include "tutorial_shared_path.h" @@ -72,13 +72,13 @@ int main(int argc, char *argv[]) igl::jet(Z_const,min_z,max_z,data.C_const); // Plot the mesh with pseudocolors - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V, F); viewer.core.show_lines = false; viewer.data.set_colors(data.C); viewer.callback_key_down = - [](igl::viewer::Viewer& viewer,unsigned char key,int mod)->bool + [](igl::opengl::glfw::Viewer& viewer,unsigned char key,int mod)->bool { if(key == ' ') { diff --git a/tutorial/305_QuadraticProgramming/main.cpp b/tutorial/305_QuadraticProgramming/main.cpp index 082f2fc06..b9189437e 100644 --- a/tutorial/305_QuadraticProgramming/main.cpp +++ b/tutorial/305_QuadraticProgramming/main.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include "tutorial_shared_path.h" @@ -14,7 +14,7 @@ Eigen::VectorXi b; Eigen::VectorXd B,bc,lx,ux,Beq,Bieq,Z; Eigen::SparseMatrix Q,Aeq,Aieq; -void solve(igl::viewer::Viewer &viewer) +void solve(igl::opengl::glfw::Viewer &viewer) { using namespace std; igl::active_set_params as; @@ -26,7 +26,7 @@ void solve(igl::viewer::Viewer &viewer) viewer.data.set_colors(C); } -bool key_down(igl::viewer::Viewer &viewer, unsigned char key, int mod) +bool key_down(igl::opengl::glfw::Viewer &viewer, unsigned char key, int mod) { switch(key) { @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) igl::readOFF(TUTORIAL_SHARED_PATH "/cheburashka.off",V,F); // Plot the mesh - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V, F); viewer.core.show_lines = false; viewer.callback_key_down = &key_down; diff --git a/tutorial/306_EigenDecomposition/main.cpp b/tutorial/306_EigenDecomposition/main.cpp index 0d0551207..4c298966c 100644 --- a/tutorial/306_EigenDecomposition/main.cpp +++ b/tutorial/306_EigenDecomposition/main.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include #include @@ -38,8 +38,8 @@ int main(int argc, char * argv[]) } U = ((U.array()-U.minCoeff())/(U.maxCoeff()-U.minCoeff())).eval(); - igl::viewer::Viewer viewer; - viewer.callback_key_down = [&](igl::viewer::Viewer & viewer,unsigned char key,int)->bool + igl::opengl::glfw::Viewer viewer; + viewer.callback_key_down = [&](igl::opengl::glfw::Viewer & viewer,unsigned char key,int)->bool { switch(key) { diff --git a/tutorial/401_BiharmonicDeformation/main.cpp b/tutorial/401_BiharmonicDeformation/main.cpp index 56fb61e1e..84a79d83a 100755 --- a/tutorial/401_BiharmonicDeformation/main.cpp +++ b/tutorial/401_BiharmonicDeformation/main.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include "tutorial_shared_path.h" @@ -15,7 +15,7 @@ Eigen::VectorXd Z; Eigen::MatrixXi F; Eigen::VectorXi b; -bool pre_draw(igl::viewer::Viewer & viewer) +bool pre_draw(igl::opengl::glfw::Viewer & viewer) { using namespace Eigen; // Determine boundary conditions @@ -41,7 +41,7 @@ bool pre_draw(igl::viewer::Viewer & viewer) return false; } -bool key_down(igl::viewer::Viewer &viewer, unsigned char key, int mods) +bool key_down(igl::opengl::glfw::Viewer &viewer, unsigned char key, int mods) { switch(key) { @@ -109,7 +109,7 @@ int main(int argc, char *argv[]) } // Plot the mesh with pseudocolors - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(U, F); viewer.core.show_lines = false; viewer.data.set_colors(C); diff --git a/tutorial/402_PolyharmonicDeformation/main.cpp b/tutorial/402_PolyharmonicDeformation/main.cpp index f3cc007ff..cefc948fb 100755 --- a/tutorial/402_PolyharmonicDeformation/main.cpp +++ b/tutorial/402_PolyharmonicDeformation/main.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include #include "tutorial_shared_path.h" @@ -16,7 +16,7 @@ Eigen::MatrixXi F; Eigen::VectorXi b; Eigen::VectorXd bc; -bool pre_draw(igl::viewer::Viewer & viewer) +bool pre_draw(igl::opengl::glfw::Viewer & viewer) { using namespace Eigen; if(resolve) @@ -35,7 +35,7 @@ bool pre_draw(igl::viewer::Viewer & viewer) return false; } -bool key_down(igl::viewer::Viewer &viewer, unsigned char key, int mods) +bool key_down(igl::opengl::glfw::Viewer &viewer, unsigned char key, int mods) { switch(key) { @@ -93,7 +93,7 @@ int main(int argc, char *argv[]) } // Plot the mesh with pseudocolors - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(U, F); viewer.core.show_lines = false; viewer.data.set_colors(C); diff --git a/tutorial/403_BoundedBiharmonicWeights/main.cpp b/tutorial/403_BoundedBiharmonicWeights/main.cpp index c42108529..146f9fa3d 100755 --- a/tutorial/403_BoundedBiharmonicWeights/main.cpp +++ b/tutorial/403_BoundedBiharmonicWeights/main.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include //#include @@ -45,7 +45,7 @@ RotationList pose; double anim_t = 1.0; double anim_t_dir = -0.03; -bool pre_draw(igl::viewer::Viewer & viewer) +bool pre_draw(igl::opengl::glfw::Viewer & viewer) { using namespace Eigen; using namespace std; @@ -88,14 +88,14 @@ bool pre_draw(igl::viewer::Viewer & viewer) return false; } -void set_color(igl::viewer::Viewer &viewer) +void set_color(igl::opengl::glfw::Viewer &viewer) { Eigen::MatrixXd C; igl::jet(W.col(selected).eval(),true,C); viewer.data.set_colors(C); } -bool key_down(igl::viewer::Viewer &viewer, unsigned char key, int mods) +bool key_down(igl::opengl::glfw::Viewer &viewer, unsigned char key, int mods) { switch(key) { @@ -163,7 +163,7 @@ int main(int argc, char *argv[]) igl::lbs_matrix(V,W,M); // Plot the mesh with pseudocolors - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(U, F); set_color(viewer); viewer.data.set_edges(C,BE,sea_green); diff --git a/tutorial/404_DualQuaternionSkinning/main.cpp b/tutorial/404_DualQuaternionSkinning/main.cpp index 0d348345d..1c573014e 100755 --- a/tutorial/404_DualQuaternionSkinning/main.cpp +++ b/tutorial/404_DualQuaternionSkinning/main.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include @@ -32,7 +32,7 @@ double anim_t_dir = 0.015; bool use_dqs = false; bool recompute = true; -bool pre_draw(igl::viewer::Viewer & viewer) +bool pre_draw(igl::opengl::glfw::Viewer & viewer) { using namespace Eigen; using namespace std; @@ -92,7 +92,7 @@ bool pre_draw(igl::viewer::Viewer & viewer) return false; } -bool key_down(igl::viewer::Viewer &viewer, unsigned char key, int mods) +bool key_down(igl::opengl::glfw::Viewer &viewer, unsigned char key, int mods) { recompute = true; switch(key) @@ -130,7 +130,7 @@ int main(int argc, char *argv[]) igl::lbs_matrix(V,W,M); // Plot the mesh with pseudocolors - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(U, F); viewer.data.set_edges(C,BE,sea_green); viewer.core.show_lines = false; diff --git a/tutorial/405_AsRigidAsPossible/main.cpp b/tutorial/405_AsRigidAsPossible/main.cpp index 73ffccadc..eaedae05a 100755 --- a/tutorial/405_AsRigidAsPossible/main.cpp +++ b/tutorial/405_AsRigidAsPossible/main.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include @@ -32,7 +32,7 @@ double anim_t = 0.0; double anim_t_dir = 0.03; igl::ARAPData arap_data; -bool pre_draw(igl::viewer::Viewer & viewer) +bool pre_draw(igl::opengl::glfw::Viewer & viewer) { using namespace Eigen; using namespace std; @@ -77,7 +77,7 @@ bool pre_draw(igl::viewer::Viewer & viewer) return false; } -bool key_down(igl::viewer::Viewer &viewer, unsigned char key, int mods) +bool key_down(igl::opengl::glfw::Viewer &viewer, unsigned char key, int mods) { switch(key) { @@ -122,7 +122,7 @@ int main(int argc, char *argv[]) } // Plot the mesh with pseudocolors - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(U, F); viewer.data.set_colors(C); viewer.callback_pre_draw = &pre_draw; diff --git a/tutorial/406_FastAutomaticSkinningTransformations/main.cpp b/tutorial/406_FastAutomaticSkinningTransformations/main.cpp index bc948120e..022a3ffb5 100755 --- a/tutorial/406_FastAutomaticSkinningTransformations/main.cpp +++ b/tutorial/406_FastAutomaticSkinningTransformations/main.cpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include @@ -51,7 +51,7 @@ enum ModeType NUM_MODE_TYPES = 4 } mode = MODE_TYPE_ARAP; -bool pre_draw(igl::viewer::Viewer & viewer) +bool pre_draw(igl::opengl::glfw::Viewer & viewer) { using namespace Eigen; using namespace std; @@ -113,7 +113,7 @@ bool pre_draw(igl::viewer::Viewer & viewer) return false; } -bool key_down(igl::viewer::Viewer &viewer, unsigned char key, int mods) +bool key_down(igl::opengl::glfw::Viewer &viewer, unsigned char key, int mods) { switch(key) { @@ -204,7 +204,7 @@ int main(int argc, char *argv[]) bbd = (V.colwise().maxCoeff()- V.colwise().minCoeff()).norm(); // Plot the mesh with pseudocolors - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(U, F); viewer.data.add_points(igl::slice(V,b,1),sea_green); viewer.core.show_lines = false; diff --git a/tutorial/407_BiharmonicCoordinates/main.cpp b/tutorial/407_BiharmonicCoordinates/main.cpp index 90cdb7487..e15d099e1 100755 --- a/tutorial/407_BiharmonicCoordinates/main.cpp +++ b/tutorial/407_BiharmonicCoordinates/main.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -11,7 +12,7 @@ #include #include #include -#include +#include #include #include #include @@ -100,7 +101,7 @@ int main(int argc, char * argv[]) // Random initial velocities to wiggle things arap_data.vel = MatrixXd::Random(n,3); - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; // Create one huge mesh containing both meshes igl::cat(1,low.U,high.U,scene.U); igl::cat(1,low.F,MatrixXi(high.F.array()+low.V.rows()),scene.F); @@ -113,7 +114,7 @@ int main(int argc, char * argv[]) viewer.data.set_colors(C); viewer.callback_key_pressed = - [&](igl::viewer::Viewer & viewer,unsigned int key,int mods)->bool + [&](igl::opengl::glfw::Viewer & viewer,unsigned int key,int mods)->bool { switch(key) { @@ -127,7 +128,7 @@ int main(int argc, char * argv[]) return true; } }; - viewer.callback_pre_draw = [&](igl::viewer::Viewer & viewer)->bool + viewer.callback_pre_draw = [&](igl::opengl::glfw::Viewer & viewer)->bool { glEnable(GL_CULL_FACE); if(viewer.core.is_animating) @@ -164,6 +165,6 @@ int main(int argc, char * argv[]) 'r' to reset positions )"; viewer.core.rotation_type = - igl::viewer::ViewerCore::ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP; + igl::opengl::ViewerCore::ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP; viewer.launch(); } diff --git a/tutorial/501_HarmonicParam/main.cpp b/tutorial/501_HarmonicParam/main.cpp index 866244710..50846e0d0 100755 --- a/tutorial/501_HarmonicParam/main.cpp +++ b/tutorial/501_HarmonicParam/main.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include "tutorial_shared_path.h" @@ -10,7 +10,7 @@ Eigen::MatrixXd V; Eigen::MatrixXi F; Eigen::MatrixXd V_uv; -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier) +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier) { if (key == '1') { @@ -50,7 +50,7 @@ int main(int argc, char *argv[]) V_uv *= 5; // Plot the mesh - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V, F); viewer.data.set_uv(V_uv); viewer.callback_key_down = &key_down; diff --git a/tutorial/502_LSCMParam/main.cpp b/tutorial/502_LSCMParam/main.cpp index 04536ec87..7d82c020c 100755 --- a/tutorial/502_LSCMParam/main.cpp +++ b/tutorial/502_LSCMParam/main.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include @@ -10,7 +10,7 @@ Eigen::MatrixXd V; Eigen::MatrixXi F; Eigen::MatrixXd V_uv; -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier) +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier) { if (key == '1') @@ -54,7 +54,7 @@ int main(int argc, char *argv[]) V_uv *= 5; // Plot the mesh - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V, F); viewer.data.set_uv(V_uv); viewer.callback_key_down = &key_down; diff --git a/tutorial/503_ARAPParam/main.cpp b/tutorial/503_ARAPParam/main.cpp index fcda0ff5a..539a48459 100755 --- a/tutorial/503_ARAPParam/main.cpp +++ b/tutorial/503_ARAPParam/main.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include "tutorial_shared_path.h" @@ -14,7 +14,7 @@ Eigen::MatrixXd initial_guess; bool show_uv = false; -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier) +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier) { if (key == '1') show_uv = false; @@ -76,7 +76,7 @@ int main(int argc, char *argv[]) V_uv *= 20; // Plot the mesh - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V, F); viewer.data.set_uv(V_uv); viewer.callback_key_down = &key_down; diff --git a/tutorial/504_NRosyDesign/main.cpp b/tutorial/504_NRosyDesign/main.cpp index adc4fde44..0bdeb1e36 100755 --- a/tutorial/504_NRosyDesign/main.cpp +++ b/tutorial/504_NRosyDesign/main.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include "tutorial_shared_path.h" @@ -55,7 +55,7 @@ void representative_to_nrosy( // Plots the mesh with an N-RoSy field and its singularities on top // The constrained faces (b) are colored in red. void plot_mesh_nrosy( - igl::viewer::Viewer& viewer, + igl::opengl::glfw::Viewer& viewer, Eigen::MatrixXd& V, Eigen::MatrixXi& F, int N, @@ -101,7 +101,7 @@ void plot_mesh_nrosy( } // It allows to change the degree of the field when a number is pressed -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier) +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier) { using namespace Eigen; using namespace std; @@ -131,7 +131,7 @@ int main(int argc, char *argv[]) bc.resize(1,3); bc << 1,1,1; - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; // Interpolate the field and plot key_down(viewer, '4', 0); diff --git a/tutorial/505_MIQ/main.cpp b/tutorial/505_MIQ/main.cpp index 9f9815036..c2d12dd21 100755 --- a/tutorial/505_MIQ/main.cpp +++ b/tutorial/505_MIQ/main.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include "tutorial_shared_path.h" @@ -79,7 +79,7 @@ void line_texture(Eigen::Matrix &te texture_B = texture_R; } -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier) +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier) { if (key == 'E') { @@ -314,7 +314,7 @@ igl::copyleft::comiso::miq(V, false); // Plot the mesh - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; // Plot the original mesh with a texture parametrization key_down(viewer,'7',0); diff --git a/tutorial/506_FrameField/main.cpp b/tutorial/506_FrameField/main.cpp index 26212fe8d..e50591eac 100755 --- a/tutorial/506_FrameField/main.cpp +++ b/tutorial/506_FrameField/main.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include "tutorial_shared_path.h" @@ -68,7 +68,7 @@ void line_texture(Eigen::Matrix &te texture_B = texture_R; } -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier) +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier) { using namespace std; using namespace Eigen; @@ -245,7 +245,7 @@ int main(int argc, char *argv[]) false, 2); - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; // Plot the original mesh with a texture parametrization key_down(viewer,'6',0); diff --git a/tutorial/507_PolyVectorField/main.cpp b/tutorial/507_PolyVectorField/main.cpp index 8f11a2592..328ffbe2b 100755 --- a/tutorial/507_PolyVectorField/main.cpp +++ b/tutorial/507_PolyVectorField/main.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include @@ -70,7 +70,7 @@ Eigen::VectorXd random_constraints(const return r; } -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier) +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier) { using namespace std; using namespace Eigen; @@ -144,7 +144,7 @@ int main(int argc, char *argv[]) // Make the example deterministic srand(0); - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V, F); viewer.callback_key_down = &key_down; viewer.core.show_lines = false; diff --git a/tutorial/508_ConjugateField/main.cpp b/tutorial/508_ConjugateField/main.cpp index aaf6bdf22..0855cd98e 100644 --- a/tutorial/508_ConjugateField/main.cpp +++ b/tutorial/508_ConjugateField/main.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include @@ -34,7 +34,7 @@ Eigen::VectorXd conjugacy_s; Eigen::VectorXd conjugacy_c; -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier) +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier) { using namespace std; using namespace Eigen; @@ -173,7 +173,7 @@ int main(int argc, char *argv[]) pvV << igl::dot_row(Vc,B1), igl::dot_row(Vc,B2); csdata.evaluateConjugacy(pvU, pvV, conjugacy_c); // Launch the viewer - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.core.invert_normals = true; viewer.core.show_lines = false; viewer.core.show_texture = false; diff --git a/tutorial/509_Planarization/main.cpp b/tutorial/509_Planarization/main.cpp index 8373f1371..2501b1225 100755 --- a/tutorial/509_Planarization/main.cpp +++ b/tutorial/509_Planarization/main.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include @@ -28,7 +28,7 @@ Eigen::MatrixXd PQC0plan, PQC1plan, PQC2plan, PQC3plan; double global_scale; //TODO: not used -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier) +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier) { using namespace std; using namespace Eigen; @@ -107,7 +107,7 @@ int main(int argc, char *argv[]) igl::slice( VQCplan, FQC.col(3).eval(), 1, PQC3plan); // Launch the viewer - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; key_down(viewer,'2',0); viewer.core.invert_normals = true; viewer.core.show_lines = false; diff --git a/tutorial/510_Integrable/main.cpp b/tutorial/510_Integrable/main.cpp index c70c44826..925a6d84d 100644 --- a/tutorial/510_Integrable/main.cpp +++ b/tutorial/510_Integrable/main.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include @@ -222,7 +222,7 @@ bc<< } -void drawCuts(igl::viewer::Viewer& viewer, +void drawCuts(igl::opengl::glfw::Viewer& viewer, const Eigen::MatrixXi &cuts) { int maxCutNum = cuts.sum(); @@ -240,7 +240,7 @@ void drawCuts(igl::viewer::Viewer& viewer, viewer.data.add_edges(start, end , Eigen::RowVector3d(1.,0,1.)); } -void drawField(igl::viewer::Viewer &viewer, +void drawField(igl::opengl::glfw::Viewer &viewer, const Eigen::MatrixXd &field, const Eigen::RowVector3d &color) { @@ -252,7 +252,7 @@ void drawField(igl::viewer::Viewer &viewer, } } -void drawConstraints(igl::viewer::Viewer &viewer) +void drawConstraints(igl::opengl::glfw::Viewer &viewer) { for (int n=0; n<2; ++n) { @@ -311,7 +311,7 @@ void colorEdgeMeshFaces(const Eigen::VectorXd &values, } -void update_display(igl::viewer::Viewer& viewer) +void update_display(igl::opengl::glfw::Viewer& viewer) { using namespace std; using namespace Eigen; @@ -517,7 +517,7 @@ void update_display(igl::viewer::Viewer& viewer) } -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier) +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier) { if (key == '1') @@ -707,7 +707,7 @@ int main(int argc, char *argv[]) cerr<<"Done. Press keys 1-0 for various visualizations, 'A' to improve integrability." < #include -#include +#include #include #include #include @@ -71,7 +71,7 @@ Eigen::VectorXd random_constraints(const return r; } -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier) +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier) { using namespace std; using namespace Eigen; @@ -172,7 +172,7 @@ int main(int argc, char *argv[]) // Make the example deterministic srand(0); - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V, F); viewer.callback_key_down = &key_down; viewer.core.show_lines = false; diff --git a/tutorial/602_Matlab/main.cpp b/tutorial/602_Matlab/main.cpp index 202242803..4bbc1f500 100755 --- a/tutorial/602_Matlab/main.cpp +++ b/tutorial/602_Matlab/main.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include "tutorial_shared_path.h" @@ -17,7 +17,7 @@ Engine* engine; // Eigenvectors of the laplacian Eigen::MatrixXd EV; -void plotEV(igl::viewer::Viewer& viewer, int id) +void plotEV(igl::opengl::glfw::Viewer& viewer, int id) { Eigen::VectorXd v = EV.col(id); v = v.array() - v.minCoeff(); @@ -36,7 +36,7 @@ void plotEV(igl::viewer::Viewer& viewer, int id) } // This function is called every time a keyboard button is pressed -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier) +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier) { if (key >= '1' && key <= '9') plotEV(viewer,(key - '1') + 1); @@ -72,7 +72,7 @@ int main(int argc, char *argv[]) igl::matlab::mlgetmatrix(&engine,"EV",EV); // Plot the mesh - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.callback_key_down = &key_down; viewer.data.set_mesh(V, F); diff --git a/tutorial/604_Triangle/main.cpp b/tutorial/604_Triangle/main.cpp index ea5d60056..0171e4795 100755 --- a/tutorial/604_Triangle/main.cpp +++ b/tutorial/604_Triangle/main.cpp @@ -1,4 +1,4 @@ -#include +#include #include // Input polygon Eigen::MatrixXd V; @@ -31,7 +31,7 @@ int main(int argc, char *argv[]) igl::triangle::triangulate(V,E,H,"a0.005q",V2,F2); // Plot the generated mesh - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V2,F2); viewer.launch(); } diff --git a/tutorial/605_Tetgen/main.cpp b/tutorial/605_Tetgen/main.cpp index edc109acf..0aecb70fc 100755 --- a/tutorial/605_Tetgen/main.cpp +++ b/tutorial/605_Tetgen/main.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -16,7 +16,7 @@ Eigen::MatrixXi TT; Eigen::MatrixXi TF; // This function is called every time a keyboard button is pressed -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier) +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier) { using namespace std; using namespace Eigen; @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) igl::barycenter(TV,TT,B); // Plot the generated mesh - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.callback_key_down = &key_down; key_down(viewer,'5',0); viewer.launch(); diff --git a/tutorial/606_AmbientOcclusion/main.cpp b/tutorial/606_AmbientOcclusion/main.cpp index 17a997f74..dd0376803 100755 --- a/tutorial/606_AmbientOcclusion/main.cpp +++ b/tutorial/606_AmbientOcclusion/main.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include "tutorial_shared_path.h" @@ -14,7 +14,7 @@ Eigen::MatrixXi F; Eigen::VectorXd AO; // It allows to change the degree of the field when a number is pressed -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier) +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier) { using namespace Eigen; using namespace std; @@ -69,7 +69,7 @@ int main(int argc, char *argv[]) AO = 1.0 - AO.array(); // Show mesh - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V, F); viewer.callback_key_down = &key_down; key_down(viewer,'2',0); diff --git a/tutorial/607_ScreenCapture/main.cpp b/tutorial/607_ScreenCapture/main.cpp index d0846c4eb..942a67364 100755 --- a/tutorial/607_ScreenCapture/main.cpp +++ b/tutorial/607_ScreenCapture/main.cpp @@ -1,12 +1,12 @@ #include -#include +#include #include #include "tutorial_shared_path.h" #include #include // This function is called every time a keyboard button is pressed -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier) +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier) { if (key == '1') { @@ -75,7 +75,7 @@ int main(int argc, char *argv[]) std::cerr << "Press 2 to load the saved png and use it as a texture." << std::endl; // Plot the mesh and register the callback - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.callback_key_down = &key_down; viewer.data.set_mesh(V, F); viewer.launch(); diff --git a/tutorial/608_LIM/main.cpp b/tutorial/608_LIM/main.cpp index 6b4b4bb69..7dde00480 100644 --- a/tutorial/608_LIM/main.cpp +++ b/tutorial/608_LIM/main.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include "tutorial_shared_path.h" @@ -22,7 +22,7 @@ bool barriersEnabled; // This function is called every time a keyboard button is pressed // keys: 0:Original Mesh / 1:Harmonic / 2:Biharmonic / 3:Green / 4:ARAP -bool key_down(igl::viewer::Viewer& viewer,unsigned char key,int modifier) +bool key_down(igl::opengl::glfw::Viewer& viewer,unsigned char key,int modifier) { using namespace std; using namespace Eigen; @@ -106,7 +106,7 @@ int main(int argc, char *argv[]) lim(V1,V0,F,C,b,energyType,1e-8,100,true,true,barriersEnabled,true,-1,-1); // Show mesh - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.callback_key_down = &key_down; viewer.data.set_mesh(V1, F); viewer.core.show_lines = true; diff --git a/tutorial/609_Boolean/main.cpp b/tutorial/609_Boolean/main.cpp index decc730f5..55234143b 100755 --- a/tutorial/609_Boolean/main.cpp +++ b/tutorial/609_Boolean/main.cpp @@ -2,7 +2,7 @@ //#define IGL_NO_CORK //#undef IGL_STATIC_LIBRARY #include -#include +#include #include #include @@ -24,7 +24,7 @@ const char * MESH_BOOLEAN_TYPE_NAMES[] = "Resolve", }; -void update(igl::viewer::Viewer &viewer) +void update(igl::opengl::glfw::Viewer &viewer) { igl::copyleft::cgal::mesh_boolean(VA,FA,VB,FB,boolean_type,VC,FC,J); Eigen::MatrixXd C(FC.rows(),3); @@ -44,7 +44,7 @@ void update(igl::viewer::Viewer &viewer) std::cout<<"A "< #include -#include +#include #include #include @@ -24,7 +24,7 @@ int main(int argc, char * argv[]) read_triangle_mesh(TUTORIAL_SHARED_PATH "/xcylinder.obj",VC,FC); read_triangle_mesh(TUTORIAL_SHARED_PATH "/ycylinder.obj",VD,FD); read_triangle_mesh(TUTORIAL_SHARED_PATH "/zcylinder.obj",VE,FE); - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; int num_views = 5+4; int view_id = num_views-1; @@ -108,7 +108,7 @@ int main(int argc, char * argv[]) update(); viewer.callback_key_down = - [&](igl::viewer::Viewer &viewer, unsigned char key, int mods)->bool + [&](igl::opengl::glfw::Viewer &viewer, unsigned char key, int mods)->bool { switch(key) { diff --git a/tutorial/702_WindingNumber/main.cpp b/tutorial/702_WindingNumber/main.cpp index d1ea824b6..65eb50b34 100755 --- a/tutorial/702_WindingNumber/main.cpp +++ b/tutorial/702_WindingNumber/main.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include @@ -23,7 +23,7 @@ enum OverLayType NUM_OVERLAY = 3, } overlay = OVERLAY_NONE; -void update_visualization(igl::viewer::Viewer & viewer) +void update_visualization(igl::opengl::glfw::Viewer & viewer) { using namespace Eigen; using namespace std; @@ -70,7 +70,7 @@ void update_visualization(igl::viewer::Viewer & viewer) viewer.data.set_face_based(true); } -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int mod) +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int mod) { switch(key) { @@ -134,7 +134,7 @@ int main(int argc, char *argv[]) W = (W.array() - W.minCoeff())/(W.maxCoeff()-W.minCoeff()); // Plot the generated mesh - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; update_visualization(viewer); viewer.callback_key_down = &key_down; viewer.launch(); diff --git a/tutorial/703_Decimation/main.cpp b/tutorial/703_Decimation/main.cpp index 4a7631614..2877304ec 100755 --- a/tutorial/703_Decimation/main.cpp +++ b/tutorial/703_Decimation/main.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include @@ -28,7 +28,7 @@ int main(int argc, char * argv[]) MatrixXi F,OF; read_triangle_mesh(filename,OV,OF); - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; // Prepare array-based edge data structures and priority queue VectorXi EMAP; @@ -65,7 +65,7 @@ int main(int argc, char * argv[]) viewer.data.set_face_based(true); }; - const auto &pre_draw = [&](igl::viewer::Viewer & viewer)->bool + const auto &pre_draw = [&](igl::opengl::glfw::Viewer & viewer)->bool { // If animating then collapse 10% of edges if(viewer.core.is_animating && !Q.empty()) @@ -95,7 +95,7 @@ int main(int argc, char * argv[]) }; const auto &key_down = - [&](igl::viewer::Viewer &viewer,unsigned char key,int mod)->bool + [&](igl::opengl::glfw::Viewer &viewer,unsigned char key,int mod)->bool { switch(key) { diff --git a/tutorial/704_SignedDistance/main.cpp b/tutorial/704_SignedDistance/main.cpp index 2d0bf2273..34acfc96e 100755 --- a/tutorial/704_SignedDistance/main.cpp +++ b/tutorial/704_SignedDistance/main.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include @@ -27,7 +27,7 @@ double max_distance = 1; double slice_z = 0.5; bool overlay = false; -void update_visualization(igl::viewer::Viewer & viewer) +void update_visualization(igl::opengl::glfw::Viewer & viewer) { using namespace Eigen; using namespace std; @@ -97,7 +97,7 @@ void update_visualization(igl::viewer::Viewer & viewer) viewer.core.lighting_factor = overlay; } -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int mod) +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int mod) { switch(key) { @@ -151,7 +151,7 @@ int main(int argc, char *argv[]) V,F,igl::PER_EDGE_NORMALS_WEIGHTING_TYPE_UNIFORM,FN,EN,E,EMAP); // Plot the generated mesh - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; update_visualization(viewer); viewer.callback_key_down = &key_down; viewer.core.show_lines = false; diff --git a/tutorial/705_MarchingCubes/main.cpp b/tutorial/705_MarchingCubes/main.cpp index e43ba920b..33963d187 100755 --- a/tutorial/705_MarchingCubes/main.cpp +++ b/tutorial/705_MarchingCubes/main.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include @@ -63,10 +63,10 @@ int main(int argc, char * argv[]) '2' Show marching cubes contour of signed distance. '3' Show marching cubes contour of indicator function. )"; - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(SV,SF); viewer.callback_key_down = - [&](igl::viewer::Viewer & viewer, unsigned char key, int mod)->bool + [&](igl::opengl::glfw::Viewer & viewer, unsigned char key, int mod)->bool { switch(key) { diff --git a/tutorial/706_FacetOrientation/main.cpp b/tutorial/706_FacetOrientation/main.cpp index 271b5bd45..7b96df0d8 100755 --- a/tutorial/706_FacetOrientation/main.cpp +++ b/tutorial/706_FacetOrientation/main.cpp @@ -4,13 +4,13 @@ #include #include #include -#include +#include #include #include #include #include -igl::viewer::Viewer viewer; +igl::opengl::glfw::Viewer viewer; Eigen::MatrixXd V; std::vector C(2); std::vector RGBcolors(2); @@ -49,7 +49,7 @@ S,s Scramble colors viewer.callback_key_pressed = [&scramble_colors] - (igl::viewer::Viewer& /*viewer*/, unsigned int key, int mod)->bool + (igl::opengl::glfw::Viewer& /*viewer*/, unsigned int key, int mod)->bool { switch(key) { diff --git a/tutorial/707_SweptVolume/main.cpp b/tutorial/707_SweptVolume/main.cpp index 66e08452b..4d5eaaaad 100755 --- a/tutorial/707_SweptVolume/main.cpp +++ b/tutorial/707_SweptVolume/main.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include @@ -30,7 +30,7 @@ int main(int argc, char * argv[]) cout<bool + [&](igl::opengl::glfw::Viewer & viewer)->bool { if(!show_swept_volume) { @@ -57,7 +57,7 @@ int main(int argc, char * argv[]) return false; }; viewer.callback_key_down = - [&](igl::viewer::Viewer & viewer, unsigned char key, int mod)->bool + [&](igl::opengl::glfw::Viewer & viewer, unsigned char key, int mod)->bool { switch(key) { diff --git a/tutorial/708_Picking/main.cpp b/tutorial/708_Picking/main.cpp index 2522d06c9..deb216db1 100755 --- a/tutorial/708_Picking/main.cpp +++ b/tutorial/708_Picking/main.cpp @@ -1,7 +1,7 @@ #include "tutorial_shared_path.h" #include #include -#include +#include #include int main(int argc, char *argv[]) @@ -15,9 +15,9 @@ int main(int argc, char *argv[]) // Initialize white C = Eigen::MatrixXd::Constant(F.rows(),3,1); - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.callback_mouse_down = - [&V,&F,&C](igl::viewer::Viewer& viewer, int, int)->bool + [&V,&F,&C](igl::opengl::glfw::Viewer& viewer, int, int)->bool { int fid; Eigen::Vector3f bc; diff --git a/tutorial/709_VectorFieldVisualizer/main.cpp b/tutorial/709_VectorFieldVisualizer/main.cpp index 27e34a445..500cded5f 100644 --- a/tutorial/709_VectorFieldVisualizer/main.cpp +++ b/tutorial/709_VectorFieldVisualizer/main.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include @@ -64,7 +64,7 @@ void representative_to_nrosy( } } -bool pre_draw(igl::viewer::Viewer &viewer) +bool pre_draw(igl::opengl::glfw::Viewer &viewer) { using namespace Eigen; using namespace std; @@ -88,7 +88,7 @@ bool pre_draw(igl::viewer::Viewer &viewer) return false; } -bool key_down(igl::viewer::Viewer &viewer, unsigned char key, int modifier) +bool key_down(igl::opengl::glfw::Viewer &viewer, unsigned char key, int modifier) { if (key == ' ') { @@ -128,7 +128,7 @@ int main(int argc, char *argv[]) // Viewer Settings - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V, F); viewer.callback_pre_draw = &pre_draw; viewer.callback_key_down = &key_down; diff --git a/tutorial/710_SLIM/main.cpp b/tutorial/710_SLIM/main.cpp index b0de5f55d..6a3f7ed4f 100644 --- a/tutorial/710_SLIM/main.cpp +++ b/tutorial/710_SLIM/main.cpp @@ -12,7 +12,7 @@ #include "igl/harmonic.h" #include #include -#include +#include #include #include #include @@ -30,12 +30,12 @@ using namespace std; using namespace Eigen; void check_mesh_for_issues(Eigen::MatrixXd& V, Eigen::MatrixXi& F); -void param_2d_demo_iter(igl::viewer::Viewer& viewer); +void param_2d_demo_iter(igl::opengl::glfw::Viewer& viewer); void get_soft_constraint_for_circle(Eigen::MatrixXd& V_o, Eigen::MatrixXi& F, Eigen::VectorXi& b, Eigen::MatrixXd& bc); -void soft_const_demo_iter(igl::viewer::Viewer& viewer); -void deform_3d_demo_iter(igl::viewer::Viewer& viewer); +void soft_const_demo_iter(igl::opengl::glfw::Viewer& viewer); +void deform_3d_demo_iter(igl::opengl::glfw::Viewer& viewer); void get_cube_corner_constraints(Eigen::MatrixXd& V_o, Eigen::MatrixXi& F, Eigen::VectorXi& b, Eigen::MatrixXd& bc); -void display_3d_mesh(igl::viewer::Viewer& viewer); +void display_3d_mesh(igl::opengl::glfw::Viewer& viewer); void int_set_to_eigen_vector(const std::set& int_set, Eigen::VectorXi& vec); Eigen::MatrixXd V; @@ -53,7 +53,7 @@ enum DEMO_TYPE { }; DEMO_TYPE demo_type; -bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier){ +bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier){ if (key == ' ') { switch (demo_type) { case PARAM_2D: { @@ -76,7 +76,7 @@ bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier){ return false; } -void param_2d_demo_iter(igl::viewer::Viewer& viewer) { +void param_2d_demo_iter(igl::opengl::glfw::Viewer& viewer) { if (first_iter) { timer.start(); igl::read_triangle_mesh(TUTORIAL_SHARED_PATH "/face.obj", V, F); @@ -114,7 +114,7 @@ void param_2d_demo_iter(igl::viewer::Viewer& viewer) { } } -void soft_const_demo_iter(igl::viewer::Viewer& viewer) { +void soft_const_demo_iter(igl::opengl::glfw::Viewer& viewer) { if (first_iter) { igl::read_triangle_mesh(TUTORIAL_SHARED_PATH "/circle.obj", V, F); @@ -141,7 +141,7 @@ void soft_const_demo_iter(igl::viewer::Viewer& viewer) { } } -void deform_3d_demo_iter(igl::viewer::Viewer& viewer) { +void deform_3d_demo_iter(igl::opengl::glfw::Viewer& viewer) { if (first_iter) { igl::readOBJ(TUTORIAL_SHARED_PATH "/cube_40k.obj", V, F); @@ -163,7 +163,7 @@ void deform_3d_demo_iter(igl::viewer::Viewer& viewer) { } } -void display_3d_mesh(igl::viewer::Viewer& viewer) { +void display_3d_mesh(igl::opengl::glfw::Viewer& viewer) { MatrixXd V_temp; MatrixXi F_temp; Eigen::MatrixXd Barycenters; @@ -232,7 +232,7 @@ int main(int argc, char *argv[]) { // Launch the viewer - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.callback_key_down = &key_down; // Disable wireframe diff --git a/tutorial/711_Subdivision/main.cpp b/tutorial/711_Subdivision/main.cpp index a68ccc9ac..d7843b646 100755 --- a/tutorial/711_Subdivision/main.cpp +++ b/tutorial/711_Subdivision/main.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include @@ -25,12 +25,12 @@ int main(int argc, char * argv[]) 3 Apply Loop subdivided mesh 4 Apply False barycentric subdivision )"; - igl::viewer::Viewer viewer; + igl::opengl::glfw::Viewer viewer; viewer.data.set_mesh(V,F); viewer.data.set_face_based(true); viewer.callback_key_down = - [&](igl::viewer::Viewer & viewer, unsigned char key, int mod)->bool + [&](igl::opengl::glfw::Viewer & viewer, unsigned char key, int mod)->bool { switch(key) {