1 // This file is part of libigl, a simple c++ geometry processing library.
2 //
3 // Copyright (C) 2016 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 "grid.h"
9 
10 template <
11   typename Derivedres,
12   typename DerivedGV>
grid(const Eigen::MatrixBase<Derivedres> & res,Eigen::PlainObjectBase<DerivedGV> & GV)13 IGL_INLINE void igl::grid(
14   const Eigen::MatrixBase<Derivedres> & res,
15   Eigen::PlainObjectBase<DerivedGV> & GV)
16 {
17   using namespace Eigen;
18   typedef typename DerivedGV::Scalar Scalar;
19   GV.resize(res(0)*res(1)*res(2),3);
20   for(int zi = 0;zi<res(2);zi++)
21   {
22     const auto lerp =
23       [&](const Scalar di, const int d)->Scalar{return di/(Scalar)(res(d)-1);};
24     const Scalar z = lerp(zi,2);
25     for(int yi = 0;yi<res(1);yi++)
26     {
27       const Scalar y = lerp(yi,1);
28       for(int xi = 0;xi<res(0);xi++)
29       {
30         const Scalar x = lerp(xi,0);
31         const int gi = xi+res(0)*(yi + res(1)*zi);
32         GV.row(gi) =
33           Eigen::Matrix<Scalar,1,3>(x,y,z);
34       }
35     }
36   }
37 }
38 
39 
40 #ifdef IGL_STATIC_LIBRARY
41 // Explicit template instantiation
42 // generated by autoexplicit.sh
43 template void igl::grid<Eigen::Matrix<int, 1, 3, 1, 1, 3>, Eigen::Matrix<float, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<int, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> >&);
44 // generated by autoexplicit.sh
45 template void igl::grid<Eigen::Matrix<int, 3, 1, 0, 3, 1>, Eigen::Matrix<float, -1, 3, 0, -1, 3> >(Eigen::MatrixBase<Eigen::Matrix<int, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 3, 0, -1, 3> >&);
46 // generated by autoexplicit.sh
47 template void igl::grid<Eigen::Matrix<int, 3, 1, 0, 3, 1>, Eigen::Matrix<float, -1, 3, 1, -1, 3> >(Eigen::MatrixBase<Eigen::Matrix<int, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> >&);
48 // generated by autoexplicit.sh
49 template void igl::grid<Eigen::Matrix<int, 3, 1, 0, 3, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<int, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
50 template void igl::grid<Eigen::Matrix<int, 1, 3, 1, 1, 3>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<int, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
51 #endif
52