unzip_corners.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 Alec Jacobson <alecjacobson@gmail.com>
  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. // UNZIP_CORNERS 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. // Inputs:
  29. // A #A list of #F by 3 attribute indices, typically {F,FTC,FN}
  30. // Outputs:
  31. // U #U by #A list of indices into each attribute for each unique mesh
  32. // vertex: U(v,a) is the attribute index of vertex v in attribute a.
  33. // G #F by 3 list of triangle indices into U
  34. // Example:
  35. // [V,F,TC,FTC] = readOBJ('~/Downloads/kiwis/kiwi.obj');
  36. // [U,G] = unzip_corners(cat(3,F,FTC));
  37. // % display mesh
  38. // tsurf(G,V(U(:,1),:));
  39. // % display texture coordinates
  40. // tsurf(G,TC(U(:,2),:));
  41. //
  42. template < typename DerivedA, typename DerivedU, typename DerivedG, typename DerivedJ>
  43. IGL_INLINE void unzip_corners(
  44. const std::vector<std::reference_wrapper<DerivedA> > & A,
  45. Eigen::PlainObjectBase<DerivedU> & U,
  46. Eigen::PlainObjectBase<DerivedG> & G,
  47. Eigen::PlainObjectBase<DerivedJ> & J);
  48. }
  49. #ifndef IGL_STATIC_LIBRARY
  50. # include "unzip_corners.cpp"
  51. #endif
  52. #endif