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 
10 template <typename DerivedX, typename DerivedY, typename DerivedI>
mat_max(const Eigen::DenseBase<DerivedX> & X,const int dim,Eigen::PlainObjectBase<DerivedY> & Y,Eigen::PlainObjectBase<DerivedI> & I)11 IGL_INLINE void igl::mat_max(
12   const Eigen::DenseBase<DerivedX> & X,
13   const int dim,
14   Eigen::PlainObjectBase<DerivedY> & Y,
15   Eigen::PlainObjectBase<DerivedI> & I)
16 {
17   assert(dim==1||dim==2);
18 
19   // output size
20   int n = (dim==1?X.cols():X.rows());
21   // resize output
22   Y.resize(n);
23   I.resize(n);
24 
25   // loop over dimension opposite of dim
26   for(int j = 0;j<n;j++)
27   {
28     typename DerivedX::Index PHONY,i;
29     typename DerivedX::Scalar  m;
30     if(dim==1)
31     {
32       m = X.col(j).maxCoeff(&i,&PHONY);
33     }else
34     {
35       m = X.row(j).maxCoeff(&PHONY,&i);
36     }
37     Y(j) = m;
38     I(j) = i;
39   }
40 }
41 
42 #ifdef IGL_STATIC_LIBRARY
43 // Explicit template instantiation
44 // generated by autoexplicit.sh
45 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> >&);
46 #endif
47