unzip_corners.cpp 1.4 KB

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