combine.cpp 5.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. typename DerivedVsizes,
  16. typename DerivedFsizes>
  17. IGL_INLINE void igl::combine(
  18. const std::vector<DerivedVV> & VV,
  19. const std::vector<DerivedFF> & FF,
  20. Eigen::PlainObjectBase<DerivedV> & V,
  21. Eigen::PlainObjectBase<DerivedF> & F,
  22. Eigen::PlainObjectBase<DerivedVsizes> & Vsizes,
  23. Eigen::PlainObjectBase<DerivedFsizes> & Fsizes)
  24. {
  25. assert(VV.size() == FF.size() &&
  26. "Lists of verex lists and face lists should be same size");
  27. Vsizes.resize(VV.size());
  28. Fsizes.resize(FF.size());
  29. // Dimension of vertex positions
  30. const int dim = VV.size() > 0 ? VV[0].cols() : 0;
  31. // Simplex/element size
  32. const int ss = FF.size() > 0 ? FF[0].cols() : 0;
  33. int n = 0;
  34. int m = 0;
  35. for(int i = 0;i<VV.size();i++)
  36. {
  37. const auto & Vi = VV[i];
  38. const auto & Fi = FF[i];
  39. Vsizes(i) = Vi.rows();
  40. n+=Vi.rows();
  41. assert((Vi.size()==0 || dim == Vi.cols()) && "All vertex lists should have same #columns");
  42. Fsizes(i) = Fi.rows();
  43. m+=Fi.rows();
  44. assert((Fi.size()==0 || ss == Fi.cols()) && "All face lists should have same #columns");
  45. }
  46. V.resize(n,dim);
  47. F.resize(m,ss);
  48. {
  49. int kv = 0;
  50. int kf = 0;
  51. for(int i = 0;i<VV.size();i++)
  52. {
  53. const auto & Vi = VV[i];
  54. const int ni = Vi.rows();
  55. const auto & Fi = FF[i];
  56. const int mi = Fi.rows();
  57. if(Fi.size() >0)
  58. {
  59. F.block(kf,0,mi,ss) = Fi.array()+kv;
  60. }
  61. kf+=mi;
  62. if(Vi.size() >0)
  63. {
  64. V.block(kv,0,ni,dim) = Vi;
  65. }
  66. kv+=ni;
  67. }
  68. assert(kv == V.rows());
  69. assert(kf == F.rows());
  70. }
  71. }
  72. template <
  73. typename DerivedVV,
  74. typename DerivedFF,
  75. typename DerivedV,
  76. typename DerivedF>
  77. IGL_INLINE void igl::combine(
  78. const std::vector<DerivedVV> & VV,
  79. const std::vector<DerivedFF> & FF,
  80. Eigen::PlainObjectBase<DerivedV> & V,
  81. Eigen::PlainObjectBase<DerivedF> & F)
  82. {
  83. Eigen::VectorXi Vsizes,Fsizes;
  84. return igl::combine(VV,FF,V,F,Vsizes,Fsizes);
  85. }
  86. #ifdef IGL_STATIC_LIBRARY
  87. // Explicit template instantiation
  88. template void igl::combine<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<unsigned long, -1, 1, 0, -1, 1>, Eigen::Matrix<unsigned long, -1, 1, 0, -1, 1> >(std::vector<Eigen::Matrix<double, -1, -1, 0, -1, -1>, std::allocator<Eigen::Matrix<double, -1, -1, 0, -1, -1> > > const&, std::vector<Eigen::Matrix<int, -1, -1, 0, -1, -1>, std::allocator<Eigen::Matrix<int, -1, -1, 0, -1, -1> > > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned long, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned long, -1, 1, 0, -1, 1> >&);
  89. template void igl::combine<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3>, Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3> >(std::vector<Eigen::Matrix<double, -1, 3, 1, -1, 3>, std::allocator<Eigen::Matrix<double, -1, 3, 1, -1, 3> > > const&, std::vector<Eigen::Matrix<int, -1, 3, 1, -1, 3>, std::allocator<Eigen::Matrix<int, -1, 3, 1, -1, 3> > > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> >&);
  90. template void igl::combine<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::vector<Eigen::Matrix<double, -1, -1, 0, -1, -1>, std::allocator<Eigen::Matrix<double, -1, -1, 0, -1, -1> > > const&, std::vector<Eigen::Matrix<int, -1, -1, 0, -1, -1>, std::allocator<Eigen::Matrix<int, -1, -1, 0, -1, -1> > > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  91. #ifdef WIN32
  92. template void igl::combine<Eigen::Matrix<double,-1,-1,0,-1,-1>, Eigen::Matrix<int,-1,-1,0,-1,-1>,Eigen::Matrix<double,-1,-1,0,-1,-1>,Eigen::Matrix<int,-1,-1,0,-1,-1>,Eigen::Matrix<unsigned __int64,-1,1,0,-1,1>,Eigen::Matrix<unsigned __int64,-1,1,0,-1,1> >(class std::vector<Eigen::Matrix<double,-1,-1,0,-1,-1>,class std::allocator<Eigen::Matrix<double,-1,-1,0,-1,-1> > > const &,class std::vector<Eigen::Matrix<int,-1,-1,0,-1,-1>,class std::allocator<Eigen::Matrix<int,-1,-1,0,-1,-1> > > const &,Eigen::PlainObjectBase<Eigen::Matrix<double,-1,-1,0,-1,-1> > &,Eigen::PlainObjectBase<Eigen::Matrix<int,-1,-1,0,-1,-1> > &,Eigen::PlainObjectBase<Eigen::Matrix<unsigned __int64,-1,1,0,-1,1> > &,Eigen::PlainObjectBase<Eigen::Matrix<unsigned __int64,-1,1,0,-1,1> > &);
  93. template void igl::combine<Eigen::Matrix<double,-1,-1,0,-1,-1>, Eigen::Matrix<int,-1,-1,0,-1,-1>,Eigen::Matrix<double,-1,-1,0,-1,-1>,Eigen::Matrix<int,-1,-1,0,-1,-1>,Eigen::Matrix<unsigned __int64,-1,1,0,-1,1>,Eigen::Matrix<unsigned __int64,-1,1,0,-1,1> >(class std::vector<Eigen::Matrix<double,-1,-1,0,-1,-1>,class std::allocator<Eigen::Matrix<double,-1,-1,0,-1,-1> > > const &,class std::vector<Eigen::Matrix<int,-1,-1,0,-1,-1>,class std::allocator<Eigen::Matrix<int,-1,-1,0,-1,-1> > > const &,Eigen::PlainObjectBase<Eigen::Matrix<double,-1,-1,0,-1,-1> > &,Eigen::PlainObjectBase<Eigen::Matrix<int,-1,-1,0,-1,-1> > &,Eigen::PlainObjectBase<Eigen::Matrix<unsigned __int64,-1,1,0,-1,1> > &,Eigen::PlainObjectBase<Eigen::Matrix<unsigned __int64,-1,1,0,-1,1> > &);
  94. #endif
  95. #endif