print_ijv.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 "print_ijv.h"
  9. #include "find.h"
  10. #include <iostream>
  11. template <typename T>
  12. IGL_INLINE void igl::print_ijv(
  13. const Eigen::SparseMatrix<T>& X,
  14. const int offset)
  15. {
  16. Eigen::Matrix<int,Eigen::Dynamic,1> I;
  17. Eigen::Matrix<int,Eigen::Dynamic,1> J;
  18. Eigen::Matrix<T,Eigen::Dynamic,1> V;
  19. igl::find(X,I,J,V);
  20. // Concatenate I,J,V
  21. Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> IJV(I.size(),3);
  22. IJV.col(0) = I.cast<T>();
  23. IJV.col(1) = J.cast<T>();
  24. IJV.col(2) = V;
  25. // Offset
  26. if(offset != 0)
  27. {
  28. IJV.col(0).array() += offset;
  29. IJV.col(1).array() += offset;
  30. }
  31. std::cout<<IJV;
  32. }
  33. #ifdef IGL_STATIC_LIBRARY
  34. // Explicit template specialization
  35. // generated by autoexplicit.sh
  36. template void igl::print_ijv<double>(Eigen::SparseMatrix<double, 0, int> const&, int);
  37. #endif