mat_min.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 DerivedX, typename DerivedY, typename DerivedI>
  10. IGL_INLINE void igl::mat_min(
  11. const Eigen::DenseBase<DerivedX> & X,
  12. const int dim,
  13. Eigen::PlainObjectBase<DerivedY> & Y,
  14. Eigen::PlainObjectBase<DerivedI> & 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 DerivedX::Index PHONY,i;
  26. typename DerivedX::Scalar m;
  27. if(dim==1)
  28. {
  29. m = X.col(j).minCoeff(&i,&PHONY);
  30. }else
  31. {
  32. m = X.row(j).minCoeff(&PHONY,&i);
  33. }
  34. Y(j) = m;
  35. I(j) = i;
  36. }
  37. }
  38. //template <typename T>
  39. //IGL_INLINE Eigen::Matrix<T,Eigen::Dynamic,1> igl::mat_min(
  40. // const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & X,
  41. // const int dim)
  42. //{
  43. // Eigen::Matrix<T,Eigen::Dynamic,1> Y;
  44. // Eigen::Matrix<int,Eigen::Dynamic,1> I;
  45. // mat_min(X,dim,Y,I);
  46. // return Y;
  47. //}
  48. #ifdef IGL_STATIC_LIBRARY
  49. // Explicit template instantiation
  50. // generated by autoexplicit.sh
  51. template void igl::mat_min<Eigen::Array<bool, -1, 3, 0, -1, 3>, Eigen::Array<bool, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::DenseBase<Eigen::Array<bool, -1, 3, 0, -1, 3> > const&, int, Eigen::PlainObjectBase<Eigen::Array<bool, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  52. // generated by autoexplicit.sh
  53. template void igl::mat_min<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::DenseBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  54. #endif