unzip_corners.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #include "unzip_corners.h"
  9. #include "unique_rows.h"
  10. template < typename DerivedA, typename DerivedU, typename DerivedG, typename DerivedJ >
  11. IGL_INLINE void igl::unzip_corners(
  12. const std::vector<std::reference_wrapper<DerivedA> > & A,
  13. Eigen::PlainObjectBase<DerivedU> & U,
  14. Eigen::PlainObjectBase<DerivedG> & G,
  15. Eigen::PlainObjectBase<DerivedJ> & J)
  16. {
  17. if(A.size() == 0)
  18. {
  19. U.resize(0,0);
  20. G.resize(0,3);
  21. J.resize(0,0);
  22. return;
  23. }
  24. const size_t num_a = A.size();
  25. const typename DerivedA::Index m = A[0].get().rows();
  26. DerivedU C(m*3,num_a);
  27. for(int a = 0;a<num_a;a++)
  28. {
  29. assert(A[a].get().rows() == m && "All attributes should be same size");
  30. assert(A[a].get().cols() == 3 && "Must be triangles");
  31. C.block(0*m,a,m,1) = A[a].get().col(0);
  32. C.block(1*m,a,m,1) = A[a].get().col(1);
  33. C.block(2*m,a,m,1) = A[a].get().col(2);
  34. }
  35. DerivedJ I;
  36. igl::unique_rows(C,U,I,J);
  37. G.resize(m,3);
  38. for(int f = 0;f<m;f++)
  39. {
  40. for(int c = 0;c<3;c++)
  41. {
  42. G(f,c) = J(f+c*m);
  43. }
  44. }
  45. }
  46. #ifdef IGL_STATIC_LIBRARY
  47. // Explicit template instantiation
  48. // generated by autoexplicit.sh
  49. template void igl::unzip_corners<Eigen::Matrix<int, -1, -1, 0, -1, -1> const, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(std::vector<std::reference_wrapper<Eigen::Matrix<int, -1, -1, 0, -1, -1> const>, std::allocator<std::reference_wrapper<Eigen::Matrix<int, -1, -1, 0, -1, -1> const> > > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  50. #endif