grid.cpp 2.4 KB

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