group_sum_matrix.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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 "group_sum_matrix.h"
  9. template <typename T>
  10. IGL_INLINE void igl::group_sum_matrix(
  11. const Eigen::Matrix<int,Eigen::Dynamic,1> & G,
  12. const int k,
  13. Eigen::SparseMatrix<T>& A)
  14. {
  15. // number of vertices
  16. int n = G.rows();
  17. assert(k > G.maxCoeff());
  18. A.resize(k,n);
  19. // builds A such that A(i,j) = 1 where i corresponds to group i and j
  20. // corresponds to vertex j
  21. // Loop over vertices
  22. for(int j = 0;j<n;j++)
  23. {
  24. A.insert(G(j),j) = 1;
  25. }
  26. A.makeCompressed();
  27. }
  28. template <typename T>
  29. IGL_INLINE void igl::group_sum_matrix(
  30. const Eigen::Matrix<int,Eigen::Dynamic,1> & G,
  31. Eigen::SparseMatrix<T>& A)
  32. {
  33. return group_sum_matrix(G,G.maxCoeff()+1,A);
  34. }
  35. #ifdef IGL_STATIC_LIBRARY
  36. // Explicit template specialization
  37. template void igl::group_sum_matrix<double>(Eigen::Matrix<int, -1, 1, 0, -1, 1> const&, int, Eigen::SparseMatrix<double, 0, int>&);
  38. template void igl::group_sum_matrix<double>(Eigen::Matrix<int, -1, 1, 0, -1, 1> const&, Eigen::SparseMatrix<double, 0, int>&);
  39. #endif