group_sum_matrix.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #ifndef IGL_GROUP_SUM_MATRIX_H
  9. #define IGL_GROUP_SUM_MATRIX_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Dense>
  12. #include <Eigen/Sparse>
  13. namespace igl
  14. {
  15. // GROUP_SUM_MATRIX Builds a matrix A such that A*V computes the sum of
  16. // vertices in each group specified by G
  17. //
  18. // group_sum_matrix(G,k,A);
  19. //
  20. // Templates:
  21. // T should be a eigen sparse matrix primitive type like int or double
  22. // Inputs:
  23. // G #V list of group indices (0 to k-1) for each vertex, such that vertex i
  24. // is assigned to group G(i)
  25. // k #groups, good choice is max(G)+1
  26. // Outputs:
  27. // A #groups by #V sparse matrix such that A*V = group_sums
  28. //
  29. template <typename T>
  30. IGL_INLINE void group_sum_matrix(
  31. const Eigen::Matrix<int,Eigen::Dynamic,1> & G,
  32. const int k,
  33. Eigen::SparseMatrix<T>& A);
  34. // Wrapper with k = max(G)+1
  35. template <typename T>
  36. IGL_INLINE void group_sum_matrix(
  37. const Eigen::Matrix<int,Eigen::Dynamic,1> & G,
  38. Eigen::SparseMatrix<T>& A);
  39. }
  40. #ifndef IGL_STATIC_LIBRARY
  41. # include "group_sum_matrix.cpp"
  42. #endif
  43. #endif