grid.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. GV.resize(res(0)*res(1)*res(2),3);
  18. for(int zi = 0;zi<res(2);zi++)
  19. {
  20. const auto lerp =
  21. [&](const double di, const int d)->double{return di/(double)(res(d)-1);};
  22. const double z = lerp(zi,2);
  23. for(int yi = 0;yi<res(1);yi++)
  24. {
  25. const double y = lerp(yi,1);
  26. for(int xi = 0;xi<res(0);xi++)
  27. {
  28. const double x = lerp(xi,0);
  29. GV.row(xi+res(0)*(yi + res(1)*zi)) = RowVector3d(x,y,z);
  30. }
  31. }
  32. }
  33. }
  34. #ifdef IGL_STATIC_LIBRARY
  35. // Explicit template instantiation
  36. // generated by autoexplicit.sh
  37. 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> >&);
  38. #endif