map_texture.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef IGL_OPENGL_GLFW_MAP_TEXTURE_H
  2. #define IGL_OPENGL_GLFW_MAP_TEXTURE_H
  3. #include "../../igl_inline.h"
  4. #include <Eigen/Core>
  5. #include <vector>
  6. namespace igl
  7. {
  8. namespace opengl
  9. {
  10. namespace glfw
  11. {
  12. /// Given a mesh (V,F) in [0,1]² and new positions (U) and a texture image
  13. /// (in_data), _render_ a new image (out_data) of the same size.
  14. /// @param[in] V #V by 2 list of undeformed mesh vertex positions ∈ [0,1]²
  15. /// @param[in] F #F by 3 list of mesh triangle indices into V
  16. /// @param[in] U #U by 2 list of deformed vertex positions ∈ [0,1]²
  17. /// @param[in] in_data w*h*nc array of color values, channels, then columns, then
  18. /// rows (e.g., what stbi_image returns and expects)
  19. /// @param[in] w width
  20. /// @param[in] h height
  21. /// @param[in] nc number of channels
  22. /// @param[out] out_data h*w*nc list of output colors in same order as input
  23. /// @param[out] out_w width of output image
  24. /// @param[out] out_h height of output image
  25. /// @param[out] out_nc number of channels of output image
  26. ///
  27. /// \pre Seems like w,h should be equal.
  28. template <typename DerivedV, typename DerivedF, typename DerivedU>
  29. IGL_INLINE bool map_texture(
  30. const Eigen::MatrixBase<DerivedV> & _V,
  31. const Eigen::MatrixBase<DerivedF> & _F,
  32. const Eigen::MatrixBase<DerivedU> & _U,
  33. const unsigned char * in_data,
  34. const int w,
  35. const int h,
  36. const int nc,
  37. std::vector<unsigned char> & out_data,
  38. int & out_w,
  39. int & out_h,
  40. int & out_nc);
  41. /// \overload
  42. template <typename DerivedV, typename DerivedF, typename DerivedU>
  43. IGL_INLINE bool map_texture(
  44. const Eigen::MatrixBase<DerivedV> & V,
  45. const Eigen::MatrixBase<DerivedF> & F,
  46. const Eigen::MatrixBase<DerivedU> & U,
  47. const unsigned char * in_data,
  48. const int w,
  49. const int h,
  50. const int nc,
  51. std::vector<unsigned char> & out_data);
  52. }
  53. }
  54. }
  55. #ifndef IGL_STATIC_LIBRARY
  56. # include "map_texture.cpp"
  57. #endif
  58. #endif