diff --git a/include/igl/png/readPNG.cpp b/include/igl/png/readPNG.cpp new file mode 100644 index 000000000..06a470b6c --- /dev/null +++ b/include/igl/png/readPNG.cpp @@ -0,0 +1,47 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 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 "readPNG.h" +#include + +IGL_INLINE bool igl::png::readPNG( + const std::string png_file, + Eigen::Matrix& R, + Eigen::Matrix& G, + Eigen::Matrix& B, + Eigen::Matrix& A +) +{ + int cols,rows,n; + unsigned char *data = stbi_load(png_file.c_str(), &cols, &rows, &n, 4); + if(data == NULL) { + return false; + } + + R.resize(cols,rows); + G.resize(cols,rows); + B.resize(cols,rows); + A.resize(cols,rows); + + for (unsigned i=0; i +// +// 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_PNG_READ_PNG_H +#define IGL_PNG_READ_PNG_H +#include "../igl_inline.h" +#include +#include + +namespace igl +{ + namespace png + { + // Read an image from a .png file into 4 memory buffers + // + // Input: + // png_file path to .png file + // Output: + // R,G,B,A texture channels + // Returns true on success, false on failure + // + IGL_INLINE bool readPNG(const std::string png_file, + Eigen::Matrix& R, + Eigen::Matrix& G, + Eigen::Matrix& B, + Eigen::Matrix& A + ); + } +} + +#ifndef IGL_STATIC_LIBRARY +# include "readPNG.cpp" +#endif + +#endif diff --git a/include/igl/png/writePNG.cpp b/include/igl/png/writePNG.cpp new file mode 100644 index 000000000..901ac85ab --- /dev/null +++ b/include/igl/png/writePNG.cpp @@ -0,0 +1,47 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 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 "writePNG.h" +#include +#include + +IGL_INLINE bool igl::png::writePNG( + const Eigen::Matrix& R, + const Eigen::Matrix& G, + const Eigen::Matrix& B, + const Eigen::Matrix& A, + const std::string png_file +) +{ + 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())); + + const int comp = 4; // 4 Channels Red, Green, Blue, Alpha + const int stride_in_bytes = R.rows()*comp; // Lenght of one row in bytes + std::vector data(R.size()*comp,0); // The image itself; + + for (unsigned i = 0; i +// +// 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_PNG_WRITE_PNG_H +#define IGL_PNG_WRITE_PNG_H +#include "../igl_inline.h" +#include +#include + +namespace igl +{ + namespace png + { + // Writes an image to a png file + // + // Input: + // R,G,B,A texture channels + // Output: + // png_file path to .png file + // Returns true on success, false on failure + // + IGL_INLINE bool writePNG + ( + const Eigen::Matrix& R, + const Eigen::Matrix& G, + const Eigen::Matrix& B, + const Eigen::Matrix& A, + const std::string png_file + ); + } +} + +#ifndef IGL_STATIC_LIBRARY +# include "writePNG.cpp" +#endif + +#endif diff --git a/index.html b/index.html index 14472eca9..6a5d0eff5 100644 --- a/index.html +++ b/index.html @@ -214,6 +214,7 @@ few labs/companies/institutions using libigl:

  • Adobe Research
  • +
  • Electronic Arts, Inc
  • Mesh, consultants, Canada
  • Pixar Research
  • Spine by Esoteric Software is an animation tool dedicated to 2D characters.
  • @@ -263,7 +264,7 @@ page.

    2016 Alec Jacobson, Daniele Panozzo, Christian Schüller, Olga Diamanti, Qingnan -Zhou, Nico Pietroni, Stefan Brugger, Kenshi Takayama, Wenzel Jakob, Nikolas De +Zhou, Sebastian Koch, Nico Pietroni, Stefan Brugger, Kenshi Takayama, Wenzel Jakob, Nikolas De Giorgis, Luigi Rocca, Leonardo Sacht, Kevin Walliman, Olga Sorkine-Hornung, and others.

    Please see individual files for appropriate copyright notices.

    diff --git a/style-guidelines.html b/style-guidelines.html index 415b904cb..16d2eb49c 100644 --- a/style-guidelines.html +++ b/style-guidelines.html @@ -185,8 +185,8 @@ Eigen::SparseMatrix<Atype> adjacency_matrix(const ... & F);

    Templating with Eigen

    Functions taking Eigen dense matrices/arrays as inputs and outputs (but not -return arguments), should template on top of Eigen::PlainObjectBase. Each -parameter should be derived using its own template.

    +return arguments), should template on top of Eigen::PlainObjectBase. **Each +parameter** should be derived using its own template.

    For example,

    @@ -264,8 +264,8 @@ unnecessary prefaces. For example, instead of compute_adjacency_matrixVariable naming conventions -

    Libigl prefers short (even single character) variable names with heavy -documentation in the comments in the header file or above the declaration of +

    Libigl prefers short (even single character) variable names _with heavy +documentation_ in the comments in the header file or above the declaration of the function. When possible use V to mean a list of vertex positions and F to mean a list of faces/triangles.

    diff --git a/tutorial/107_ScreenCapture/CMakeLists.txt b/tutorial/107_ScreenCapture/CMakeLists.txt new file mode 100644 index 000000000..ed651e5c8 --- /dev/null +++ b/tutorial/107_ScreenCapture/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 2.8.12) +project(107_ScreenCapture) + +add_executable(${PROJECT_NAME}_bin + main.cpp) +target_include_directories(${PROJECT_NAME}_bin PRIVATE ${LIBIGL_INCLUDE_DIRS}) +target_compile_definitions(${PROJECT_NAME}_bin PRIVATE ${LIBIGL_DEFINITIONS}) +target_link_libraries(${PROJECT_NAME}_bin ${LIBIGL_LIBRARIES} ${LIBIGL_EXTRA_LIBRARIES}) diff --git a/tutorial/107_ScreenCapture/main.cpp b/tutorial/107_ScreenCapture/main.cpp new file mode 100755 index 000000000..d0846c4eb --- /dev/null +++ b/tutorial/107_ScreenCapture/main.cpp @@ -0,0 +1,82 @@ +#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) +{ + if (key == '1') + { + // Allocate temporary buffers + Eigen::Matrix R(1280,800); + Eigen::Matrix G(1280,800); + Eigen::Matrix B(1280,800); + Eigen::Matrix A(1280,800); + + // Draw the scene in the buffers + viewer.core.draw_buffer(viewer.data,viewer.opengl,false,R,G,B,A); + + // Save it to a PNG + igl::png::writePNG(R,G,B,A,"out.png"); + } + + if (key == '2') + { + // Allocate temporary buffers + Eigen::Matrix R,G,B,A; + + // Read the PNG + igl::png::readPNG("out.png",R,G,B,A); + + // Replace the mesh with a triangulated square + Eigen::MatrixXd V(4,3); + V << + -0.5,-0.5,0, + 0.5,-0.5,0, + 0.5, 0.5,0, + -0.5, 0.5,0; + Eigen::MatrixXi F(2,3); + F << + 0,1,2, + 2,3,0; + Eigen::MatrixXd UV(4,2); + UV << + 0,0, + 1,0, + 1,1, + 0,1; + + viewer.data.clear(); + viewer.data.set_mesh(V,F); + viewer.data.set_uv(UV); + viewer.core.align_camera_center(V); + viewer.core.show_texture = true; + + // Use the image as a texture + viewer.data.set_texture(R,G,B); + + } + + + return false; +} + +int main(int argc, char *argv[]) +{ + // Load a mesh in OFF format + Eigen::MatrixXd V; + Eigen::MatrixXi F; + igl::readOFF(TUTORIAL_SHARED_PATH "/bunny.off", V, F); + + std::cerr << "Press 1 to render the scene and save it in a png." << std::endl; + 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; + viewer.callback_key_down = &key_down; + viewer.data.set_mesh(V, F); + viewer.launch(); +} diff --git a/tutorial/CMakeLists.txt b/tutorial/CMakeLists.txt index d09bad47e..bd43582fb 100644 --- a/tutorial/CMakeLists.txt +++ b/tutorial/CMakeLists.txt @@ -89,6 +89,9 @@ if(TUTORIALS_CHAPTER1) add_subdirectory("104_Colors") add_subdirectory("105_Overlays") add_subdirectory("106_ViewerMenu") + if(LIBIGL_WITH_PNG) + add_subdirectory("107_ScreenCapture") + endif() endif() # Chapter 2 diff --git a/tutorial/tutorial.html.REMOVED.git-id b/tutorial/tutorial.html.REMOVED.git-id index eb33265a4..a1ecdf5d3 100644 --- a/tutorial/tutorial.html.REMOVED.git-id +++ b/tutorial/tutorial.html.REMOVED.git-id @@ -1 +1 @@ -f46cce260ca12390184cb5fef8205ea121b3cb97 \ No newline at end of file +0ba0c22d44c641478413576281dc8e745316e8c7 \ No newline at end of file diff --git a/tutorial/tutorial.md.REMOVED.git-id b/tutorial/tutorial.md.REMOVED.git-id index 1bcb51072..daf1831fe 100644 --- a/tutorial/tutorial.md.REMOVED.git-id +++ b/tutorial/tutorial.md.REMOVED.git-id @@ -1 +1 @@ -f87bfabc63b2facf8ce8a778e86028722a7af22f \ No newline at end of file +6c7992b923fba06ca0986754535c23cb220875da \ No newline at end of file