mat_max.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 specialization
  40. #endif