2
0

unzip_corners.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 Alec Jacobson <[email protected]>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_UNZIP_CORNERS_H
  9. #define IGL_UNZIP_CORNERS_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <vector>
  13. #include <functional>
  14. namespace igl
  15. {
  16. /// Given a triangle mesh where corners of each triangle index
  17. /// different matrices of attributes (e.g. read from an OBJ file), unzip the
  18. /// corners into unique efficiently: attributes become properly vertex valued
  19. /// (usually creating greater than #V but less than #F*3 vertices).
  20. ///
  21. /// To pass a list of attributes this function takes an std::vector of
  22. /// std::reference_wrapper of an Eigen::... type. This allows you to use list
  23. /// initializers **without** incurring a copy, but means you'll need to
  24. /// provide the derived type of A as an explicit template parameter:
  25. ///
  26. /// unzip_corners<Eigen::MatrixXi>({F,FTC,FN},U,G,J);
  27. ///
  28. /// @param[in] A #A list of #F by 3 attribute indices, typically {F,FTC,FN}
  29. /// @param[out] U #U by #A list of indices into each attribute for each unique mesh
  30. /// vertex: U(v,a) is the attribute index of vertex v in attribute a.
  31. /// @param[out] G #F by 3 list of triangle indices into U
  32. /// @param[out] J #F*3 by 1 list of indices so that A[](i,j) = U.row(i+j*#F)
  33. ///
  34. /// #### Matlibberish Example
  35. ///
  36. /// [V,F,TC,FTC] = readOBJ('~/Downloads/kiwis/kiwi.obj');
  37. /// [U,G] = unzip_corners(cat(3,F,FTC));
  38. /// % display mesh
  39. /// tsurf(G,V(U(:,1),:));
  40. /// % display texture coordinates
  41. /// tsurf(G,TC(U(:,2),:));
  42. ///
  43. template < typename DerivedA, typename DerivedU, typename DerivedG, typename DerivedJ>
  44. IGL_INLINE void unzip_corners(
  45. const std::vector<std::reference_wrapper<DerivedA> > & A,
  46. Eigen::PlainObjectBase<DerivedU> & U,
  47. Eigen::PlainObjectBase<DerivedG> & G,
  48. Eigen::PlainObjectBase<DerivedJ> & J);
  49. }
  50. #ifndef IGL_STATIC_LIBRARY
  51. # include "unzip_corners.cpp"
  52. #endif
  53. #endif