mat_min.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 "mat_min.h"
  9. template <typename T>
  10. IGL_INLINE void igl::mat_min(
  11. const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & X,
  12. const int dim,
  13. Eigen::Matrix<T,Eigen::Dynamic,1> & Y,
  14. Eigen::Matrix<int,Eigen::Dynamic,1> & I)
  15. {
  16. assert(dim==1||dim==2);
  17. // output size
  18. int n = (dim==1?X.cols():X.rows());
  19. // resize output
  20. Y.resize(n);
  21. I.resize(n);
  22. // loop over dimension opposite of dim
  23. for(int j = 0;j<n;j++)
  24. {
  25. typename Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic>::Index PHONY;
  26. typename Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic>::Index i;
  27. T m;
  28. if(dim==1)
  29. {
  30. m = X.col(j).minCoeff(&i,&PHONY);
  31. }else
  32. {
  33. m = X.row(j).minCoeff(&PHONY,&i);
  34. }
  35. Y(j) = m;
  36. I(j) = i;
  37. }
  38. }
  39. //template <typename T>
  40. //IGL_INLINE Eigen::Matrix<T,Eigen::Dynamic,1> igl::mat_min(
  41. // const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & X,
  42. // const int dim)
  43. //{
  44. // Eigen::Matrix<T,Eigen::Dynamic,1> Y;
  45. // Eigen::Matrix<int,Eigen::Dynamic,1> I;
  46. // mat_min(X,dim,Y,I);
  47. // return Y;
  48. //}
  49. #ifdef IGL_STATIC_LIBRARY
  50. // Explicit template specialization
  51. // generated by autoexplicit.sh
  52. template void igl::mat_min<double>(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, int, Eigen::Matrix<double, -1, 1, 0, -1, 1>&, Eigen::Matrix<int, -1, 1, 0, -1, 1>&);
  53. #endif