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 
10 template <typename DerivedX, typename DerivedY, typename DerivedI>
mat_min(const Eigen::DenseBase<DerivedX> & X,const int dim,Eigen::PlainObjectBase<DerivedY> & Y,Eigen::PlainObjectBase<DerivedI> & I)11 IGL_INLINE void igl::mat_min(
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).minCoeff(&i,&PHONY);
33     }else
34     {
35       m = X.row(j).minCoeff(&PHONY,&i);
36     }
37     Y(j) = m;
38     I(j) = i;
39   }
40 }
41 
42 //template <typename T>
43 //IGL_INLINE Eigen::Matrix<T,Eigen::Dynamic,1> igl::mat_min(
44 //  const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & X,
45 //  const int dim)
46 //{
47 //  Eigen::Matrix<T,Eigen::Dynamic,1> Y;
48 //  Eigen::Matrix<int,Eigen::Dynamic,1> I;
49 //  mat_min(X,dim,Y,I);
50 //  return Y;
51 //}
52 
53 #ifdef IGL_STATIC_LIBRARY
54 // Explicit template instantiation
55 // generated by autoexplicit.sh
56 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> >&);
57 // generated by autoexplicit.sh
58 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> >&);
59 #endif
60