mat_max.cpp 1.5 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 "mat_max.h"
  9. template <typename DerivedX, typename DerivedY, typename DerivedI>
  10. IGL_INLINE void igl::mat_max(
  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).maxCoeff(&i,&PHONY);
  30. }else
  31. {
  32. m = X.row(j).maxCoeff(&PHONY,&i);
  33. }
  34. Y(j) = m;
  35. I(j) = i;
  36. }
  37. }
  38. #ifdef IGL_STATIC_LIBRARY
  39. // Explicit template instantiation
  40. // generated by autoexplicit.sh
  41. template void igl::mat_max<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> >&);
  42. #endif