grid.cpp 926 B

123456789101112131415161718192021222324252627282930
  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. IGL_INLINE void igl::grid(const Eigen::RowVector3i & res, Eigen::MatrixXd & GV)
  10. {
  11. using namespace Eigen;
  12. GV.resize(res(0)*res(1)*res(2),3);
  13. for(int zi = 0;zi<res(2);zi++)
  14. {
  15. const auto lerp =
  16. [&](const double di, const int d)->double{return di/(double)(res(d)-1);};
  17. const double z = lerp(zi,2);
  18. for(int yi = 0;yi<res(1);yi++)
  19. {
  20. const double y = lerp(yi,1);
  21. for(int xi = 0;xi<res(0);xi++)
  22. {
  23. const double x = lerp(xi,0);
  24. GV.row(xi+res(0)*(yi + res(1)*zi)) = RowVector3d(x,y,z);
  25. }
  26. }
  27. }
  28. }