combine.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 "combine.h"
  9. #include <cassert>
  10. template <
  11. typename DerivedVV,
  12. typename DerivedFF,
  13. typename DerivedV,
  14. typename DerivedF>
  15. IGL_INLINE void igl::combine(
  16. const std::vector<DerivedVV> & VV,
  17. const std::vector<DerivedFF> & FF,
  18. Eigen::PlainObjectBase<DerivedV> & V,
  19. Eigen::PlainObjectBase<DerivedF> & F)
  20. {
  21. assert(VV.size() == FF.size() &&
  22. "Lists of verex lists and face lists should be same size");
  23. // Dimension of vertex positions
  24. const int dim = VV.size() > 0 ? VV[0].cols() : 0;
  25. // Simplex/element size
  26. const int ss = FF.size() > 0 ? FF[0].cols() : 0;
  27. int n = 0;
  28. int m = 0;
  29. for(int i = 0;i<VV.size();i++)
  30. {
  31. const auto & Vi = VV[i];
  32. const auto & Fi = FF[i];
  33. n+=Vi.rows();
  34. assert(dim == Vi.cols() && "All vertex lists should have same #columns");
  35. m+=Fi.rows();
  36. assert(ss == Fi.cols() && "All face lists should have same #columns");
  37. }
  38. V.resize(n,dim);
  39. F.resize(m,ss);
  40. {
  41. int kv = 0;
  42. int kf = 0;
  43. for(int i = 0;i<VV.size();i++)
  44. {
  45. const auto & Vi = VV[i];
  46. const int ni = Vi.rows();
  47. const auto & Fi = FF[i];
  48. const int mi = Fi.rows();
  49. F.block(kf,0,mi,ss) = Fi.array()+kv;
  50. kf+=mi;
  51. V.block(kv,0,ni,dim) = Vi;
  52. kv+=ni;
  53. }
  54. assert(kv == V.rows());
  55. assert(kf == F.rows());
  56. }
  57. }