grid.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. GV.row(xi+res(0)*(yi + res(1)*zi)) =
  31. Eigen::Matrix<Scalar,1,3>(x,y,z);
  32. }
  33. }
  34. }
  35. }
  36. #ifdef IGL_STATIC_LIBRARY
  37. // Explicit template instantiation
  38. template void igl::grid<Eigen::Matrix<float, 1, 3, 1, 1, 3>, Eigen::Matrix<float, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<float, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> >&);
  39. 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> >&);
  40. #endif