unzip_corners.cpp 1.0 KB

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